首页 > 数据库技术 > 详细

zabbix监控mysql示例脚本

时间:2021-01-28 22:07:31      阅读:42      评论:0      收藏:0      [点我收藏+]
  • check_mysql.sh
#!/bin/bash
HOST=‘127.0.0.1‘
PORT=‘3306‘
CONN="mysqladmin -h ${HOST} -P ${PORT}"

if [ $# -ne "1" ]; then
	echo "arg error!"
fi

case $1 in
	update)
		result=$($CONN status | cut -d ":" -f2 | awk ‘{print $1}‘)
		echo $result
		;;
	Com_update)
		result=$($CONN extended-status | grep -w "Com_update"| cut -d "|" -f3 | sed ‘s/ //g‘)
		echo $result
		;;
	Slow_queries)
		result=$($CONN status |cut -d ":" -f5 | awk ‘{print $1}‘)
		echo $result
		;;
	Com_select)
		result=$($CONN extended-status |grep -w "Com_select" | cut -d "|" -f3 | sed ‘s/ //g‘)
		echo $result
		;;
	Com_rollback)
		result=$($CONN extended-status |grep -w "Com_rollback" | cut -d "|" -f3 | sed ‘s/ //g‘)
		echo $result
		;;
	Questions)
		result=$($CONN status|cut -f4 -d":"| awk ‘{print $1}‘)
		echo $result
		;;
	Com_insert)
		result=$($CONN extended-status |grep -w "Com_insert"| cut -d "|" -f3 | sed ‘s/ //g‘)
		echo $result
		;;
	Com_delete)
		result=$($CONN extended-status |grep -w "Com_delete"| cut -d "|" -f3 | sed ‘s/ //g‘)
		echo $result
		;;
	Com_commit)
		result=$($CONN extended-status |grep -w "Com_commit"| cut -d "|" -f3 | sed ‘s/ //g‘)
		echo $result
		;;
	Bytes_sent)
		result=$($CONN extended-status |grep -w "Bytes_sent"| cut -d "|" -f3 | sed ‘s/ //g‘)
		echo $result
		;;
	Bytes_received)
		result=$($CONN extended-status |grep -w "Bytes_received"| cut -d "|" -f3 | sed ‘s/ //g‘)
		echo $result
		;;
	Com_begin)
		result=$($CONN extended-status |grep -w "Com_begin"| cut -d "|" -f3 | sed ‘s/ //g‘)
		echo $result
		;;
	*)
		echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|C
om_begin)"
		;;
esac

zabbix监控mysql示例脚本

原文:https://www.cnblogs.com/ly447742/p/14342090.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!