# no need for shebang - this file is loaded from charts.d.plugin # http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html # # https://dev.mysql.com/doc/refman/5.1/en/show-status.html # SHOW STATUS provides server status information (see Section 5.1.6, “Server Status Variables”). # This statement does not require any privilege. # It requires only the ability to connect to the server. mysql_update_every=2 mysql_priority=60000 declare -A mysql_cmds=() mysql_opts=() mysql_ids=() mysql_data=() mysql_get() { local arr local oIFS="${IFS}" mysql_data=() IFS=$'\t'$'\n' #arr=($("${@}" -e "SHOW GLOBAL STATUS WHERE value REGEXP '^[0-9]';" | egrep "^(Bytes|Slow_|Que|Handl|Table|Selec|Sort_|Creat|Conne|Abort|Binlo|Threa|Innod|Qcach|Key_|Open)" )) #arr=($("${@}" -N -e "SHOW GLOBAL STATUS;" | egrep "^(Bytes|Slow_|Que|Handl|Table|Selec|Sort_|Creat|Conne|Abort|Binlo|Threa|Innod|Qcach|Key_|Open)[^ ]+\s[0-9]" )) arr=($("${@}" -N -e "SHOW GLOBAL STATUS;" | egrep "^(Bytes|Slow_|Que|Handl|Table|Selec|Sort_|Creat|Conne|Abort|Binlo|Threa|Innod|Qcach|Key_|Open)[^[:space:]]+[[:space:]]+[0-9]+" )) IFS="${oIFS}" [ "${#arr[@]}" -lt 3 ] && return 1 local end=${#arr[@]} for ((i=2;i&2 "$PROGRAM_NAME: mysql: cannot get mysql command for '$m'. Please set mysql_cmds[$m]='/path/to/mysql', in $confd/mysql.conf" fi mysql_get "${mysql_cmds[$m]}" ${mysql_opts[$m]} if [ ! $? -eq 0 ] then echo >&2 "$PROGRAM_NAME: mysql: cannot get global status for '$m'. Please set mysql_opts[$m]='options' to whatever needed to get connected to the mysql server, in $confd/mysql.conf" unset mysql_cmds[$m] unset mysql_opts[$m] unset mysql_ids[$m] continue fi mysql_ids[$m]="$( fixid "$m" )" done if [ ${#mysql_opts[@]} -eq 0 ] then if [ ${unconfigured} -eq 1 -a ${tryroot} -eq 0 ] then mysql_check tryroot "${@}" return $? else echo >&2 "$PROGRAM_NAME: mysql: no mysql servers found. Please set mysql_opts[name]='options' to whatever needed to get connected to the mysql server, in $confd/mysql.conf" return 1 fi fi return 0 } mysql_create() { local x # create the charts for x in "${mysql_ids[@]}" do cat <&2 "$PROGRAM_NAME: mysql: failed to get values for '$m', disabling it." continue fi # write the result of the work. cat <&2 "$PROGRAM_NAME: mysql: no mysql servers left active." && return 1 return 0 }