summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--collectors/charts.d.plugin/ap/ap.chart.sh91
-rw-r--r--collectors/charts.d.plugin/apache/apache.chart.sh79
-rw-r--r--collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh87
-rwxr-xr-xcollectors/charts.d.plugin/charts.d.dryrun-helper.sh58
-rwxr-xr-xcollectors/charts.d.plugin/charts.d.plugin.in924
-rw-r--r--collectors/charts.d.plugin/cpu_apps/cpu_apps.chart.sh20
-rw-r--r--collectors/charts.d.plugin/cpufreq/cpufreq.chart.sh18
-rw-r--r--collectors/charts.d.plugin/example/example.chart.sh15
-rw-r--r--collectors/charts.d.plugin/exim/exim.chart.sh26
-rw-r--r--collectors/charts.d.plugin/hddtemp/hddtemp.chart.sh24
-rw-r--r--collectors/charts.d.plugin/libreswan/libreswan.chart.sh32
-rw-r--r--collectors/charts.d.plugin/load_average/load_average.chart.sh14
-rw-r--r--collectors/charts.d.plugin/loopsleepms.sh.inc282
-rw-r--r--collectors/charts.d.plugin/mem_apps/mem_apps.chart.sh13
-rw-r--r--collectors/charts.d.plugin/mysql/mysql.chart.sh67
-rw-r--r--collectors/charts.d.plugin/nginx/nginx.chart.sh37
-rw-r--r--collectors/charts.d.plugin/nut/nut.chart.sh35
-rw-r--r--collectors/charts.d.plugin/opensips/opensips.chart.sh10
-rw-r--r--collectors/charts.d.plugin/phpfpm/phpfpm.chart.sh49
-rw-r--r--collectors/charts.d.plugin/postfix/postfix.chart.sh14
-rw-r--r--collectors/charts.d.plugin/sensors/sensors.chart.sh195
-rw-r--r--collectors/charts.d.plugin/squid/squid.chart.sh20
-rw-r--r--collectors/charts.d.plugin/tomcat/tomcat.chart.sh18
23 files changed, 973 insertions, 1155 deletions
diff --git a/collectors/charts.d.plugin/ap/ap.chart.sh b/collectors/charts.d.plugin/ap/ap.chart.sh
index ccc36120cd..a2d04c0a71 100644
--- a/collectors/charts.d.plugin/ap/ap.chart.sh
+++ b/collectors/charts.d.plugin/ap/ap.chart.sh
@@ -56,8 +56,7 @@ ap_check() {
ap_create() {
local ssid dev
- for dev in "${!ap_devs[@]}"
- do
+ for dev in "${!ap_devs[@]}"; do
ssid="${ap_devs[${dev}]}"
# create the chart with 3 dimensions
@@ -99,14 +98,13 @@ ap_update() {
# for each dimension
# remember: KEEP IT SIMPLE AND SHORT
- for dev in "${!ap_devs[@]}"
- do
- echo
- echo "DEVICE ${dev}"
+ for dev in "${!ap_devs[@]}"; do
+ echo
+ echo "DEVICE ${dev}"
iw "${dev}" station dump
- done | awk "
+ done | awk '
function zero_data() {
- dev = \"\";
+ dev = "";
c = 0;
rb = 0;
tb = 0;
@@ -121,32 +119,32 @@ ap_update() {
e = 0;
}
function print_device() {
- if(dev != \"\" && length(dev) > 0) {
- print \"BEGIN ap_clients.\" dev;
- print \"SET clients = \" c;
- print \"END\";
- print \"BEGIN ap_bandwidth.\" dev;
- print \"SET received = \" rb;
- print \"SET sent = \" tb;
- print \"END\";
- print \"BEGIN ap_packets.\" dev;
- print \"SET received = \" rp;
- print \"SET sent = \" tp;
- print \"END\";
- print \"BEGIN ap_issues.\" dev;
- print \"SET retries = \" tr;
- print \"SET failures = \" tf;
- print \"END\";
+ if(dev != "" && length(dev) > 0) {
+ print "BEGIN ap_clients." dev;
+ print "SET clients = " c;
+ print "END";
+ print "BEGIN ap_bandwidth." dev;
+ print "SET received = " rb;
+ print "SET sent = " tb;
+ print "END";
+ print "BEGIN ap_packets." dev;
+ print "SET received = " rp;
+ print "SET sent = " tp;
+ print "END";
+ print "BEGIN ap_issues." dev;
+ print "SET retries = " tr;
+ print "SET failures = " tf;
+ print "END";
if( c == 0 ) c = 1;
- print \"BEGIN ap_signal.\" dev;
- print \"SET signal = \" int(s / c);
- print \"END\";
- print \"BEGIN ap_bitrate.\" dev;
- print \"SET receive = \" int(rt / c);
- print \"SET transmit = \" int(tt / c);
- print \"SET expected = \" int(e / c);
- print \"END\";
+ print "BEGIN ap_signal." dev;
+ print "SET signal = " int(s / c);
+ print "END";
+ print "BEGIN ap_bitrate." dev;
+ print "SET receive = " int(rt / c);
+ print "SET transmit = " int(tt / c);
+ print "SET expected = " int(e / c);
+ print "END";
}
zero_data();
}
@@ -155,28 +153,27 @@ ap_update() {
}
/^DEVICE / {
print_device();
- dev = \$2;
+ dev = $2;
}
/^Station/ { c++; }
- /^[ \\t]+rx bytes:/ { rb += \$3; }
- /^[ \\t]+tx bytes:/ { tb += \$3; }
- /^[ \\t]+rx packets:/ { rp += \$3; }
- /^[ \\t]+tx packets:/ { tp += \$3; }
- /^[ \\t]+tx retries:/ { tr += \$3; }
- /^[ \\t]+tx failed:/ { tf += \$3; }
- /^[ \\t]+signal:/ { x = \$2; s += x * 1000; }
- /^[ \\t]+rx bitrate:/ { x = \$3; rt += x * 1000; }
- /^[ \\t]+tx bitrate:/ { x = \$3; tt += x * 1000; }
- /^[ \\t]+expected throughput:(.*)Mbps/ {
- x=\$3;
- sub(/Mbps/, \"\", x);
+ /^[ \t]+rx bytes:/ { rb += $3; }
+ /^[ \t]+tx bytes:/ { tb += $3; }
+ /^[ \t]+rx packets:/ { rp += $3; }
+ /^[ \t]+tx packets:/ { tp += $3; }
+ /^[ \t]+tx retries:/ { tr += $3; }
+ /^[ \t]+tx failed:/ { tf += $3; }
+ /^[ \t]+signal:/ { x = $2; s += x * 1000; }
+ /^[ \t]+rx bitrate:/ { x = $3; rt += x * 1000; }
+ /^[ \t]+tx bitrate:/ { x = $3; tt += x * 1000; }
+ /^[ \t]+expected throughput:(.*)Mbps/ {
+ x=$3;
+ sub(/Mbps/, "", x);
e += x * 1000;
}
END {
print_device();
}
- "
+ '
return 0
}
-
diff --git a/collectors/charts.d.plugin/apache/apache.chart.sh b/collectors/charts.d.plugin/apache/apache.chart.sh
index 95876432f3..7d09ee6767 100644
--- a/collectors/charts.d.plugin/apache/apache.chart.sh
+++ b/collectors/charts.d.plugin/apache/apache.chart.sh
@@ -52,21 +52,20 @@ apache_key_connsasynckeepalive=
apache_key_connsasyncclosing=
apache_detect() {
local i=0
- for x in "${@}"
- do
+ for x in "${@}"; do
case "${x}" in
- 'Total Accesses') apache_key_accesses=$((i + 1)) ;;
- 'Total kBytes') apache_key_kbytes=$((i + 1)) ;;
- 'ReqPerSec') apache_key_reqpersec=$((i + 1)) ;;
- 'BytesPerSec') apache_key_bytespersec=$((i + 1)) ;;
- 'BytesPerReq') apache_key_bytesperreq=$((i + 1)) ;;
- 'BusyWorkers') apache_key_busyworkers=$((i + 1)) ;;
- 'IdleWorkers') apache_key_idleworkers=$((i + 1));;
- 'ConnsTotal') apache_key_connstotal=$((i + 1)) ;;
- 'ConnsAsyncWriting') apache_key_connsasyncwriting=$((i + 1)) ;;
- 'ConnsAsyncKeepAlive') apache_key_connsasynckeepalive=$((i + 1)) ;;
- 'ConnsAsyncClosing') apache_key_connsasyncclosing=$((i + 1)) ;;
- 'Scoreboard') apache_key_scoreboard=$((i)) ;;
+ 'Total Accesses') apache_key_accesses=$((i + 1)) ;;
+ 'Total kBytes') apache_key_kbytes=$((i + 1)) ;;
+ 'ReqPerSec') apache_key_reqpersec=$((i + 1)) ;;
+ 'BytesPerSec') apache_key_bytespersec=$((i + 1)) ;;
+ 'BytesPerReq') apache_key_bytesperreq=$((i + 1)) ;;
+ 'BusyWorkers') apache_key_busyworkers=$((i + 1)) ;;
+ 'IdleWorkers') apache_key_idleworkers=$((i + 1)) ;;
+ 'ConnsTotal') apache_key_connstotal=$((i + 1)) ;;
+ 'ConnsAsyncWriting') apache_key_connsasyncwriting=$((i + 1)) ;;
+ 'ConnsAsyncKeepAlive') apache_key_connsasynckeepalive=$((i + 1)) ;;
+ 'ConnsAsyncClosing') apache_key_connsasyncclosing=$((i + 1)) ;;
+ 'Scoreboard') apache_key_scoreboard=$((i)) ;;
esac
i=$((i + 1))
@@ -74,20 +73,19 @@ apache_detect() {
# we will not check of the Conns*
# keys, since these are apache 2.4 specific
- [ -z "${apache_key_accesses}" ] && error "missing 'Total Accesses' from apache server: ${*}" && return 1
- [ -z "${apache_key_kbytes}" ] && error "missing 'Total kBytes' from apache server: ${*}" && return 1
- [ -z "${apache_key_reqpersec}" ] && error "missing 'ReqPerSec' from apache server: ${*}" && return 1
+ [ -z "${apache_key_accesses}" ] && error "missing 'Total Accesses' from apache server: ${*}" && return 1
+ [ -z "${apache_key_kbytes}" ] && error "missing 'Total kBytes' from apache server: ${*}" && return 1
+ [ -z "${apache_key_reqpersec}" ] && error "missing 'ReqPerSec' from apache server: ${*}" && return 1
[ -z "${apache_key_bytespersec}" ] && error "missing 'BytesPerSec' from apache server: ${*}" && return 1
[ -z "${apache_key_bytesperreq}" ] && error "missing 'BytesPerReq' from apache server: ${*}" && return 1
[ -z "${apache_key_busyworkers}" ] && error "missing 'BusyWorkers' from apache server: ${*}" && return 1
[ -z "${apache_key_idleworkers}" ] && error "missing 'IdleWorkers' from apache server: ${*}" && return 1
- [ -z "${apache_key_scoreboard}" ] && error "missing 'Scoreboard' from apache server: ${*}" && return 1
+ [ -z "${apache_key_scoreboard}" ] && error "missing 'Scoreboard' from apache server: ${*}" && return 1
- if [ ! -z "${apache_key_connstotal}" ] && \
- [ ! -z "${apache_key_connsasyncwriting}" ] && \
- [ ! -z "${apache_key_connsasynckeepalive}" ] && \
- [ ! -z "${apache_key_connsasyncclosing}" ]
- then
+ if [ ! -z "${apache_key_connstotal}" ] &&
+ [ ! -z "${apache_key_connsasyncwriting}" ] &&
+ [ ! -z "${apache_key_connsasynckeepalive}" ] &&
+ [ ! -z "${apache_key_connsasyncclosing}" ]; then
apache_has_conns=1
else
apache_has_conns=0
@@ -103,15 +101,13 @@ apache_get() {
ret=$?
IFS="${oIFS}"
- if [ $ret -ne 0 ] || [ "${#apache_response[@]}" -eq 0 ]
- then
+ if [ $ret -ne 0 ] || [ "${#apache_response[@]}" -eq 0 ]; then
return 1
fi
# the last line on the apache output is "Scoreboard"
# we use this label to detect that the output has a new word count
- if [ ${apache_keys_detected} -eq 0 ] || [ "${apache_response[${apache_key_scoreboard}]}" != "Scoreboard" ]
- then
+ if [ ${apache_keys_detected} -eq 0 ] || [ "${apache_response[${apache_key_scoreboard}]}" != "Scoreboard" ]; then
apache_detect "${apache_response[@]}" || return 1
apache_keys_detected=1
fi
@@ -131,20 +127,20 @@ apache_get() {
apache_busyworkers="${apache_response[${apache_key_busyworkers}]}"
apache_idleworkers="${apache_response[${apache_key_idleworkers}]}"
- if [ -z "${apache_accesses}" ] || \
- [ -z "${apache_kbytes}" ] || \
- [ -z "${apache_reqpersec}" ] || \
- [ -z "${apache_bytespersec}" ] || \
- [ -z "${apache_bytesperreq}" ] || \
- [ -z "${apache_busyworkers}" ]
- [ -z "${apache_idleworkers}" ]
+ if
+ [ -z "${apache_accesses}" ] ||
+ [ -z "${apache_kbytes}" ] ||
+ [ -z "${apache_reqpersec}" ] ||
+ [ -z "${apache_bytespersec}" ] ||
+ [ -z "${apache_bytesperreq}" ] ||
+ [ -z "${apache_busyworkers}" ]
+ [ -z "${apache_idleworkers}" ]
then
error "empty values got from apache server: ${apache_response[*]}"
return 1
fi
- if [ ${apache_has_conns} -eq 1 ]
- then
+ if [ ${apache_has_conns} -eq 1 ]; then
apache_connstotal="${apache_response[${apache_key_connstotal}]}"
apache_connsasyncwriting="${apache_response[${apache_key_connsasyncwriting}]}"
apache_connsasynckeepalive="${apache_response[${apache_key_connsasynckeepalive}]}"
@@ -159,8 +155,7 @@ apache_check() {
apache_get
# shellcheck disable=2181
- if [ $? -ne 0 ]
- then
+ if [ $? -ne 0 ]; then
# shellcheck disable=2154
error "cannot find stub_status on URL '${apache_url}'. Please set apache_url='http://apache.server:80/server-status?auto' in $confd/apache.conf"
return 1
@@ -191,8 +186,7 @@ CHART apache_local.net '' "apache Bandwidth" "kilobits/s" bandwidth apache.net a
DIMENSION sent '' incremental 8 1
EOF
- if [ ${apache_has_conns} -eq 1 ]
- then
+ if [ ${apache_has_conns} -eq 1 ]; then
cat <<EOF2
CHART apache_local.connections '' "apache Connections" "connections" connections apache.connections line $((apache_priority + 2)) $apache_update_every
DIMENSION connections '' absolute 1 1
@@ -240,9 +234,8 @@ SET busy = $((apache_busyworkers))
END
VALUESEOF
- if [ ${apache_has_conns} -eq 1 ]
- then
- cat <<VALUESEOF2
+ if [ ${apache_has_conns} -eq 1 ]; then
+ cat <<VALUESEOF2
BEGIN apache_local.connections $1
SET connections = $((apache_connstotal))
END
diff --git a/collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh b/collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh
index e26ef566aa..744d396cd8 100644
--- a/collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh
+++ b/collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh
@@ -11,7 +11,7 @@ apcupsd_ip=
apcupsd_port=
declare -A apcupsd_sources=(
- ["local"]="127.0.0.1:3551"
+ ["local"]="127.0.0.1:3551"
)
# how frequently to collect UPS data
@@ -35,46 +35,40 @@ apcupsd_check() {
require_cmd apcaccess || return 1
# backwards compatibility
- if [ "${apcupsd_ip}:${apcupsd_port}" != ":" ]
- then
- apcupsd_sources["local"]="${apcupsd_ip}:${apcupsd_port}"
+ if [ "${apcupsd_ip}:${apcupsd_port}" != ":" ]; then
+ apcupsd_sources["local"]="${apcupsd_ip}:${apcupsd_port}"
fi
- local host working=0 failed=0
- for host in "${!apcupsd_sources[@]}"
- do
- run apcupsd_get "${apcupsd_sources[${host}]}" >/dev/null
- # shellcheck disable=2181
- if [ $? -ne 0 ]
- then
- error "cannot get information for apcupsd server ${host} on ${apcupsd_sources[${host}]}."
- failed=$((failed + 1))
- elif [ "$(apcupsd_get "${apcupsd_sources[${host}]}" | awk '/^STATUS.*/{ print $3 }')" != "ONLINE" ]
- then
- error "APC UPS ${host} on ${apcupsd_sources[${host}]} is not online."
- failed=$((failed + 1))
- else
- working=$((working + 1))
- fi
- done
-
- if [ ${working} -eq 0 ]
- then
- error "No APC UPSes found available."
- return 1
- fi
+ local host working=0 failed=0
+ for host in "${!apcupsd_sources[@]}"; do
+ run apcupsd_get "${apcupsd_sources[${host}]}" >/dev/null
+ # shellcheck disable=2181
+ if [ $? -ne 0 ]; then
+ error "cannot get information for apcupsd server ${host} on ${apcupsd_sources[${host}]}."
+ failed=$((failed + 1))
+ elif [ "$(apcupsd_get "${apcupsd_sources[${host}]}" | awk '/^STATUS.*/{ print $3 }')" != "ONLINE" ]; then
+ error "APC UPS ${host} on ${apcupsd_sources[${host}]} is not online."
+ failed=$((failed + 1))
+ else
+ working=$((working + 1))
+ fi
+ done
+
+ if [ ${working} -eq 0 ]; then
+ error "No APC UPSes found available."
+ return 1
+ fi
return 0
}
apcupsd_create() {
- local host src
- for host in "${!apcupsd_sources[@]}"
- do
- src=${apcupsd_sources[${host}]}
+ local host src
+ for host in "${!apcupsd_sources[@]}"; do
+ src=${apcupsd_sources[${host}]}
- # create the charts
- cat <<EOF
+ # create the charts
+ cat <<EOF
CHART apcupsd_${host}.charge '' "UPS Charge for ${host} on ${src}" "percentage" ups apcupsd.charge area $((apcupsd_priority + 1)) $apcupsd_update_every
DIMENSION battery_charge charge absolute 1 100
@@ -104,11 +98,10 @@ CHART apcupsd_${host}.time '' "UPS Time Remaining for ${host} on ${src}" "Minute
DIMENSION time time absolute 1 100
EOF
- done
+ done
return 0
}
-
apcupsd_update() {
# the first argument to this function is the microseconds since last update
# pass this parameter to the BEGIN statement (see bellow).
@@ -117,10 +110,9 @@ apcupsd_update() {
# for each dimension
# remember: KEEP IT SIMPLE AND SHORT
- local host working=0 failed=0
- for host in "${!apcupsd_sources[@]}"
- do
- apcupsd_get "${apcupsd_sources[${host}]}" | awk "
+ local host working=0 failed=0
+ for host in "${!apcupsd_sources[@]}"; do
+ apcupsd_get "${apcupsd_sources[${host}]}" | awk "
BEGIN {
battery_charge = 0;
@@ -185,15 +177,14 @@ END {
print \"SET time = \" time;
print \"END\"
}"
- # shellcheck disable=SC2181
- if [ $? -ne 0 ]
- then
- failed=$((failed + 1))
- error "failed to get values for APC UPS ${host} on ${apcupsd_sources[${host}]}" && return 1
- else
- working=$((working + 1))
- fi
- done
+ # shellcheck disable=SC2181
+ if [ $? -ne 0 ]; then
+ failed=$((failed + 1))
+ error "failed to get values for APC UPS ${host} on ${apcupsd_sources[${host}]}" && return 1
+ else
+ working=$((working + 1))
+ fi
+ done
[ $working -eq 0 ] && error "failed to get values from all APC UPSes" && return 1
diff --git a/collectors/charts.d.plugin/charts.d.dryrun-helper.sh b/collectors/charts.d.plugin/charts.d.dryrun-helper.sh
index 67496c1bdf..91af2c5426 100755
--- a/collectors/charts.d.plugin/charts.d.dryrun-helper.sh
+++ b/collectors/charts.d.plugin/charts.d.dryrun-helper.sh
@@ -17,7 +17,7 @@ tmp1="$(mktemp)"
tmp2="$(mktemp)"
myset() {
- set | grep -v "^_=" | grep -v "^PIPESTATUS=" | grep -v "^BASH_LINENO="
+ set | grep -v "^_=" | grep -v "^PIPESTATUS=" | grep -v "^BASH_LINENO="
}
# save 2 'set'
@@ -26,52 +26,46 @@ myset >"$tmp2"
# make sure they don't differ
diff "$tmp1" "$tmp2" >/dev/null 2>&1
-if [ $? -ne 0 ]
-then
- # they differ, we cannot do the check
- echo >&2 "$me: cannot check with diff."
- can_diff=0
+if [ $? -ne 0 ]; then
+ # they differ, we cannot do the check
+ echo >&2 "$me: cannot check with diff."
+ can_diff=0
fi
# do it again, now including the script
myset >"$tmp1"
# include the plugin and its config
-if [ -f "$conf" ]
-then
- # shellcheck source=/dev/null
- . "$conf"
- if [ $? -ne 0 ]
- then
- echo >&2 "$me: cannot load config file $conf"
- rm "$tmp1" "$tmp2"
- exit 1
- fi
+if [ -f "$conf" ]; then
+ # shellcheck source=/dev/null
+ . "$conf"
+ if [ $? -ne 0 ]; then
+ echo >&2 "$me: cannot load config file $conf"
+ rm "$tmp1" "$tmp2"
+ exit 1
+ fi
fi
# shellcheck source=/dev/null
. "$chart"
-if [ $? -ne 0 ]
-then
- echo >&2 "$me: cannot load chart file $chart"
- rm "$tmp1" "$tmp2"
- exit 1
+if [ $? -ne 0 ]; then
+ echo >&2 "$me: cannot load chart file $chart"
+ rm "$tmp1" "$tmp2"
+ exit 1
fi
# remove all variables starting with the plugin name
myset | grep -v "^$name" >"$tmp2"
-if [ $can_diff -eq 1 ]
-then
- # check if they are different
- # make sure they don't differ
- diff "$tmp1" "$tmp2" >&2
- if [ $? -ne 0 ]
- then
- # they differ
- rm "$tmp1" "$tmp2"
- exit 1
- fi
+if [ $can_diff -eq 1 ]; then
+ # check if they are different
+ # make sure they don't differ
+ diff "$tmp1" "$tmp2" >&2
+ if [ $? -ne 0 ]; then
+ # they differ
+ rm "$tmp1" "$tmp2"
+ exit 1
+ fi
fi
rm "$tmp1" "$tmp2"
diff --git a/collectors/charts.d.plugin/charts.d.plugin.in b/collectors/charts.d.plugin/charts.d.plugin.in
index 3477894d89..05a63875b3 100755
--- a/collectors/charts.d.plugin/charts.d.plugin.in
+++ b/collectors/charts.d.plugin/charts.d.plugin.in
@@ -17,7 +17,7 @@ export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
PROGRAM_FILE="$0"
PROGRAM_NAME="$(basename $0)"
-PROGRAM_NAME="${PROGRAM_NAME/.plugin}"
+PROGRAM_NAME="${PROGRAM_NAME/.plugin/}"
MODULE_NAME="main"
# -----------------------------------------------------------------------------
@@ -26,72 +26,69 @@ MODULE_NAME="main"
debug=0
TMP_DIR=
chartsd_cleanup() {
- trap '' EXIT QUIT HUP INT TERM
-
- if [ ! -z "$TMP_DIR" -a -d "$TMP_DIR" ]
- then
- [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: cleaning up temporary directory $TMP_DIR ..."
- rm -rf "$TMP_DIR"
- fi
- exit 0
+ trap '' EXIT QUIT HUP INT TERM
+
+ if [ ! -z "$TMP_DIR" -a -d "$TMP_DIR" ]; then
+ [ $debug -eq 1 ] && echo >&2 "$PROGRAM_NAME: cleaning up temporary directory $TMP_DIR ..."
+ rm -rf "$TMP_DIR"
+ fi
+ exit 0
}
trap chartsd_cleanup EXIT QUIT HUP INT TERM
-if [ $UID = "0" ]
-then
- TMP_DIR="$( mktemp -d /var/run/netdata-${PROGRAM_NAME}-XXXXXXXXXX )"
+if [ $UID = "0" ]; then
+ TMP_DIR="$(mktemp -d /var/run/netdata-${PROGRAM_NAME}-XXXXXXXXXX)"
else
- TMP_DIR="$( mktemp -d /tmp/.netdata-${PROGRAM_NAME}-XXXXXXXXXX )"
+ TMP_DIR="$(mktemp -d /tmp/.netdata-${PROGRAM_NAME}-XXXXXXXXXX)"
fi
logdate() {
- date "+%Y-%m-%d %H:%M:%S"
+ date "+%Y-%m-%d %H:%M:%S"
}
log() {
- local status="${1}"
- shift
+ local status="${1}"
+ shift
- echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${MODULE_NAME}: ${*}"
+ echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${MODULE_NAME}: ${*}"
}
warning() {
- log WARNING "${@}"
+ log WARNING "${@}"
}
error() {
- log ERROR "${@}"
+ log ERROR "${@}"
}
info() {
- log INFO "${@}"
+ log INFO "${@}"
}
fatal() {
- log FATAL "${@}"
- echo "DISABLE"
- exit 1
+ log FATAL "${@}"
+ echo "DISABLE"
+ exit 1
}
debug() {
- [ $debug -eq 1 ] && log DEBUG "${@}"
+ [ $debug -eq 1 ] && log DEBUG "${@}"
}
# -----------------------------------------------------------------------------
# check a few commands
require_cmd() {
- local x=$(which "${1}" 2>/dev/null || command -v "${1}" 2>/dev/null)
- if [ -z "${x}" -o ! -x "${x}" ]
- then
- warning "command '${1}' is not found in ${PATH}."
- eval "${1^^}_CMD=\"\""
- return 1
- fi
-
- eval "${1^^}_CMD=\"${x}\""
- return 0
+ local x=$(which "${1}" 2>/dev/null || command -v "${1}" 2>/dev/null)
+ if [ -z "${x}" -o ! -x "${x}" ]; then
+ warning "command '${1}' is not found in ${PATH}."
+ eval "${1^^}_CMD=\"\""
+ return 1
+ fi
+
+ eval "${1^^}_CMD=\"${x}\""
+ return 0
}
require_cmd date || exit 1
@@ -108,7 +105,7 @@ require_cmd curl || exit 1
# -----------------------------------------------------------------------------
-[ $(( ${BASH_VERSINFO[0]} )) -lt 4 ] && fatal "BASH version 4 or later is required, but found version: ${BASH_VERSION}. Please upgrade."
+[ $((BASH_VERSINFO[0])) -lt 4 ] && fatal "BASH version 4 or later is required, but found version: ${BASH_VERSION}. Please upgrade."
info "started from '$PROGRAM_FILE' with options: $*"
@@ -117,7 +114,7 @@ info "started from '$PROGRAM_FILE' with options: $*"
# netdata exposes a few environment variables for us
[ -z "${NETDATA_PLUGINS_DIR}" ] && NETDATA_PLUGINS_DIR="$(dirname "${0}")"
-[ -z "${NETDATA_USER_CONFIG_DIR}" ] && NETDATA_USER_CONFIG_DIR="@configdir_POST@"
+[ -z "${NETDATA_USER_CONFIG_DIR}" ] && NETDATA_USER_CONFIG_DIR="@configdir_POST@"
[ -z "${NETDATA_STOCK_CONFIG_DIR}" ] && NETDATA_STOCK_CONFIG_DIR="@libconfigdir_POST@"
pluginsd="${NETDATA_PLUGINS_DIR}"
@@ -127,7 +124,7 @@ olduserconfd="${NETDATA_USER_CONFIG_DIR}"
chartsd="$pluginsd/../charts.d"
minimum_update_frequency="${NETDATA_UPDATE_EVERY-1}"
-update_every=${minimum_update_frequency} # this will be overwritten by the command line
+update_every=${minimum_update_frequency} # this will be overwritten by the command line
# work around for non BASH shells
charts_create="_create"
@@ -169,53 +166,46 @@ enable_all_charts="yes"
check=0
chart_only=
-while [ ! -z "$1" ]
-do
- if [ "$1" = "check" ]
- then
- check=1
- shift
- continue
- fi
-
- if [ "$1" = "debug" -o "$1" = "all" ]
- then
- debug=1
- shift
- continue
- fi
-
- if [ -f "$chartsd/$1.chart.sh" ]
- then
- debug=1
- chart_only="$( echo $1.chart.sh | sed "s/\.chart\.sh$//g" )"
- shift
- continue
- fi
-
- if [ -f "$chartsd/$1" ]
- then
- debug=1
- chart_only="$( echo $1 | sed "s/\.chart\.sh$//g" )"
- shift
- continue
- fi
-
- # number check
- n="$1"
- x=$(( n ))
- if [ "$x" = "$n" ]
- then
- shift
- update_every=$x
- [ $update_every -lt $minimum_update_frequency ] && update_every=$minimum_update_frequency
- continue
- fi
-
- fatal "Cannot understand parameter $1. Aborting."
+while [ ! -z "$1" ]; do
+ if [ "$1" = "check" ]; then
+ check=1
+ shift
+ continue
+ fi
+
+ if [ "$1" = "debug" -o "$1" = "all" ]; then
+ debug=1
+ shift
+ continue
+ fi
+
+ if [ -f "$chartsd/$1.chart.sh" ]; then
+ debug=1
+ chart_only="$(echo $1.chart.sh | sed "s/\.chart\.sh$//g")"
+ shift
+ continue
+ fi
+
+ if [ -f "$chartsd/$1" ]; then
+ debug=1
+ chart_only="$(echo $1 | sed "s/\.chart\.sh$//g")"
+ shift
+ continue
+ fi
+
+ # number check
+ n="$1"
+ x=$((n))
+ if [ "$x" = "$n" ]; then
+ shift
+ update_every=$x
+ [ $update_every -lt $minimum_update_frequency ] && update_every=$minimum_update_frequency
+ continue
+ fi
+
+ fatal "Cannot understand parameter $1. Aborting."
done
-
# -----------------------------------------------------------------------------
# loop control
@@ -223,7 +213,7 @@ done
LOOPSLEEPMS_HIGHRES=0
now_ms=
current_time_ms_default() {
- now_ms="$(date +'%s')000"
+ now_ms="$(date +'%s')000"
}
current_time_ms="current_time_ms_default"
current_time_ms_accuracy=1
@@ -238,20 +228,17 @@ source "$pluginsd/loopsleepms.sh.inc"
# -----------------------------------------------------------------------------
# load my configuration
-for myconfig in "${NETDATA_STOCK_CONFIG_DIR}/${PROGRAM_NAME}.conf" "${NETDATA_USER_CONFIG_DIR}/${PROGRAM_NAME}.conf"
-do
- if [ -f "$myconfig" ]
- then
- source "$myconfig"
- if [ $? -ne 0 ]
- then
- error "Config file '$myconfig' loaded with errors."
- else
- info "Configuration file '$myconfig' loaded."
- fi
- else
- warning "Configuration file '$myconfig' not found."
- fi
+for myconfig in "${NETDATA_STOCK_CONFIG_DIR}/${PROGRAM_NAME}.conf" "${NETDATA_USER_CONFIG_DIR}/${PROGRAM_NAME}.conf"; do
+ if [ -f "$myconfig" ]; then
+ source "$myconfig"
+ if [ $? -ne 0 ]; then
+ error "Config file '$myconfig' loaded with errors."
+ else
+ info "Configuration file '$myconfig' loaded."
+ fi
+ else
+ warning "Configuration file '$myconfig' not found."
+ fi
done
# make sure time_divisor is right
@@ -259,22 +246,20 @@ time_divisor=$((time_divisor))
[ $time_divisor -lt 10 ] && time_divisor=10
[ $time_divisor -gt 100 ] && time_divisor=100
-
# we check for the timeout command, after we load our
# configuration, so that the user may overwrite the
# timeout command we use, providing a function that
# can emulate the timeout command we need:
# > timeout SECONDS command ...
-if [ $check_for_timeout -eq 1 ]
- then
- require_cmd timeout || exit 1
+if [ $check_for_timeout -eq 1 ]; then
+ require_cmd timeout || exit 1
fi
# -----------------------------------------------------------------------------
# internal checks
# netdata passes the requested update frequency as the first argument
-update_every=$(( update_every + 1 - 1)) # makes sure it is a number
+update_every=$((update_every + 1 - 1)) # makes sure it is a number
test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
# check the charts.d directory
@@ -284,39 +269,37 @@ test $update_every -eq 0 && update_every=1 # if it is zero, make it 1
# library functions
fixid() {
- echo "$*" |\
- tr -c "[A-Z][a-z][0-9]" "_" |\
- sed -e "s|^_\+||g" -e "s|_\+$||g" -e "s|_\+|_|g" |\
- tr "[A-Z]" "[a-z]"
+ echo "$*" |
+ tr -c "[A-Z][a-z][0-9]" "_" |
+ sed -e "s|^_\+||g" -e "s|_\+$||g" -e "s|_\+|_|g" |
+ tr "[A-Z]" "[a-z]"
}
run() {
- local ret pid="${BASHPID}" t
-
- if [ "z${1}" = "z-t" -a "${2}" != "0" ]
- then
- t="${2}"
- shift 2
- timeout ${t} "${@}" 2>"${TMP_DIR}/run.${pid}"
- ret=$?
- else
- "${@}" 2>"${TMP_DIR}/run.${pid}"
- ret=$?
- fi
-
- if [ ${ret} -ne 0 ]
- then
- {
- printf "$(logdate): ${PROGRAM_NAME}: ${status}: ${MODULE_NAME}: command '"
- printf "%q " "${@}"
- printf "' failed with code ${ret}:\n --- BEGIN TRACE ---\n"
- cat "${TMP_DIR}/run.${pid}"
- printf " --- END TRACE ---\n"
- } >&2
- fi
- rm "${TMP_DIR}/run.${pid}"
-
- return ${ret}
+ local ret pid="${BASHPID}" t
+
+ if [ "z${1}" = "z-t" -a "${2}" != "0" ]; then
+ t="${2}"
+ shift 2
+ timeout ${t} "${@}" 2>"${TMP_DIR}/run.${pid}"
+ ret=$?
+ else
+ "${@}" 2>"${TMP_DIR}/run.${pid}"
+ ret=$?
+ fi
+
+ if [ ${ret} -ne 0 ]; then
+ {
+ printf