better log management for charts.d.plugin - fixes #1144
Costa Tsaousis (ktsaou) committed
Oct 20, 2016 at 22:04 UTC
addb52bb18ba356fc1cb5888b1fe5b809137346d
19 files changed
+236
-205
charts.d/ap.chart.sh
+2
-3
@@ -7,13 +7,11 @@ ap_priority=6900
7
8
declare -A ap_devs=()
9
10
-export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
11
-
10
# _check is called once, to find out if this chart should be enabled or not
11
ap_check() {
12
require_cmd iw || return 1
13
16
- local ev=$(iw dev | awk '
14
+ local ev=$(run iw dev | awk '
15
BEGIN {
16
i = "";
17
ssid = "";
@@ -43,6 +41,7 @@ ap_check() {
41
# - 1 to disable the chart
42
43
[ ${#ap_devs[@]} -gt 0 ] && return 0
44
+ error "no devices found in AP mode, with 'iw dev'"
45
return 1
46
}
47
charts.d/apache.chart.sh
+11
-11
@@ -67,14 +67,14 @@ apache_detect() {
67
68
# we will not check of the Conns*
69
# keys, since these are apache 2.4 specific
70
- [ -z "${apache_key_accesses}" ] && echo >&2 "apache: missing 'Total Accesses' from apache server: ${*}" && return 1
71
- [ -z "${apache_key_kbytes}" ] && echo >&2 "apache: missing 'Total kBytes' from apache server: ${*}" && return 1
72
- [ -z "${apache_key_reqpersec}" ] && echo >&2 "apache: missing 'ReqPerSec' from apache server: ${*}" && return 1
73
- [ -z "${apache_key_bytespersec}" ] && echo >&2 "apache: missing 'BytesPerSec' from apache server: ${*}" && return 1
74
- [ -z "${apache_key_bytesperreq}" ] && echo >&2 "apache: missing 'BytesPerReq' from apache server: ${*}" && return 1
75
- [ -z "${apache_key_busyworkers}" ] && echo >&2 "apache: missing 'BusyWorkers' from apache server: ${*}" && return 1
76
- [ -z "${apache_key_idleworkers}" ] && echo >&2 "apache: missing 'IdleWorkers' from apache server: ${*}" && return 1
77
- [ -z "${apache_key_scoreboard}" ] && echo >&2 "apache: missing 'Scoreboard' from apache server: ${*}" && return 1
70
+ [ -z "${apache_key_accesses}" ] && error "missing 'Total Accesses' from apache server: ${*}" && return 1
71
+ [ -z "${apache_key_kbytes}" ] && error "missing 'Total kBytes' from apache server: ${*}" && return 1
72
+ [ -z "${apache_key_reqpersec}" ] && error "missing 'ReqPerSec' from apache server: ${*}" && return 1
73
+ [ -z "${apache_key_bytespersec}" ] && error "missing 'BytesPerSec' from apache server: ${*}" && return 1
74
+ [ -z "${apache_key_bytesperreq}" ] && error "missing 'BytesPerReq' from apache server: ${*}" && return 1
75
+ [ -z "${apache_key_busyworkers}" ] && error "missing 'BusyWorkers' from apache server: ${*}" && return 1
76
+ [ -z "${apache_key_idleworkers}" ] && error "missing 'IdleWorkers' from apache server: ${*}" && return 1
77
+ [ -z "${apache_key_scoreboard}" ] && error "missing 'Scoreboard' from apache server: ${*}" && return 1
78
79
if [ ! -z "${apache_key_connstotal}" \
80
-a ! -z "${apache_key_connsasyncwriting}" \
@@ -92,7 +92,7 @@ apache_detect() {
92
93
apache_get() {
94
local oIFS="${IFS}" ret
95
- IFS=$':\n' apache_response=($(curl -Ss ${apache_curl_opts} "${apache_url}"))
95
+ IFS=$':\n' apache_response=($(run curl -Ss ${apache_curl_opts} "${apache_url}"))
96
ret=$?
97
IFS="${oIFS}"
98
@@ -130,7 +130,7 @@ apache_get() {
130
-o -z "${apache_idleworkers}" \
131
]
132
then
133
- echo >&2 "apache: empty values got from apache server: ${apache_response[*]}"
133
+ error "empty values got from apache server: ${apache_response[*]}"
134
return 1
135
fi
136
@@ -151,7 +151,7 @@ apache_check() {
151
apache_get
152
if [ $? -ne 0 ]
153
then
154
- echo >&2 "apache: cannot find stub_status on URL '${apache_url}'. Please set apache_url='http://apache.server:80/server-status?auto' in $confd/apache.conf"
154
+ error "cannot find stub_status on URL '${apache_url}'. Please set apache_url='http://apache.server:80/server-status?auto' in $confd/apache.conf"
155
return 1
156
fi
157
charts.d/apcupsd.chart.sh
+5
-5
@@ -12,7 +12,7 @@ apcupsd_timeout=3
12
apcupsd_priority=90000
13
14
apcupsd_get() {
15
- timeout $apcupsd_timeout apcaccess status "$1:$2"
15
+ run -t $apcupsd_timeout apcaccess status "$1:$2"
16
}
17
18
apcupsd_check() {
@@ -23,14 +23,14 @@ apcupsd_check() {
23
24
require_cmd apcaccess || return 1
25
26
- apcupsd_get $apcupsd_ip $apcupsd_port >/dev/null
26
+ run apcupsd_get $apcupsd_ip $apcupsd_port >/dev/null
27
if [ $? -ne 0 ]
28
then
29
- echo >&2 "apcupsd: ERROR: Cannot get information for apcupsd server."
29
+ error "cannot get information for apcupsd server."
30
return 1
31
elif [ $(apcupsd_get $apcupsd_ip $apcupsd_port | awk '/^STATUS.*/{ print $3 }') != "ONLINE" ]
32
then
33
- echo >&2 "apcupsd: ERROR: UPS not online."
33
+ error "APC UPS not online."
34
return 1
35
fi
36
@@ -146,7 +146,7 @@ END {
146
print \"SET time = \" time;
147
print \"END\"
148
}"
149
- [ $? -ne 0 ] && echo >&2 "apcupsd: failed to get values" && return 1
149
+ [ $? -ne 0 ] && error "failed to get values" && return 1
150
151
return 0
152
}
charts.d/cpu_apps.chart.sh
+1
-1
@@ -19,7 +19,7 @@ cpu_apps_check() {
19
20
if [ -z "$cpu_apps_apps" ]
21
then
22
- echo >&2 "$PROGRAM_NAME: cpu_apps: Please set cpu_apps_apps='command1 command2 ...' in $confd/cpu_apps_apps.conf"
22
+ error "manual configuration required: please set cpu_apps_apps='command1 command2 ...' in $confd/cpu_apps_apps.conf"
23
return 1
24
fi
25
return 0
charts.d/cpufreq.chart.sh
+1
-2
@@ -51,7 +51,7 @@ cpufreq_create() {
51
52
id="$( fixid "cpu$cpu" )"
53
54
- echo >&2 "charts.d: cpufreq: on file='$file', dir='$dir', cpu='$cpu', id='$id'"
54
+ debug "file='$file', dir='$dir', cpu='$cpu', id='$id'"
55
56
echo "DIMENSION $id '$id' absolute 1 1000"
57
echo >>$TMP_DIR/cpufreq.sh "echo \"SET $id = \"\$(< $file )"
@@ -59,7 +59,6 @@ cpufreq_create() {
59
echo >>$TMP_DIR/cpufreq.sh "echo END"
60
61
[ $cpufreq_source_update -eq 1 ] && echo >>$TMP_DIR/cpufreq.sh "}"
62
- # cat >&2 $TMP_DIR/cpufreq.sh
62
63
# ok, load the function cpufreq_update() we created
64
[ $cpufreq_source_update -eq 1 ] && . $TMP_DIR/cpufreq.sh
charts.d/example.chart.sh
+1
-2
@@ -67,7 +67,7 @@ example_check() {
67
# - 1 to disable the chart
68
69
# check something
70
- [ "${example_magic_number}" != "12345" ] && echo >&2 "example: you have to set example_magic_number=$example_magic_number in example.conf to start example chart." && return 1
70
+ [ "${example_magic_number}" != "12345" ] && error "manual configuration required: you have to set example_magic_number=$example_magic_number in example.conf to start example chart." && return 1
71
72
# check that we can collect data
73
example_get || return 1
@@ -108,7 +108,6 @@ BEGIN example.random2 $1
108
SET random = $example_value4
109
END
110
VALUESEOF
111
- # echo >&2 "example_count = $example_count value = $value4"
111
112
return 0
113
}
charts.d/exim.chart.sh
+14
-26
@@ -1,5 +1,6 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# the exim command to run
4
exim_command=
5
6
# how frequently to collect queue size
@@ -8,28 +9,15 @@ exim_update_every=5
9
exim_priority=60000
10
11
exim_check() {
11
- if [ -z "$exim_command" -o ! -x "$exim_command" ]
12
- then
13
- local d=
14
- for d in /sbin /usr/sbin /usr/local/sbin
15
- do
16
- if [ -x "$d/exim" ]
17
- then
18
- exim_command="$d/exim"
19
- break
20
- fi
21
- done
22
- fi
23
-
24
- if [ -z "$exim_command" -o ! -x "$exim_command" ]
25
- then
26
- echo >&2 "$PROGRAM_NAME: exim: cannot find exim executable. Please set 'exim_command=/path/to/exim' in $confd/exim.conf"
27
- return 1
28
- fi
12
+ if [ -z "${exim_command}" ]
13
+ then
14
+ require_cmd exim || return 1
15
+ exim_command="${EXIM_CMD}"
16
+ fi
17
30
- if [ `$exim_command -bpc 2>&1 | grep -c denied` -ne 0 ]
18
+ if [ $(${exim_command} -bpc 2>&1 | grep -c denied) -ne 0 ]
19
then
32
- echo >&2 "$PROGRAM_NAME: exim: permission denied. Please set 'queue_list_requires_admin = false' in your exim options file"
20
+ error "permission denied - please set 'queue_list_requires_admin = false' in your exim options file"
21
return 1
22
fi
23
@@ -37,16 +25,16 @@ exim_check() {
25
}
26
27
exim_create() {
40
-cat <<EOF
28
+ cat <<EOF
29
CHART exim_local.qemails '' "Exim Queue Emails" "emails" queue exim.queued.emails line $((exim_priority + 1)) $exim_update_every
30
DIMENSION emails '' absolute 1 1
31
EOF
44
-return 0
32
+ return 0
33
}
34
35
exim_update() {
48
-echo "BEGIN exim_local.qemails $1"
49
-echo "SET emails = " `$exim_command -bpc`
50
-echo "END"
51
-return 0
36
+ echo "BEGIN exim_local.qemails $1"
37
+ echo "SET emails = " $(run ${exim_command} -bpc)
38
+ echo "END"
39
+ return 0
40
}
charts.d/hddtemp.chart.sh
+2
-1
@@ -13,7 +13,8 @@ hddtemp_priority=90000
13
14
# _check is called once, to find out if this chart should be enabled or not
15
hddtemp_check() {
16
- nc $hddtemp_host $hddtemp_port &>/dev/null && return 0 || return 1
16
+ require_cmd nc || return 1
17
+ run nc $hddtemp_host $hddtemp_port && return 0 || return 1
18
}
19
20
# _create is called once, to create the charts
charts.d/mem_apps.chart.sh
+1
-1
@@ -15,7 +15,7 @@ mem_apps_check() {
15
16
if [ -z "$mem_apps_apps" ]
17
then
18
- echo >&2 "$PROGRAM_NAME: mem_apps: not configured. Please set mem_apps_apps='command1 command2 ...' in $confd/mem_apps_apps.conf"
18
+ error "manual configuration required: please set mem_apps_apps='command1 command2 ...' in $confd/mem_apps_apps.conf"
19
return 1
20
fi
21
return 0
charts.d/mysql.chart.sh
+8
-8
@@ -17,9 +17,9 @@ mysql_get() {
17
local oIFS="${IFS}"
18
mysql_data=()
19
IFS=$'\t'$'\n'
20
- #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)" ))
21
- #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]" ))
22
- 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]+" ))
20
+ #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)" ))
21
+ #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]" ))
22
+ 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]+" ))
23
IFS="${oIFS}"
24
25
[ "${#arr[@]}" -lt 3 ] && return 1
@@ -74,13 +74,13 @@ mysql_check() {
74
[ -z "${mysql_cmds[$m]}" ] && mysql_cmds[$m]="$mysql_cmd"
75
if [ -z "${mysql_cmds[$m]}" ]
76
then
77
- echo >&2 "$PROGRAM_NAME: mysql: cannot get mysql command for '$m'. Please set mysql_cmds[$m]='/path/to/mysql', in $confd/mysql.conf"
77
+ error "cannot get mysql command for '$m'. Please set mysql_cmds[$m]='/path/to/mysql', in $confd/mysql.conf"
78
fi
79
80
mysql_get "${mysql_cmds[$m]}" ${mysql_opts[$m]}
81
if [ ! $? -eq 0 ]
82
then
83
- 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"
83
+ 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"
84
unset mysql_cmds[$m]
85
unset mysql_opts[$m]
86
unset mysql_ids[$m]
@@ -97,7 +97,7 @@ mysql_check() {
97
mysql_check tryroot "${@}"
98
return $?
99
else
100
- 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"
100
+ 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"
101
return 1
102
fi
103
fi
@@ -318,7 +318,7 @@ mysql_update() {
318
unset mysql_ids[$m]
319
unset mysql_opts[$m]
320
unset mysql_cmds[$m]
321
- echo >&2 "$PROGRAM_NAME: mysql: failed to get values for '$m', disabling it."
321
+ error "failed to get values for '$m', disabling it."
322
continue
323
fi
324
@@ -510,7 +510,7 @@ VALUESEOF
510
fi
511
done
512
513
- [ ${#mysql_ids[@]} -eq 0 ] && echo >&2 "$PROGRAM_NAME: mysql: no mysql servers left active." && return 1
513
+ [ ${#mysql_ids[@]} -eq 0 ] && error "no mysql servers left active." && return 1
514
return 0
515
}
516
charts.d/nginx.chart.sh
+4
-4
@@ -20,7 +20,7 @@ nginx_reading=0
20
nginx_writing=0
21
nginx_waiting=0
22
nginx_get() {
23
- nginx_response=($(curl -Ss ${nginx_curl_opts} "${nginx_url}"))
23
+ nginx_response=($(run curl -Ss ${nginx_curl_opts} "${nginx_url}"))
24
[ $? -ne 0 -o "${#nginx_response[@]}" -eq 0 ] && return 1
25
26
if [ "${nginx_response[0]}" != "Active" \
@@ -34,7 +34,7 @@ nginx_get() {
34
-o "${nginx_response[14]}" != "Waiting:" \
35
]
36
then
37
- echo >&2 "nginx: Invalid response from nginx server: ${nginx_response[*]}"
37
+ error "Invalid response from nginx server: ${nginx_response[*]}"
38
return 1
39
fi
40
@@ -55,7 +55,7 @@ nginx_get() {
55
-o -z "${nginx_waiting}" \
56
]
57
then
58
- echo >&2 "nginx: empty values got from nginx server: ${nginx_response[*]}"
58
+ error "empty values got from nginx server: ${nginx_response[*]}"
59
return 1
60
fi
61
@@ -68,7 +68,7 @@ nginx_check() {
68
nginx_get
69
if [ $? -ne 0 ]
70
then
71
- echo >&2 "nginx: cannot find stub_status on URL '${nginx_url}'. Please set nginx_url='http://nginx.server/stub_status' in $confd/nginx.conf"
71
+ error "cannot find stub_status on URL '${nginx_url}'. Please set nginx_url='http://nginx.server/stub_status' in $confd/nginx.conf"
72
return 1
73
fi
74
charts.d/nut.chart.sh
+6
-6
@@ -15,11 +15,11 @@ nut_priority=90000
15
declare -A nut_ids=()
16
17
nut_get_all() {
18
- timeout $nut_timeout upsc -l
18
+ run -t $nut_timeout upsc -l
19
}
20
21
nut_get() {
22
- timeout $nut_timeout upsc "$1"
22
+ run -t $nut_timeout upsc "$1"
23
}
24
25
nut_check() {
@@ -42,12 +42,12 @@ nut_check() {
42
nut_ids[$x]="$( fixid "$x" )"
43
continue
44
fi
45
- echo >&2 "nut: ERROR: Cannot get information for NUT UPS '$x'."
45
+ error "cannot get information for NUT UPS '$x'."
46
done
47
48
if [ ${#nut_ids[@]} -eq 0 ]
49
then
50
- echo >&2 "nut: Please set nut_ups='ups_name' in $confd/nut.conf"
50
+ error "Cannot find UPSes - please set nut_ups='ups_name' in $confd/nut.conf"
51
return 1
52
fi
53
@@ -179,9 +179,9 @@ END {
179
print \"SET temp = \" temp;
180
print \"END\"
181
}"
182
- [ $? -ne 0 ] && unset nut_ids[$i] && echo >&2 "nut: failed to get values for '$i', disabling it."
182
+ [ $? -ne 0 ] && unset nut_ids[$i] && error "failed to get values for '$i', disabling it."
183
done
184
185
- [ ${#nut_ids[@]} -eq 0 ] && echo >&2 "nut: no UPSes left active." && return 1
185
+ [ ${#nut_ids[@]} -eq 0 ] && error "no UPSes left active." && return 1
186
return 0
187
}
charts.d/opensips.chart.sh
+3
-3
@@ -7,7 +7,7 @@ opensips_timeout=2
7
opensips_priority=80000
8
9
opensips_get_stats() {
10
- timeout $opensips_timeout "$opensips_cmd" $opensips_opts |\
10
+ run -t $opensips_timeout "$opensips_cmd" $opensips_opts |\
11
grep "^\(core\|dialog\|net\|registrar\|shmem\|siptrace\|sl\|tm\|uri\|usrloc\):[a-zA-Z0-9_-]\+[[:space:]]*[=:]\+[[:space:]]*[0-9]\+[[:space:]]*$" |\
12
sed \
13
-e "s|[[:space:]]*[=:]\+[[:space:]]*\([0-9]\+\)[[:space:]]*$|=\1|g" \
@@ -31,7 +31,7 @@ opensips_check() {
31
local x="$(opensips_get_stats | grep "^opensips_core_")"
32
if [ ! $? -eq 0 -o -z "$x" ]
33
then
34
- echo >&2 "$PROGRAM_NAME: opensips: cannot get global status. Please set opensips_opts='options' whatever needed to get connected to opensips server, in $confd/opensips.conf"
34
+ error "cannot get global status. Please set opensips_opts='options' whatever needed to get connected to opensips server, in $confd/opensips.conf"
35
return 1
36
fi
37
@@ -214,7 +214,7 @@ opensips_update() {
214
eval "local $(opensips_get_stats)"
215
[ $? -ne 0 ] && return 1
216
217
- [ $opensips_command_failed -eq 1 ] && echo >&2 "$PROGRAM_NAME: opensips: failed to get values, disabling." && return 1
217
+ [ $opensips_command_failed -eq 1 ] && error "failed to get values, disabling." && return 1
218
219
# write the result of the work.
220
cat <<VALUESEOF
charts.d/phpfpm.chart.sh
+5
-5
@@ -32,7 +32,7 @@ phpfpm_slow_requests=0
32
phpfpm_get() {
33
local opts="${1}" url="${2}"
34
35
- phpfpm_response=($(curl -Ss ${opts} "${url}"))
35
+ phpfpm_response=($(run curl -Ss ${opts} "${url}"))
36
[ $? -ne 0 -o "${#phpfpm_response[@]}" -eq 0 ] && return 1
37
38
if [[ "${phpfpm_response[0]}" != "pool:" \
@@ -46,7 +46,7 @@ phpfpm_get() {
46
|| "${phpfpm_response[32]}" != "total" \
47
]]
48
then
49
- echo >&2 "phpfpm: invalid response from phpfpm status server: ${phpfpm_response[*]}"
49
+ error "invalid response from phpfpm status server: ${phpfpm_response[*]}"
50
return 1
51
fi
52
@@ -83,7 +83,7 @@ phpfpm_get() {
83
|| -z "${phpfpm_max_children_reached}" \
84
]]
85
then
86
- echo >&2 "phpfpm: empty values got from phpfpm status server: ${phpfpm_response[*]}"
86
+ error "empty values got from phpfpm status server: ${phpfpm_response[*]}"
87
return 1
88
fi
89
@@ -101,14 +101,14 @@ phpfpm_check() {
101
do
102
phpfpm_get "${phpfpm_curl_opts[$m]}" "${phpfpm_urls[$m]}"
103
if [ $? -ne 0 ]; then
104
- echo >&2 "phpfpm: cannot find status on URL '${phpfpm_url[$m]}'. Please set phpfpm_urls[$m]='http://localhost/status' in $confd/phpfpm.conf"
104
+ error "cannot find status on URL '${phpfpm_url[$m]}'. Please set phpfpm_urls[$m]='http://localhost/status' in $confd/phpfpm.conf"
105
unset phpfpm_urls[$m]
106
continue
107
fi
108
done
109
110
if [ ${#phpfpm_urls[@]} -eq 0 ]; then
111
- echo >&2 "phpfpm: no phpfpm servers found. Please set phpfpm_urls[name]='url' to whatever needed to get status to the phpfpm server, in $confd/phpfpm.conf"
111
+ error "no phpfpm servers found. Please set phpfpm_urls[name]='url' to whatever needed to get status to the phpfpm server, in $confd/phpfpm.conf"
112
return 1
113
fi
114
charts.d/postfix.chart.sh
+3
-15
@@ -18,23 +18,11 @@ postfix_check() {
18
if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ]
19
then
20
postfix_postqueue="`which postqueue 2>/dev/null`"
21
- if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ]
22
- then
23
- local d=
24
- for d in /sbin /usr/sbin /usr/local/sbin
25
- do
26
- if [ -x "$d/postqueue" ]
27
- then
28
- postfix_postqueue="$d/postqueue"
29
- break
30
- fi
31
- done
32
- fi
21
fi
22
23
if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ]
24
then
37
- echo >&2 "$PROGRAM_NAME: postfix: cannot find postqueue. Please set 'postfix_postqueue=/path/to/postqueue' in $confd/postfix.conf"
25
+ error "cannot find postqueue. Please set 'postfix_postqueue=/path/to/postqueue' in $confd/postfix.conf"
26
return 1
27
fi
28
@@ -73,10 +61,10 @@ postfix_update() {
61
postfix_q_emails=0
62
postfix_q_size=0
63
76
- eval "`$postfix_postqueue -p |\
64
+ eval "$(run $postfix_postqueue -p |\
65
grep "^--" |\
66
sed -e "s/-- \([0-9]\+\) Kbytes in \([0-9]\+\) Requests.$/local postfix_q_size=\1\nlocal postfix_q_emails=\2/g" |\
79
- egrep "^local postfix_q_(emails|size)=[0-9]+$"`"
67
+ egrep "^local postfix_q_(emails|size)=[0-9]+$")"
68
69
# write the result of the work.
70
cat <<VALUESEOF
charts.d/sensors.chart.sh
+4
-5
@@ -43,7 +43,7 @@ sensors_check() {
43
# - 0 to enable the chart
44
# - 1 to disable the chart
45
46
- [ -z "$( sensors_find_all_files $sensors_sys_dir )" ] && echo >&2 "$PROGRAM_NAME: sensors: no sensors found in '$sensors_sys_dir'." && return 1
46
+ [ -z "$( sensors_find_all_files $sensors_sys_dir )" ] && error "no sensors found in '$sensors_sys_dir'." && return 1
47
return 0
48
}
49
@@ -64,7 +64,7 @@ sensors_check_files() {
64
[ $v -ne 0 ] && echo "$f" && continue
65
excluded=
66
67
- echo >&2 "$PROGRAM_NAME: sensors: $f gives zero values"
67
+ error "$f gives zero values"
68
done
69
}
70
@@ -83,7 +83,7 @@ sensors_check_temp_type() {
83
v=$(( v + 1 - 1 ))
84
[ $v -ne 0 ] && echo "$f" && continue
85
86
- echo >&2 "$PROGRAM_NAME: sensors: $f is disabled"
86
+ error "$f is disabled"
87
done
88
}
89
@@ -121,7 +121,7 @@ sensors_create() {
121
122
id="$( fixid "$device.$subsystem.$dir" )"
123
124
- echo >&2 "charts.d: sensors: on path='$path', dir='$dir', device='$device', subsystem='$subsystem', id='$id', name='$name'"
124
+ debug "path='$path', dir='$dir', device='$device', subsystem='$subsystem', id='$id', name='$name'"
125
126
for mode in temperature voltage fans power current energy humidity
127
do
@@ -221,7 +221,6 @@ sensors_create() {
221
done
222
223
[ $sensors_source_update -eq 1 ] && echo >>$TMP_DIR/sensors.sh "}"
224
- # cat >&2 $TMP_DIR/sensors.sh
224
225
# ok, load the function sensors_update() we created
226
[ $sensors_source_update -eq 1 ] && . $TMP_DIR/sensors.sh
charts.d/squid.chart.sh
+4
-4
@@ -9,7 +9,7 @@ squid_priority=60000
9
10
squid_get_stats_internal() {
11
local host="$1" port="$2" url="$3"
12
- squidclient -h $host -p $port $url
12
+ run squidclient -h $host -p $port $url
13
}
14
15
squid_get_stats() {
@@ -29,13 +29,13 @@ squid_autodetect() {
29
squid_host="$host"
30
squid_port="$port"
31
squid_url="$url"
32
- echo >&2 "squid: found squid at '$host:$port' with url '$url'"
32
+ debug "found squid at '$host:$port' with url '$url'"
33
return 0
34
fi
35
done
36
done
37
38
- echo >&2 "squid: cannot find squid running in localhost. Please set squid_url='url' and squid_host='IP' and squid_port='PORT' in $confd/squid.conf"
38
+ error "cannot find squid running in localhost. Please set squid_url='url' and squid_host='IP' and squid_port='PORT' in $confd/squid.conf"
39
return 1
40
}
41
@@ -53,7 +53,7 @@ squid_check() {
53
local x="$(squid_get_stats | grep client_http.requests)"
54
if [ ! $? -eq 0 -o -z "$x" ]
55
then
56
- echo >&2 "squid: cannot fetch URL '$squid_url' by connecting to $squid_host:$squid_port. Please set squid_url='url' and squid_host='host' and squid_port='port' in $confd/squid.conf"
56
+ error "cannot fetch URL '$squid_url' by connecting to $squid_host:$squid_port. Please set squid_url='url' and squid_host='host' and squid_port='port' in $confd/squid.conf"
57
return 1
58
fi
59
charts.d/tomcat.chart.sh
+6
-7
@@ -34,13 +34,13 @@ tomcat_check() {
34
35
# check if url, username, passwords are set
36
if [ -z "${tomcat_url}" ]; then
37
- echo >&2 "tomcat url is unset or set to the empty string"
37
+ error "tomcat url is unset or set to the empty string"
38
return 1
39
fi
40
if [ -z "${tomcat_user}" ]; then
41
# check backwards compatibility
42
if [ -z "${tomcatUser}" ]; then
43
- echo >&2 "tomcat user is unset or set to the empty string"
43
+ error "tomcat user is unset or set to the empty string"
44
return 1
45
else
46
tomcat_user="${tomcatUser}"
@@ -49,7 +49,7 @@ tomcat_check() {
49
if [ -z "${tomcat_password}" ]; then
50
# check backwards compatibility
51
if [ -z "${tomcatPassword}" ]; then
52
- echo >&2 "tomcat password is unset or set to the empty string"
52
+ error "tomcat password is unset or set to the empty string"
53
return 1
54
else
55
tomcat_password="${tomcatPassword}"
@@ -60,8 +60,7 @@ tomcat_check() {
60
tomcat_get
61
if [ $? -ne 0 ]
62
then
63
- echo >&2 "tomcat: couldn't get to status page on URL '${tomcat_url}'."\
64
- "Please make sure tomcat url, username and password are correct."
63
+ error "cannot get to status page on URL '${tomcat_url}'. Please make sure tomcat url, username and password are correct."
64
return 1
65
fi
66
@@ -75,8 +74,8 @@ tomcat_check() {
74
tomcat_get() {
75
# collect tomcat values
76
tomcat_port="$(IFS=/ read -ra a <<< "$tomcat_url"; hostport=${a[2]}; echo "${hostport#*:}")"
78
- mapfile -t lines < <(curl -u "$tomcat_user":"$tomcat_password" -Ss ${tomcat_curl_opts} "$tomcat_url" |\
79
- xmlstarlet sel \
77
+ mapfile -t lines < <(run curl -u "$tomcat_user":"$tomcat_password" -Ss ${tomcat_curl_opts} "$tomcat_url" |\
78
+ run xmlstarlet sel \
79
-t -m "/status/jvm/memory" -v @free \
80
-n -m "/status/connector[@name='\"http-bio-$tomcat_port\"']/threadInfo" -v @currentThreadCount \
81
-n -v @currentThreadsBusy \
plugins.d/charts.d.plugin
+155
-96
@@ -1,8 +1,11 @@
1
#!/usr/bin/env bash
2
3
+export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
4
+
5
PROGRAM_FILE="$0"
6
PROGRAM_NAME="$(basename $0)"
7
PROGRAM_NAME="${PROGRAM_NAME/.plugin}"
8
+MODULE_NAME="main"
9
10
# if you need to run parallel charts.d processes
11
# just link this files with a different name
@@ -10,27 +13,77 @@ PROGRAM_NAME="${PROGRAM_NAME/.plugin}"
13
# netdata will start multiple of them
14
# each will have a different config file
15
13
-echo >&2 "$PROGRAM_NAME: started from '$PROGRAM_FILE' with options: $*"
16
+# -----------------------------------------------------------------------------
17
+# create temp dir
18
+
19
+debug=0
20
+TMP_DIR=
21
+chartsd_cleanup() {
22
+ if [ ! -z "$TMP_DIR" -a -d "$TMP_DIR" ]
23
+ then
24
+ [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: cleaning up temporary directory $TMP_DIR ..."
25
+ rm -rf "$TMP_DIR"
26
+ fi
27
+ exit 0
28
+}
29
+trap chartsd_cleanup EXIT
30
+trap chartsd_cleanup SIGHUP
31
+trap chartsd_cleanup INT
32
15
-if [ $(( ${BASH_VERSINFO[0]} )) -lt 4 ]
33
+if [ $UID = "0" ]
34
then
17
- echo >&2
18
- echo >&2 "$PROGRAM_NAME: ERROR"
19
- echo >&2 "BASH version 4 or later is required."
20
- echo >&2 "You are running version: ${BASH_VERSION}"
21
- echo >&2 "Please upgrade."
22
- echo >&2
23
- exit 1
35
+ TMP_DIR="$( mktemp -d /var/run/netdata-${PROGRAM_NAME}-XXXXXXXXXX )"
36
+else
37
+ TMP_DIR="$( mktemp -d /tmp/.netdata-${PROGRAM_NAME}-XXXXXXXXXX )"
38
fi
39
40
+logdate() {
41
+ date "+%Y-%m-%d %H:%M:%S"
42
+}
43
+
44
+log() {
45
+ local status="${1}"
46
+ shift
47
+
48
+ echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${MODULE_NAME}: ${*}"
49
+
50
+}
51
+
52
+warning() {
53
+ log WARNING "${@}"
54
+}
55
+
56
+error() {
57
+ log ERROR "${@}"
58
+}
59
+
60
+info() {
61
+ log INFO "${@}"
62
+}
63
+
64
+fatal() {
65
+ log FATAL "${@}"
66
+ echo "DISABLE"
67
+ exit 1
68
+}
69
+
70
+debug() {
71
+ [ $debug -eq 1 ] && log DEBUG "${@}"
72
+}
73
+
74
+# -----------------------------------------------------------------------------
75
# check a few commands
76
+
77
require_cmd() {
28
- which "$1" >/dev/null
29
- if [ $? -ne 0 ]
78
+ local x=$(which "${1}" 2>/dev/null || command -v "${1}" 2>/dev/null)
79
+ if [ -z "${x}" -o ! -x "${x}" ]
80
then
31
- echo >&2 "$PROGRAM_NAME: ERROR: Command '$1' is not found in the system path."
81
+ warning "command '${1}' is not found in ${PATH}."
82
+ eval "${1^^}_CMD=\"\""
83
return 1
84
fi
85
+
86
+ eval "${1^^}_CMD=\"${x}\""
87
return 0
88
}
89
@@ -43,9 +96,17 @@ require_cmd grep || exit 1
96
require_cmd egrep || exit 1
97
require_cmd mktemp || exit 1
98
require_cmd awk || exit 1
99
+require_cmd timeout || exit 1
100
+require_cmd curl || exit 1
101
+
102
+# -----------------------------------------------------------------------------
103
+
104
+[ $(( ${BASH_VERSINFO[0]} )) -lt 4 ] && fatal "BASH version 4 or later is required, but found version: ${BASH_VERSION}. Please upgrade."
105
+
106
+info "started from '$PROGRAM_FILE' with options: $*"
107
108
# -----------------------------------------------------------------------------
48
-# insternal defaults
109
+# internal defaults
110
# netdata exposes a few environment variables for us
111
112
pluginsd="${NETDATA_PLUGINS_DIR}"
@@ -97,7 +158,6 @@ enable_all_charts="yes"
158
# -----------------------------------------------------------------------------
159
# parse parameters
160
100
-debug=0
161
check=0
162
chart_only=
163
while [ ! -z "$1" ]
@@ -143,9 +203,7 @@ do
203
continue
204
fi
205
146
- echo >&2 "Cannot understand parameter $1. Aborting."
147
- echo "DISABLE"
148
- exit 1
206
+ fatal "Cannot understand parameter $1. Aborting."
207
done
208
209
@@ -173,17 +231,13 @@ mysleep="sleep"
231
if [ -f "$myconfig" ]
232
then
233
. "$myconfig"
176
- if [ $? -ne 0 ]
177
- then
178
- echo >&2 "$PROGRAM_NAME: cannot load $myconfig"
179
- echo "DISABLE"
180
- exit 1
181
- fi
234
+ [ $? -ne 0 ] && fatal "cannot load $myconfig"
235
+
236
time_divisor=$((time_divisor))
237
[ $time_divisor -lt 10 ] && time_divisor=10
238
[ $time_divisor -gt 100 ] && time_divisor=100
239
else
186
- echo >&2 "$PROGRAM_NAME: configuration file '$myconfig' not found. Using defaults."
240
+ info "configuration file '$myconfig' not found. Using defaults."
241
fi
242
243
# we check for the timeout command, after we load our
@@ -204,12 +258,7 @@ update_every=$(( update_every + 1 - 1)) # makes sure it is a number
258
test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
259
260
# check the charts.d directory
207
-if [ ! -d "$chartsd" ]
208
- then
209
- echo >&2 "$PROGRAM_NAME: cannot find charts directory '$chartsd'"
210
- echo "DISABLE"
211
-fi
212
-
261
+[ ! -d "$chartsd" ] && fatal "cannot find charts directory '$chartsd'"
262
263
# -----------------------------------------------------------------------------
264
# library functions
@@ -221,6 +270,35 @@ fixid() {
270
tr "[A-Z]" "[a-z]"
271
}
272
273
+run() {
274
+ local ret pid="${BASHPID}" t
275
+
276
+ if [ "z${1}" = "z-t" -a "${2}" != "0" ]
277
+ then
278
+ t="${2}"
279
+ shift 2
280
+ timeout ${t} "${@}" 2>"${TMP_DIR}/run.${pid}"
281
+ ret=$?
282
+ else
283
+ "${@}" 2>"${TMP_DIR}/run.${pid}"
284
+ ret=$?
285
+ fi
286
+
287
+ if [ ${ret} -ne 0 ]
288
+ then
289
+ {
290
+ printf "$(logdate): ${PROGRAM_NAME}: ${status}: ${MODULE_NAME}: command '"
291
+ printf "%q " "${@}"
292
+ printf "' failed:\n --- BEGIN TRACE ---\n"
293
+ cat "${TMP_DIR}/run.${pid}"
294
+ printf " --- END TRACE ---\n"
295
+ } >&2
296
+ fi
297
+ rm "${TMP_DIR}/run.${pid}"
298
+
299
+ return ${ret}
300
+}
301
+
302
# convert any floating point number
303
# to integer, give a multiplier
304
# the result is stored in ${FLOAT2INT_RESULT}
@@ -230,8 +308,6 @@ float2int() {
308
local f m="$2" a b l v=($1)
309
f=${v[0]}
310
233
- # echo >&2 "value='${1}' f='${f}', m='${m}'"
234
-
311
# the length of the multiplier - 1
312
l=$(( ${#m} - 1 ))
313
@@ -277,7 +353,6 @@ float2int() {
353
354
# store the result
355
FLOAT2INT_RESULT=$(( (a * m) + b ))
280
- #echo >&2 "FLOAT2INT_RESULT='${FLOAT2INT_RESULT}'"
356
}
357
358
@@ -286,7 +361,7 @@ float2int() {
361
362
all_charts() {
363
cd "$chartsd"
289
- [ $? -ne 0 ] && echo >&2 "$PROGRAM_NAME: Cannot cd to $chartsd" && return 1
364
+ [ $? -ne 0 ] && error "cannot cd to $chartsd" && return 1
365
366
ls *.chart.sh | sed "s/\.chart\.sh$//g"
367
}
@@ -316,6 +391,8 @@ all_enabled_charts() {
391
392
for chart in $( all_charts )
393
do
394
+ MODULE_NAME="${chart}"
395
+
396
eval "enabled=\$$chart"
397
if [ -z "${enabled}" ]
398
then
@@ -327,35 +404,38 @@ all_enabled_charts() {
404
405
if [ ! "${enabled}" = "${required}" ]
406
then
330
- echo >&2 "$PROGRAM_NAME: '$chart' is NOT enabled. Add a line with $chart=$required in $myconfig to enable it (or remove the line that disables it)."
407
+ info "is disabled. Add a line with $chart=$required in $myconfig to enable it (or remove the line that disables it)."
408
else
332
- [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: '$chart' is enabled."
409
+ debug "is enabled for auto-detection."
410
local charts="$charts $chart"
411
fi
412
done
413
+ MODULE_NAME="main"
414
415
local charts2=
416
for chart in $charts
417
do
418
+ MODULE_NAME="${chart}"
419
+
420
# check the enabled charts
421
local check="$( cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_check()" )"
422
if [ -z "$check" ]
423
then
344
- echo >&2 "$PROGRAM_NAME: chart '$chart' does not seem to have a $chart$charts_check() function. Disabling it."
424
+ error "module '$chart' does not seem to have a $chart$charts_check() function. Disabling it."
425
continue
426
fi
427
428
local create="$( cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_create()" )"
429
if [ -z "$create" ]
430
then
351
- echo >&2 "$PROGRAM_NAME: chart '$chart' does not seem to have a $chart$charts_create() function. Disabling it."
431
+ error "module '$chart' does not seem to have a $chart$charts_create() function. Disabling it."
432
continue
433
fi
434
435
local update="$( cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_update()" )"
436
if [ -z "$update" ]
437
then
358
- echo >&2 "$PROGRAM_NAME: chart '$chart' does not seem to have a $chart$charts_update() function. Disabling it."
438
+ error "module '$chart' does not seem to have a $chart$charts_update() function. Disabling it."
439
continue
440
fi
441
@@ -364,7 +444,7 @@ all_enabled_charts() {
444
#then
445
# if [ ! -z "$( cat "$confd/$chart.conf" | sed "s/^ \+//g" | grep -v "^$" | grep -v "^#" | grep -v "^$chart$charts_undescore" )" ]
446
# then
367
- # echo >&2 "$PROGRAM_NAME: chart's $chart config $confd/$chart.conf should only have lines starting with $chart$charts_undescore . Disabling it."
447
+ # error "module's $chart config $confd/$chart.conf should only have lines starting with $chart$charts_undescore . Disabling it."
448
# continue
449
# fi
450
#fi
@@ -374,19 +454,19 @@ all_enabled_charts() {
454
# "$pluginsd/charts.d.dryrun-helper.sh" "$chart" "$chartsd/$chart.chart.sh" "$confd/$chart.conf" >/dev/null
455
# if [ $? -ne 0 ]
456
# then
377
- # echo >&2 "$PROGRAM_NAME: chart's $chart did not pass the dry run check. This means it uses global variables not starting with $chart. Disabling it."
457
+ # error "module's $chart did not pass the dry run check. This means it uses global variables not starting with $chart. Disabling it."
458
# continue
459
# fi
460
#fi
461
462
local charts2="$charts2 $chart"
463
done
464
+ MODULE_NAME="main"
465
466
echo $charts2
386
- [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: enabled charts: $charts2"
467
+ debug "enabled charts: $charts2"
468
}
469
389
-
470
# -----------------------------------------------------------------------------
471
# load the charts
472
@@ -394,19 +474,22 @@ suffix_update_every="_update_every"
474
active_charts=
475
for chart in $( all_enabled_charts )
476
do
397
- [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: loading chart: '$chartsd/$chart.chart.sh'"
477
+ MODULE_NAME="${chart}"
478
+
479
+ debug "loading module: '$chartsd/$chart.chart.sh'"
480
+
481
. "$chartsd/$chart.chart.sh"
482
483
if [ -f "$confd/$PROGRAM_NAME/$chart.conf" ]
484
then
402
- [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: loading chart options: '$confd/$PROGRAM_NAME/$chart.conf'"
485
+ debug "loading module configuration: '$confd/$PROGRAM_NAME/$chart.conf'"
486
. "$confd/$PROGRAM_NAME/$chart.conf"
487
elif [ -f "$confd/$chart.conf" ]
488
then
406
- [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: loading chart options: '$confd/$chart.conf'"
489
+ debug "loading module configuration: '$confd/$chart.conf'"
490
. "$confd/$chart.conf"
491
else
409
- echo >&2 "$PROGRAM_NAME: $chart: configuration file '$confd/$PROGRAM_NAME/$chart.conf' not found. Using defaults."
492
+ warning "configuration file '$confd/$PROGRAM_NAME/$chart.conf' not found. Using defaults."
493
fi
494
495
eval "dt=\$$chart$suffix_update_every"
@@ -419,13 +502,14 @@ do
502
$chart$charts_check
503
if [ $? -eq 0 ]
504
then
422
- [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: '$chart' activated"
505
+ debug "module '$chart' activated"
506
active_charts="$active_charts $chart"
507
else
425
- echo >&2 "$PROGRAM_NAME: chart '$chart' check() function reports failure."
508
+ error "module's '$chart' check() function reports failure."
509
fi
510
done
428
-[ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: activated charts: $active_charts"
511
+MODULE_NAME="main"
512
+debug "activated modules: $active_charts"
513
514
515
# -----------------------------------------------------------------------------
@@ -438,7 +522,7 @@ test $debug -eq 1 && debug_time=tellwork
522
# if we only need a specific chart, remove all the others
523
if [ ! -z "${chart_only}" ]
524
then
441
- [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: requested to run only for: '${chart_only}'"
525
+ debug "requested to run only for: '${chart_only}'"
526
check_charts=
527
for chart in $active_charts
528
do
@@ -450,41 +534,19 @@ then
534
done
535
active_charts="$check_charts"
536
fi
453
-[ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: activated charts: $active_charts"
537
+debug "activated charts: $active_charts"
538
539
# stop if we just need a pre-check
540
if [ $check -eq 1 ]
541
then
458
- echo >&2 "CHECK RESULT"
459
- echo >&2 "Will run the charts: $active_charts"
542
+ info "CHECK RESULT"
543
+ info "Will run the charts: $active_charts"
544
exit 0
545
fi
546
547
# -----------------------------------------------------------------------------
464
-# create temp dir
465
-
466
-TMP_DIR=
467
-chartsd_cleanup() {
468
- cd /tmp
469
- if [ ! -z "$TMP_DIR" -a -d "$TMP_DIR" ]
470
- then
471
- [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: cleaning up temporary directory $TMP_DIR ..."
472
- rm -rf "$TMP_DIR"
473
- fi
474
- exit 0
475
-}
476
-trap chartsd_cleanup EXIT
477
-trap chartsd_cleanup SIGHUP
478
-trap chartsd_cleanup INT
548
480
-if [ $UID = "0" ]
481
-then
482
- TMP_DIR="$( mktemp -d /var/run/netdata-${PROGRAM_NAME}-XXXXXXXXXX )"
483
-else
484
- TMP_DIR="$( mktemp -d /tmp/.netdata-${PROGRAM_NAME}-XXXXXXXXXX )"
485
-fi
486
-
487
-cd "$TMP_DIR" || exit 1
549
+cd "${TMP_DIR}" || exit 1
550
551
# -----------------------------------------------------------------------------
552
# create charts
@@ -492,28 +554,26 @@ cd "$TMP_DIR" || exit 1
554
run_charts=
555
for chart in $active_charts
556
do
495
- [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: Calling '$chart$charts_create()'..."
557
+ MODULE_NAME="${chart}"
558
+
559
+ debug "calling '$chart$charts_create()'..."
560
$chart$charts_create
561
if [ $? -eq 0 ]
562
then
563
run_charts="$run_charts $chart"
500
- [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: '$chart' has initialized."
564
+ debug "'$chart' initialized."
565
else
502
- echo >&2 "$PROGRAM_NAME: chart '$chart' function '$chart$charts_create()' reports failure."
566
+ error "module's '$chart' function '$chart$charts_create()' reports failure."
567
fi
568
done
505
-[ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: run_charts='$run_charts'"
569
+MODULE_NAME="main"
570
+debug "run_charts='$run_charts'"
571
572
573
# -----------------------------------------------------------------------------
574
# update dimensions
575
511
-if [ -z "$run_charts" ]
512
- then
513
- echo >&2 "$PROGRAM_NAME: No charts to collect data from."
514
- echo "DISABLE"
515
- exit 1
516
-fi
576
+[ -z "$run_charts" ] && fatal "No charts to collect data from."
577
578
declare -A charts_last_update=() charts_update_every=() charts_next_update=() charts_run_counter=() charts_serial_failures=()
579
global_update() {
@@ -552,12 +612,12 @@ global_update() {
612
613
for chart in "${now_charts[@]}"
614
do
555
- #echo >&2 " DEBUG: chart: $chart last: ${charts_last_update[$chart]}, next: ${charts_next_update[$chart]}, now: ${now_ms}"
615
+ MODULE_NAME="${chart}"
616
+
617
if [ ${now_ms} -ge ${charts_next_update[$chart]} ]
618
then
619
last_ms=${charts_last_update[$chart]}
620
dt=$(( (now_ms - last_ms) ))
560
- #echo >&2 " DEBUG: chart: $chart last: ${charts_last_update[$chart]}, next: ${charts_next_update[$chart]}, now: ${now_ms}, dt: ${dt}"
621
622
charts_last_update[$chart]=${now_ms}
623
@@ -576,7 +636,6 @@ global_update() {
636
fi
637
638
exec_start_ms=$now_ms
579
- #echo >&2 " EXEC: $chart$charts_update $dt"
639
$chart$charts_update $dt
640
ret=$?
641
@@ -596,9 +655,9 @@ global_update() {
655
656
if [ ${charts_serial_failures[$chart]} -gt 10 ]
657
then
599
- echo >&2 "$PROGRAM_NAME: chart '$chart' update() function reported failure ${charts_serial_failures[$chart]} times. Disabling it."
658
+ error "module's '$chart' update() function reported failure ${charts_serial_failures[$chart]} times. Disabling it."
659
else
601
- echo >&2 "$PROGRAM_NAME: chart '$chart' update() function reports failure. Will keep trying for a while."
660
+ error "module's '$chart' update() function reports failure. Will keep trying for a while."
661
next_charts+=($chart)
662
fi
663
fi
@@ -606,6 +665,7 @@ global_update() {
665
next_charts+=($chart)
666
fi
667
done
668
+ MODULE_NAME="${chart}"
669
670
# wait the time you are required to
671
next_ms=$((now_ms + (update_every * 1000 * 100) ))
@@ -625,18 +685,17 @@ global_update() {
685
millis="0${millis}"
686
fi
687
628
- [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: sleeping for ${seconds}.${millis} seconds."
688
+ debug "sleeping for ${seconds}.${millis} seconds."
689
${mysleep} ${seconds}.${millis}
690
else
631
- [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: sleeping for ${update_every} seconds."
691
+ debug "sleeping for ${update_every} seconds."
692
${mysleep} $update_every
693
fi
694
695
test ${now_ms} -ge ${exit_at} && exit 0
696
done
697
638
- echo >&2 "$PROGRAM_NAME: Nothing left to do. Disabling charts.d.plugin."
639
- echo "DISABLE"
698
+ fatal "nothing left to do, exiting..."
699
}
700
701
global_update