码迷,mamicode.com
首页 > 数据库 > 详细

zabbix监控mysql脚本

时间:2020-09-17 17:57:30      阅读:42      评论:0      收藏:0      [点我收藏+]

标签:back   ext   获取   grep   $0   err   ali   res   运行   

vim /usr/local/scripts/mysql_status.sh
#!/bin/bash
#Desc:zabbix 监控 MySQL 状态
#Date:2020-09-05
#by:Luojq
#主机
HOST="localhost"
#用户
USER="root"
#密码
PASSWORD="123456"
#端口
PORT="3306"
#MySQL连接
CONNECTION="mysqladmin -h ${HOST} -u ${USER} -P ${PORT} -p${PASSWORD}"
if [ $# -ne "1" ];then
echo "arg error!"
fi
case $1 in
Uptime)
result=${CONNECTION} status 2>/dev/null |awk ‘{print $2}‘
echo $result
;;
Questions)
result=${CONNECTION} status 2>/dev/null |awk ‘{print $6}‘
echo $result
;;
Com_update)
result=${CONNECTION} extended-status 2>/dev/null |grep -w "Com_update" |awk ‘{print $4}‘
echo $result
;;
Slow_queries)
result=${CONNECTION} extended-status 2>/dev/null |grep -w "Slow_queries" |awk ‘{print $4}‘
echo $result
;;
Com_select)
result=${CONNECTION} extended-status 2>/dev/null |grep -w "Com_select" |awk ‘{print $4}‘
echo $result
;;
Com_rollback)
result=${CONNECTION} extended-status 2>/dev/null |grep -w "Com_rollback" |awk ‘{print $4}‘
echo $result
;;
Com_insert)
result=${CONNECTION} extended-status 2>/dev/null |grep -w "Com_insert" |awk ‘{print $4}‘
echo $result
;;
Com_delete)
result=${CONNECTION} extended-status 2>/dev/null |grep -w "Com_delete" |awk ‘{print $4}‘
echo $result
;;
Com_commit)
result=${CONNECTION} extended-status 2>/dev/null |grep -w "Com_commit" |awk ‘{print $4}‘
echo $result
;;
Bytes_sent)
result=${CONNECTION} extended-status 2>/dev/null |grep -w "Bytes_sent" |awk ‘{print $4}‘
echo $result
;;
Bytes_received)
result=${CONNECTION} extended-status 2>/dev/null |grep -w "Bytes_received" |awk ‘{print $4}‘
echo $result
;;
Com_begin)
result=${CONNECTION} extended-status 2>/dev/null |grep -w "Com_begin" |awk ‘{print $4}‘
echo $result
;;*)
echo "Usage:$0(Uptime|Questions|Com_update|Slow_queries|Com_select|Com_rollback|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)"
;;
esac

vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
#获取MySQL性能指标,这个是上一步编辑好的脚本
UserParameter=mysql.status[*],/usr/local/scripts/mysql_status.sh $1
#获取MySQL运行状态
UserParameter=mysql.ping,mysqladmin -u root -h localhost -p123457 ping 2>/dev/null | grep -c alive
#获取MySQL版本
UserParameter=mysql.version,mysql -V

zabbix监控mysql脚本

标签:back   ext   获取   grep   $0   err   ali   res   运行   

原文地址:https://blog.51cto.com/13293070/2529875

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!