一、前提环境说明
1、最终实现Freeswitch监控指标信息:
2、环境需求:
-
(1)需要使用Zabbix6.0及以上
-
(2)需要使用zabbix_agent2
二、实现步骤
1、zabbix_agent2添加监控键值
cat /etc/zabbix/conf.d/freeswitch.conf
UserParameter=fs.version,/etc/zabbix/shell/freeswitch.sh version
UserParameter=fs.calls,/etc/zabbix/shell/freeswitch.sh calls
UserParameter=fs.regs,/etc/zabbix/shell/freeswitch.sh regs
UserParameter=fs.thread,/etc/zabbix/shell/freeswitch.sh thread
UserParameter=fs.cpu.usage,/etc/zabbix/shell/freeswitch.sh cpu
UserParameter=fs.memory.usage,/etc/zabbix/shell/freeswitch.sh memory
UserParameter=fs.uptime,/etc/zabbix/shell/freeswitch.sh uptime
2、添加脚本(键值都是通过脚本获取到的值)
cat /etc/zabbix/shell/freeswitch.sh
#!/bin/bash
fsPath="/usr/local/freeswitch/bin/fs_cli -x"
fsPid=$(ps -ef |grep -w ./freeswitch |grep -v grep|awk NR==1|awk '{print $2}')
# 当前注册分级数量
RegistrationNum(){
${fsPath} "sofia status profile internal reg"|grep -w "Total items returned:"|awk '{print $NF}'
}
# 当前通话数量
CallsNum(){
${fsPath} "show calls"|grep -w total.|awk '{print $1}'
}
# FreeSwitch版本
FreeSwitchVersion(){
${fsPath} "version"|awk NR==1
}
# 线程数量
ThreadNum(){
ps -T -p ${fsPid}|wc -l
}
# FS进程内存使用率
MemoryUsage(){
ps -aux |grep -w ${fsPid}|grep -v grep|awk '{print $4}'
}
# FS进程CPU使用率
CpuUsage(){
ps -aux |grep -w ${fsPid}|grep -v grep|awk '{print $3}'
}
# FS运行时间
UpTime(){
ps -eo pid,comm,etime | grep -w ${fsPid}|awk '{print $NF}'
}
case $1 in
"uptime")
UpTime
;;
"regs")
RegistrationNum
;;
"calls")
CallsNum
;;
"version")
FreeSwitchVersion
;;
"thread")
ThreadNum
;;
"cpu")
CpuUsage
;;
"memory")
MemoryUsage
;;
esac
3、重启zabbix_agent2
systemctl restart zabbix-agent2
4、导入模板,把模板内容保存到一个yaml结尾文件中,然后在zabbix导入中选择此文件
模板内容如下:
zabbix_export:
version: '6.0'
date: '2024-07-14T13:01:51Z'
groups:
- uuid: dc579cd7a1a34222933f24f52a68bcd8
name: 'Linux servers'
templates:
- uuid: a16626cf7ef045c3a81271a0851e5eb8
template: CCP
name: CCP
groups:
- name: 'Linux servers'
items:
- uuid: f330cd7c74824042b817daccfdd4bd49
name: FS_当前通话数量
key: fs.calls
delay: 5s
triggers:
- uuid: d4e3c70610ad4bd18b698a380ffce20b
expression: last(/CCP/fs.calls)>20
recovery_mode: RECOVERY_EXPRESSION
recovery_expression: last(/CCP/fs.calls)<20
name: 'FS通话数量 > 20'
priority: WARNING
manual_close: 'YES'
- uuid: 6ae520e19b51454c80d58506fc1ccdf6
name: FS_CPU使用率
key: fs.cpu.usage
delay: 30s
value_type: FLOAT
- uuid: 6e09770ffc13411dad9b4fee482a6201
name: FS_内存使用率
key: fs.memory.usage
delay: 30s
value_type: FLOAT
- uuid: c51803aaf6b94ea797ccf24508f3914b
name: FS_分级注册数量
key: fs.regs
delay: 5s
triggers:
- uuid: 6cd4b619f9c14b999863ae1ded3e984a
expression: last(/CCP/fs.regs)>20
recovery_mode: RECOVERY_EXPRESSION
recovery_expression: last(/CCP/fs.regs)<20
name: 'FS分级注册数量 > 20'
priority: WARNING
manual_close: 'YES'
- uuid: fc755a6d0ec144fa8af674c1c8009c40
name: FS_线程数
key: fs.thread
delay: 30s
triggers:
- uuid: aecd450798304e80a25689a055449471
expression: last(/CCP/fs.thread)>500
recovery_mode: RECOVERY_EXPRESSION
recovery_expression: last(/CCP/fs.thread)<500
name: FS线程数大于500
priority: WARNING
manual_close: 'YES'
- uuid: 78aff8d733bd4eb6b35d7af905d0c7ee
name: FS_运行时间
key: fs.uptime
delay: 30s
trends: '0'
value_type: TEXT
- uuid: 0d0c61ce5f194f569eafc6a2ca64670e
name: FS_版本
key: fs.version
trends: '0'
value_type: TEXT
- uuid: ebb21ecc1a0846dc804533e09799e70f
name: FS_38890端口
key: 'net.udp.listen[38890]'
delay: 30s
triggers:
- uuid: dbdba4b9b4dd4b83a7efa4a9bccdaf06
expression: 'last(/CCP/net.udp.listen[38890])=0'
recovery_mode: RECOVERY_EXPRESSION
recovery_expression: 'last(/CCP/net.udp.listen[38890])=1'
name: 'FS 38890端口无法建立连接'
priority: HIGH
manual_close: 'YES'
- uuid: 5b6c01fb6ddc414dbb4cde2019f96378
name: FS_38891端口
key: 'net.udp.listen[38891]'
delay: 30s
triggers:
- uuid: 34885f3725c94583bbb667730d61b552
expression: 'last(/CCP/net.udp.listen[38891])=0'
recovery_mode: RECOVERY_EXPRESSION
recovery_expression: 'last(/CCP/net.udp.listen[38891])=1'
name: 'FS 38891端口无法建立连接'
priority: HIGH
manual_close: 'YES'
graphs:
- uuid: 83074d6630964d65a8810c326c973444
name: FS分级注册数量
graph_items:
- color: 199C0D
calc_fnc: ALL
item:
host: CCP
key: fs.regs
- uuid: d4bb3c3e9fa24d1e92d6fed17e471394
name: FS整体信息
graph_items:
- color: 199C0D
calc_fnc: ALL
item:
host: CCP
key: fs.regs
- sortorder: '1'
color: F63100
calc_fnc: ALL
item:
host: CCP
key: fs.calls
- uuid: 0dadf47386de4b08a8b97663ccba72d5
name: FS通话数量
graph_items:
- color: 199C0D
calc_fnc: ALL
item:
host: CCP
key: fs.calls
WEB页面导入模板
模板内容如下:
导入模板后,就可以针对主机使用此模板了!!