X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=charts.d%2Fmysql.chart.sh;h=1363d01f420c1a2ed19f4aabd0a319209030199f;hb=b060bae83cc36fdc4f14120228e4c9b0d1ec42e8;hp=9390f972fe9cf0439f60015613746b00441131bd;hpb=c5572d0ddaf88f58995cfe4f916494e714c2f7ca;p=netdata.git diff --git a/charts.d/mysql.chart.sh b/charts.d/mysql.chart.sh old mode 100755 new mode 100644 index 9390f972..1363d01f --- a/charts.d/mysql.chart.sh +++ b/charts.d/mysql.chart.sh @@ -1,4 +1,10 @@ -#!/bin/sh +# 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 +# GPL v3+ +# # http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html # @@ -7,75 +13,294 @@ # This statement does not require any privilege. # It requires only the ability to connect to the server. -mysql_cmd_opts= -mysql_update_every=5 +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=($(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 + local end=${#arr[@]} + for ((i=2;i&2 "mysql: cannot get global status. Please set mysql_cmd_opts='options' whatever needed to get connected to mysql server, in $confd/mysql.conf" - return 1 + for m in "${!mysql_opts[@]}" + do + [ -z "${mysql_cmds[$m]}" ] && mysql_cmds[$m]="$mysql_cmd" + if [ -z "${mysql_cmds[$m]}" ] + then + 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 + 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] + 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 + 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 return 0 } mysql_create() { + local x + # create the charts - cat <