上一次的文章写得简直惨不忍睹。
首先我用官方自带模板
然后就会出现
我是二进制部署
就在源码包里有默认的mysql模板配置文件
cp 至 /usr/local/zabbix/etc/zabbix-agent.d/
然后在mysql的配置文件下配置有权限的用户即可
随后重启mysql and agentd
- 自定义脚本
[root@zabbix scripts]# cat mysql.sh #!/bin/bash #用户名 MYSQL_USER='root' #密码 MYSQL_PASSWORD='shanyao@2020' #主机地址/IP MYSQL_HOST='127.0.0.1' #端口 MYSQL_PORT='3306' #数据连接 MYSQL_CONN="/usr/bin/mysqladmin" #参数是否正确 if [ $# -ne "1" ];then echo "arg error!" fi #获取数据 case $1 in Uptime) result=`${MYSQL_CONN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} 2>/dev/null status|awk '{print $2}'` echo $result ;; Threads) result=`${MYSQL_CONN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} 2>/dev/null status|awk '{print $4}'` echo $result ;; Questions) result=`${MYSQL_CONN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} 2>/dev/null status|awk '{print $6}'` echo $result ;; Queries_avg) result=`${MYSQL_CONN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} 2>/dev/null status|awk '{print $NF}'` echo $result ;; Com_update) result=`${MYSQL_CONN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} 2>/dev/null extended-status |grep -w "Com_update"|awk -F'|' '{print $3}'` echo $result ;; Slow_queries) result=`${MYSQL_CONN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} 2>/dev/null status|awk '{print $9}'` echo $result ;; Com_select) result=`${MYSQL_CONN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} 2>/dev/null extended-status |grep -w "Com_select"|awk -F'|' '{print $3}'` echo $result ;; Com_rollback) result=`${MYSQL_CONN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} 2>/dev/null extended-status |grep -w "Com_rollback"|awk -F'|' '{print $3}'` echo $result ;; Com_insert) result=`${MYSQL_CONN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} 2>/dev/null extended-status |grep -w "Com_insert"|awk -F'|' '{print $3}'` echo $result ;; Com_delete) result=`${MYSQL_CONN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} 2>/dev/null extended-status |grep -w "Com_delete"|awk -F'|' '{print $3}'` echo $result ;; Com_commit) result=`${MYSQL_CONN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} 2>/dev/null extended-status |grep -w "Com_commit"|awk -F'|' '{print $3}'` echo $result ;; Bytes_sent) result=`${MYSQL_CONN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} 2>/dev/null extended-status |grep -w "Bytes_sent" |awk -F'|' '{print $3}'` echo $result ;; Bytes_received) result=`${MYSQL_CONN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} 2>/dev/null extended-status |grep -w "Bytes_received" |awk -F'|' '{print $3}'` echo $result ;; Com_begin) result=`${MYSQL_CONN} -u${MYSQL_USER} -p${MYSQL_PASSWORD} 2>/dev/null extended-status |grep -w "Com_begin"|awk -F'|' '{print $3}'` echo $result ;; *) echo "Usage:$0(Uptime|Threads|Questions|Questions_avg|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)" ;; esac
[root@zabbix scripts]# cd /usr/local/zabbix/etc/zabbix_agentd.conf.d/
[root@zabbix zabbix_agentd.conf.d]# ls
mysql_status.conf userparameter_mysql.conf
[root@zabbix zabbix_agentd.conf.d]# cat mysql_status.conf
UserParameter=mysql.status[*],/server/scripts/mysql.sh $1
#UserParameter=mysql.ping,HOME=/usr/local/zabbix/etc /usr/bin/mysqladmin -uroot -pshanyao@2020 ping|grep alive|wc -l
#UserParameter=mysql.version,mysql -V |awk '{print $5}'|sed 's/,//'
[root@zabbix zabbix_agentd.conf.d]#
注释的条目是我在配置系统自带模板的时候,名称冲突
重启zabbix-agentd,在item监控项里添加
后置创建图形 选中自建item项