Skip to content

Instantly share code, notes, and snippets.

@php-cpm
Last active January 4, 2018 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save php-cpm/eb551b8c610bd4f176ea8cae37d7ecc8 to your computer and use it in GitHub Desktop.
Save php-cpm/eb551b8c610bd4f176ea8cae37d7ecc8 to your computer and use it in GitHub Desktop.
#!/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
Copy link
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