一、前提环境说明
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: dc579cd7a1a34222933f24f52a68bcd8name: 'Linux servers'templates:- uuid: a16626cf7ef045c3a81271a0851e5eb8template: CCPname: CCPgroups:- name: 'Linux servers'items:- uuid: f330cd7c74824042b817daccfdd4bd49name: FS_当前通话数量key: fs.callsdelay: 5striggers:- uuid: d4e3c70610ad4bd18b698a380ffce20bexpression: last(/CCP/fs.calls)>20recovery_mode: RECOVERY_EXPRESSIONrecovery_expression: last(/CCP/fs.calls)<20name: 'FS通话数量 > 20'priority: WARNINGmanual_close: 'YES'- uuid: 6ae520e19b51454c80d58506fc1ccdf6name: FS_CPU使用率key: fs.cpu.usagedelay: 30svalue_type: FLOAT- uuid: 6e09770ffc13411dad9b4fee482a6201name: FS_内存使用率key: fs.memory.usagedelay: 30svalue_type: FLOAT- uuid: c51803aaf6b94ea797ccf24508f3914bname: FS_分级注册数量key: fs.regsdelay: 5striggers:- uuid: 6cd4b619f9c14b999863ae1ded3e984aexpression: last(/CCP/fs.regs)>20recovery_mode: RECOVERY_EXPRESSIONrecovery_expression: last(/CCP/fs.regs)<20name: 'FS分级注册数量 > 20'priority: WARNINGmanual_close: 'YES'- uuid: fc755a6d0ec144fa8af674c1c8009c40name: FS_线程数key: fs.threaddelay: 30striggers:- uuid: aecd450798304e80a25689a055449471expression: last(/CCP/fs.thread)>500recovery_mode: RECOVERY_EXPRESSIONrecovery_expression: last(/CCP/fs.thread)<500name: FS线程数大于500priority: WARNINGmanual_close: 'YES'- uuid: 78aff8d733bd4eb6b35d7af905d0c7eename: FS_运行时间key: fs.uptimedelay: 30strends: '0'value_type: TEXT- uuid: 0d0c61ce5f194f569eafc6a2ca64670ename: FS_版本key: fs.versiontrends: '0'value_type: TEXT- uuid: ebb21ecc1a0846dc804533e09799e70fname: FS_38890端口key: 'net.udp.listen[38890]'delay: 30striggers:- uuid: dbdba4b9b4dd4b83a7efa4a9bccdaf06expression: 'last(/CCP/net.udp.listen[38890])=0'recovery_mode: RECOVERY_EXPRESSIONrecovery_expression: 'last(/CCP/net.udp.listen[38890])=1'name: 'FS 38890端口无法建立连接'priority: HIGHmanual_close: 'YES'- uuid: 5b6c01fb6ddc414dbb4cde2019f96378name: FS_38891端口key: 'net.udp.listen[38891]'delay: 30striggers:- uuid: 34885f3725c94583bbb667730d61b552expression: 'last(/CCP/net.udp.listen[38891])=0'recovery_mode: RECOVERY_EXPRESSIONrecovery_expression: 'last(/CCP/net.udp.listen[38891])=1'name: 'FS 38891端口无法建立连接'priority: HIGHmanual_close: 'YES'graphs:- uuid: 83074d6630964d65a8810c326c973444name: FS分级注册数量graph_items:- color: 199C0Dcalc_fnc: ALLitem:host: CCPkey: fs.regs- uuid: d4bb3c3e9fa24d1e92d6fed17e471394name: FS整体信息graph_items:- color: 199C0Dcalc_fnc: ALLitem:host: CCPkey: fs.regs- sortorder: '1'color: F63100calc_fnc: ALLitem:host: CCPkey: fs.calls- uuid: 0dadf47386de4b08a8b97663ccba72d5name: FS通话数量graph_items:- color: 199C0Dcalc_fnc: ALLitem:host: CCPkey: fs.calls
WEB页面导入模板
模板内容如下:
导入模板后,就可以针对主机使用此模板了!!