zabbix的rpm包下载地址 http://repo.zabbix.com/zabbix/
1、Tcp连接监控相关设置
模板
Templates TCP Connection Status.xml 已上传到附件,导入到web zabbix即可
客户端脚本
cat Tcp_Status.sh
#!/bin/bash #scripts for tcp status function SYNRECV { /usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘SYN-RECV‘ | awk ‘{print $2}‘ } function ESTAB { /usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘ESTAB‘ | awk ‘{print $2}‘ } function FINWAIT1 { /usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘FIN-WAIT-1‘ | awk ‘{print $2}‘ } function FINWAIT2 { /usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘FIN-WAIT-2‘ | awk ‘{print $2}‘ } function TIMEWAIT { /usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘TIME-WAIT‘ | awk ‘{print $2}‘ } function LASTACK { /usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘LAST-ACK‘ | awk ‘{print $2}‘ } function LISTEN { /usr/sbin/ss -ant | awk ‘{++s[$1]} END {for(k in s) print k,s[k]}‘ | grep ‘LISTEN‘ | awk ‘{print $2}‘ }
添加脚本x权限 chmod +x Tcp_Status.sh
在zabbix_agentd .conf 添加如下代码,注意脚本路径
UserParameter=Tcp.Status[*],/etc/zabbix/Tcp_Status.sh $1
zabbix-agent重启即可
2、Nginx的连接监控设置
提供模板
Template Nginx Connection.xml 已上传到附件,导入到web zabbix即可
客户端脚本
cat nginx_status.sh
#!/bin/bash # Info: zabbix 监控 nginx 性能以及进程状态 # 检查nginx 进程是否存在 function ping { /sbin/pidof nginx | wc -l } # 检查nginx 性能 # 活动连接数 function active { /usr/bin/curl "http://127.0.0.1/nginx_status/" 2>/dev/null| grep ‘Active‘ | awk ‘{print $NF}‘ } # 处理的连接数 function accepts { /usr/bin/curl "http://127.0.0.1/nginx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $1}‘ } # 成功创建的握手次数 function handled { /usr/bin/curl "http://127.0.0.1/nginx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $2}‘ } # 处理的请求数 function requests { /usr/bin/curl "http://127.0.0.1/nginx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $3}‘ } # 读取客户端的连接数 function reading { /usr/bin/curl "http://127.0.0.1/nginx_status/" 2>/dev/null| grep ‘Reading‘ | awk ‘{print $2}‘ } # 响应数据到客户端的数量 function writing { /usr/bin/curl "http://127.0.0.1/nginx_status/" 2>/dev/null| grep ‘Writing‘ | awk ‘{print $4}‘ } # 已经处理完正在等候下一次请求指令的驻留连接 function waiting { /usr/bin/curl "http://127.0.0.1/nginx_status/" 2>/dev/null| grep ‘Waiting‘ | awk ‘{print $6}‘ } # 执行function $1
添加x权限
在zabbix_agentd .conf 添加如下代码,注意脚本路径
UserParameter=Nginx.Status[*],/etc/zabbix/nginx_status.sh $1
最后zabbix-agent重启即可
3、RabbitMQ的连接监控设置
提供模板
Template RabbitMQ Connection.xml 已上传到附件,导入到web zabbix即可
客户端脚本
cat Rabbitmq_status.sh
4、Mysql的监控设置
提供模板 Template Mysql.xml 已上传到附件,导入到web zabbix即可
客户端脚本
cat Check_mysql.sh
#!/bin/sh MYSQL_SOCK="/tmp/mysql.sock" MYSQL_PWD=`cat /opt/application/zabbix/plugin/.mysqlp` ARGS=1 if [ $# -ne "$ARGS" ];then echo "Please input one arguement:" fi case $1 in Uptime) result=`mysqladmin -uZabbixAgent -p${MYSQL_PWD} -S $MYSQL_SOCK status|cut -f2 -d":"|cut -f1 -d"T"` echo $result ;; Com_update) result=`mysqladmin -uZabbixAgent -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_update"|cut -d"|" -f3` echo $result ;; Slow_queries) result=`mysqladmin -uZabbixAgent -p${MYSQL_PWD} -S $MYSQL_SOCK status |cut -f5 -d":"|cut -f1 -d"O"` echo $result ;; Com_select) result=`mysqladmin -uZabbixAgent -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_select"|cut -d"|" -f3` echo $result ;; Com_rollback) result=`mysqladmin -uZabbixAgent -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_rollback"|cut -d"|" -f3` echo $result ;; Questions) result=`mysqladmin -uZabbixAgent -p${MYSQL_PWD} -S $MYSQL_SOCK status|cut -f4 -d":"|cut -f1 -d"S"` echo $result ;; Com_insert) result=`mysqladmin -uZabbixAgent -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_insert"|cut -d"|" -f3` echo $result ;; Com_delete) result=`mysqladmin -uZabbixAgent -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_delete"|cut -d"|" -f3` echo $result ;; Com_commit) result=`mysqladmin -uZabbixAgent -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_commit"|cut -d"|" -f3` echo $result ;; Bytes_sent) result=`mysqladmin -uZabbixAgent -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Bytes_sent" |cut -d"|" -f3` echo $result ;; Bytes_received) result=`mysqladmin -uZabbixAgent -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Bytes_received" |cut -d"|" -f3` echo $result ;; Com_begin) result=`mysqladmin -uZabbixAgent -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_begin"|cut -d"|" -f3` echo $result ;; CPU_usage) result=`/usr/bin/top -bn1 -U mysql|grep mysqld|awk ‘{print $9}‘` echo $result ;; Memory_usage) result=`/usr/bin/top -bn1 -U mysql|grep mysqld|awk ‘{print $10}‘` echo $result ;; *) echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|CPU_usage|Memory_usage)" ;; esac
在zabbix_agent.conf添加如下代码
# 获取mysql性能指标,这个是上面定义好的脚本 UserParameter=mysql.status[*],/opt/application/zabbix/plugin/Check_mysql.sh $1 # # 获取mysql运行状态 UserParameter=mysql.ping,mysqladmin -uUSER -pPASSWPRD ping | grep -c alive
重启 zabbix-agent 即可
时间: 2024-10-11 16:33:49