X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=charts.d%2Fmysql.chart.sh;h=1363d01f420c1a2ed19f4aabd0a319209030199f;hb=b060bae83cc36fdc4f14120228e4c9b0d1ec42e8;hp=4fcbe7b1c79dc185ebde28d01819e4c100f96eb5;hpb=1f7a68fb4aec58088cd66267b263a0d421c5b3f1;p=netdata.git diff --git a/charts.d/mysql.chart.sh b/charts.d/mysql.chart.sh old mode 100755 new mode 100644 index 4fcbe7b1..1363d01f --- a/charts.d/mysql.chart.sh +++ b/charts.d/mysql.chart.sh @@ -1,4 +1,10 @@ -#!/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 +# GPL v3+ +# # http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html # @@ -7,139 +13,31 @@ # This statement does not require any privilege. # It requires only the ability to connect to the server. -mysql_update_every=5 +mysql_update_every=2 mysql_priority=60000 -declare -A mysql_cmds=() mysql_opts=() mysql_ids=() - -mysql_exec() { - local ret +declare -A mysql_cmds=() mysql_opts=() mysql_ids=() mysql_data=() - "${@}" -s -e "show global status;" - ret=$? +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 "$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] @@ -205,7 +103,7 @@ mysql_check() { 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 @@ -380,7 +278,7 @@ CHART mysql_$x.files_rate '' "mysql Opened Files Rate" "files/s" files mysql.fil DIMENSION Opened_files files incremental 1 1 EOF - if [ ! -z "$mysql_Binlog_stmt_cache_disk_use" ] + if [ ! -z "${mysql_data[Binlog_stmt_cache_disk_use]}" ] then cat <&2 "$PROGRAM_NAME: mysql: failed to get values for '$m', disabling it." + error "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 + [ ${#mysql_ids[@]} -eq 0 ] && error "no mysql servers left active." && return 1 return 0 }