-#!/bin/bash
+# no need for shebang - this file is loaded from charts.d.plugin
+
+# netdata
+# real-time performance and health monitoring, done right!
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
+# GPL v3+
+#
# http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html
#
local oIFS="${IFS}"
mysql_data=()
IFS=$'\t'$'\n'
- arr=($("${@}" -e "SHOW GLOBAL STATUS WHERE value REGEXP '^[0-9]';" | egrep "^(Bytes|Slow_|Queri|Handl|Table|Selec|Sort_|Creat|Conne|Abort|Binlo|Threa|Innod|Qcach|Key_|Open)" ))
+ #arr=($(run "${@}" -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=($(run "${@}" -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=($(run "${@}" -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
shift
fi
- [ -z "${mysql_cmd}" ] && mysql_cmd="$(which mysql)"
+ [ -z "${mysql_cmd}" ] && mysql_cmd="$(which mysql 2>/dev/null || command -v mysql 2>/dev/null)"
if [ ${#mysql_opts[@]} -eq 0 ]
then
[ -z "${mysql_cmds[$m]}" ] && mysql_cmds[$m]="$mysql_cmd"
if [ -z "${mysql_cmds[$m]}" ]
then
- echo >&2 "$PROGRAM_NAME: mysql: cannot get mysql command for '$m'. Please set mysql_cmds[$m]='/path/to/mysql', in $confd/mysql.conf"
+ error "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"
+ error "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]
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"
+ error "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
unset mysql_ids[$m]
unset mysql_opts[$m]
unset mysql_cmds[$m]
- echo >&2 "$PROGRAM_NAME: mysql: failed to get values for '$m', disabling it."
+ error "failed to get values for '$m', disabling it."
continue
fi
BEGIN mysql_$x.qcache_ops $1
SET Qcache_hits hits = ${mysql_data[Qcache_hits]}
SET Qcache_lowmem_prunes = ${mysql_data[Qcache_lowmem_prunes]}
-SET Qcache_inserts_inserts = ${mysql_data[Qcache_inserts_inserts]}
+SET Qcache_inserts = ${mysql_data[Qcache_inserts]}
SET Qcache_not_cached = ${mysql_data[Qcache_not_cached]}
END
BEGIN mysql_$x.qcache $1
fi
done
- [ ${#mysql_ids[@]} -eq 0 ] && echo >&2 "$PROGRAM_NAME: mysql: no mysql servers left active." && return 1
+ [ ${#mysql_ids[@]} -eq 0 ] && error "no mysql servers left active." && return 1
return 0
}