Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
# -------------------------------------------------------------------------------
# FileName: chk_mysql.sh
# Revision: 1.0
# Date: 2018/01/04
# Author: zouyi
# Description:
# License: MIT
# DB Connection
MYCONN="mysqladmin "
# check args
if [ $# -ne "1" ];then
echo "arg error!"
fi
check_extended_status()
{
data=$1
echo `$MYCONN extended-status | grep -w $data | cut -d '|' -f3`
}
# fetch data
case $1 in
Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)
check_extended_status $1
;;
Slow_queries)
result=`$MYCONN status |cut -f5 -d":"|cut -f1 -d"O"`
echo $result
;;
Questions)
result=`$MYCONN status|cut -f4 -d":"|cut -f1 -d"S"`
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|Com_begin)"
;;
esac
@php-cpm

This comment has been minimized.

Copy link
Owner Author

php-cpm commented Jan 4, 2018

vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf modify line mysql.status like this

UserParameter=mysql.status[*],HOME=/var/lib/zabbix /usr/local/share/zabbix/externalscripts/chk_mysql.sh $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.