uniform logging from all scripts
Costa Tsaousis (ktsaou) committed
Oct 20, 2016 at 22:39 UTC
0a26e46c36e7fc1c343f9512ae6ade05a78349a1
24 files changed
+358
-64
charts.d/ap.chart.sh
+6
@@ -1,5 +1,11 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+
9
# _update_every is a special variable - it holds the number of seconds
10
# between the calls of the _update() function
11
ap_update_every=
charts.d/apache.chart.sh
+6
@@ -1,5 +1,11 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+
9
# the URL to download apache status info
10
apache_url="http://127.0.0.1:80/server-status?auto"
11
apache_curl_opts=
charts.d/apcupsd.chart.sh
+6
@@ -1,5 +1,11 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+
9
apcupsd_ip=127.0.0.1
10
apcupsd_port=3551
11
charts.d/cpu_apps.chart.sh
+5
@@ -1,5 +1,10 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
# THIS PLUGIN IS OBSOLETE
9
# USE apps.plugin INSTEAD
10
charts.d/cpufreq.chart.sh
+6
@@ -1,5 +1,11 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+
9
# if this chart is called X.chart.sh, then all functions and global variables
10
# must start with X_
11
charts.d/example.chart.sh
+6
@@ -1,5 +1,11 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+
9
# if this chart is called X.chart.sh, then all functions and global variables
10
# must start with X_
11
charts.d/exim.chart.sh
+7
@@ -1,5 +1,12 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+# Contributed by @jsveiga with PR #480
9
+
10
# the exim command to run
11
exim_command=
12
charts.d/hddtemp.chart.sh
+7
@@ -1,5 +1,12 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+# contributed by @paulfantom with PR #511
9
+
10
# if this chart is called X.chart.sh, then all functions and global variables
11
# must start with X_
12
hddtemp_host="localhost"
charts.d/load_average.chart.sh
+6
@@ -1,5 +1,11 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+
9
load_average_update_every=5
10
load_priority=100
11
charts.d/mem_apps.chart.sh
+6
@@ -1,5 +1,11 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+
9
mem_apps_apps=
10
11
# these are required for computing memory in bytes and cpu in seconds
charts.d/mysql.chart.sh
+6
@@ -1,5 +1,11 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+
9
# http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html
10
#
11
# https://dev.mysql.com/doc/refman/5.1/en/show-status.html
charts.d/nginx.chart.sh
+6
@@ -1,5 +1,11 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+
9
# if this chart is called X.chart.sh, then all functions and global variables
10
# must start with X_
11
charts.d/nut.chart.sh
+6
@@ -1,5 +1,11 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+
9
# a space separated list of UPS names
10
# if empty, the list returned by 'upsc -l' will be used
11
nut_ups=
charts.d/opensips.chart.sh
+6
@@ -1,5 +1,11 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+
9
opensips_opts="fifo get_statistics all"
10
opensips_cmd=
11
opensips_update_every=5
charts.d/phpfpm.chart.sh
+8
-4
@@ -1,9 +1,13 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
-# if this chart is called X.chart.sh, then all functions and global variables
4
-# must start with X_
5
-
6
-# first, you need open php-fpm status in php-fpm.conf
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+# Contributed by @safeie with PR #276
9
+
10
+# first, you need open php-fpm status in php-fpm.conf
11
# second, you need add status location in nginx.conf
12
# you can see, https://easyengine.io/tutorials/php/fpm-status-page/
13
charts.d/postfix.chart.sh
+6
@@ -1,5 +1,11 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+
9
# the postqueue command
10
# if empty, it will use the one found in the system path
11
postfix_postqueue=
charts.d/sensors.chart.sh
+6
@@ -1,5 +1,11 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+
9
# sensors docs
10
# https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
11
charts.d/squid.chart.sh
+6
@@ -1,5 +1,11 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+
9
squid_host=
10
squid_port=
11
squid_url=
charts.d/tomcat.chart.sh
+7
@@ -1,5 +1,12 @@
1
# no need for shebang - this file is loaded from charts.d.plugin
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+# Contributed by @jgeromero with PR #277
9
+
10
# Description: Tomcat netdata charts.d plugin
11
# Author: Jorge Romero
12
plugins.d/alarm-notify.sh
+58
-17
@@ -5,7 +5,7 @@
5
# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
# GPL v3+
7
#
8
-# Script the send alarm notifications for netdata
8
+# Script to send alarm notifications for netdata
9
#
10
# Features:
11
# - multiple notification methods
@@ -20,14 +20,56 @@
20
# - telegram.org notifications
21
#
22
23
-me="${0}"
23
+export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
24
+export LC_ALL=C
25
+
26
+# -----------------------------------------------------------------------------
27
+
28
+PROGRAM_NAME="$(basename "${0}")"
29
+
30
+logdate() {
31
+ date "+%Y-%m-%d %H:%M:%S"
32
+}
33
+
34
+log() {
35
+ local status="${1}"
36
+ shift
37
+
38
+ echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
39
+
40
+}
41
+
42
+warning() {
43
+ log WARNING "${@}"
44
+}
45
+
46
+error() {
47
+ log ERROR "${@}"
48
+}
49
+
50
+info() {
51
+ log INFO "${@}"
52
+}
53
+
54
+fatal() {
55
+ log FATAL "${@}"
56
+ exit 1
57
+}
58
+
59
+debug=0
60
+debug() {
61
+ [ $debug -eq 1 ] && log DEBUG "${@}"
62
+}
63
+
64
+# -----------------------------------------------------------------------------
65
66
# check for BASH v4+ (required for associative arrays)
67
[ $(( ${BASH_VERSINFO[0]} )) -lt 4 ] && \
27
- echo >&2 "${me}: BASH version 4 or later is required (this is ${BASH_VERSION})." && \
28
- exit 1
68
+ fatal "BASH version 4 or later is required (this is ${BASH_VERSION})."
69
70
+# -----------------------------------------------------------------------------
71
# defaults to allow running this script by hand
72
+
73
NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
74
NETDATA_CACHE_DIR="${NETDATA_CACHE_DIR-/var/cache/netdata}"
75
[ -z "${NETDATA_REGISTRY_URL}" ] && NETDATA_REGISTRY_URL="https://registry.my-netdata.io"
@@ -62,14 +104,14 @@ info="${18}" # a short description of the alarm
104
# don't do anything if this is not WARNING, CRITICAL or CLEAR
105
if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a "${status}" != "CLEAR" ]
106
then
65
- echo >&2 "${me}: not sending notification for ${status} on '${chart}.${name}'"
107
+ info "not sending notification for ${status} on '${chart}.${name}'"
108
exit 1
109
fi
110
111
# don't do anything if this is CLEAR, but it was not WARNING or CRITICAL
112
if [ "${old_status}" != "WARNING" -a "${old_status}" != "CRITICAL" -a "${status}" = "CLEAR" ]
113
then
72
- echo >&2 "${me}: not sending notification for ${status} on '${chart}.${name}' (last status was ${old_status})"
114
+ info "not sending notification for ${status} on '${chart}.${name}' (last status was ${old_status})"
115
exit 1
116
fi
117
@@ -262,8 +304,7 @@ fi
304
# check that we have at least a method enabled
305
if [ "${SEND_EMAIL}" != "YES" -a "${SEND_PUSHOVER}" != "YES" -a "${SEND_TELEGRAM}" != "YES" -a "${SEND_SLACK}" != "YES" ]
306
then
265
- echo >&2 "All notification methods are disabled. Not sending a notification."
266
- exit 1
307
+ fatal "All notification methods are disabled. Not sending a notification."
308
fi
309
310
# -----------------------------------------------------------------------------
@@ -372,10 +413,10 @@ send_email() {
413
414
if [ $ret -eq 0 ]
415
then
375
- echo >&2 "${me}: Sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'"
416
+ info "sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'"
417
return 0
418
else
378
- echo >&2 "${me}: Failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret}."
419
+ error "failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret}."
420
return 1
421
fi
422
fi
@@ -417,10 +458,10 @@ send_pushover() {
458
459
if [ "${httpcode}" == "200" ]
460
then
420
- echo >&2 "${me}: Sent pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
461
+ info "sent pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
462
sent=$((sent + 1))
463
else
423
- echo >&2 "${me}: Failed to send pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
464
+ error "failed to send pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
465
fi
466
done
467
@@ -452,13 +493,13 @@ send_telegram() {
493
494
if [ "${httpcode}" == "200" ]
495
then
455
- echo >&2 "${me}: Sent telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}'"
496
+ info "sent telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}'"
497
sent=$((sent + 1))
498
elif [ "${httpcode}" == "401" ]
499
then
459
- echo >&2 "${me}: Failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}': Wrong bot token."
500
+ error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}': Wrong bot token."
501
else
461
- echo >&2 "${me}: Failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}' with HTTP error code ${httpcode}."
502
+ error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}' with HTTP error code ${httpcode}."
503
fi
504
done
505
@@ -520,10 +561,10 @@ EOF
561
httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null -X POST --data-urlencode "payload=${payload}" "${webhook}")
562
if [ "${httpcode}" == "200" ]
563
then
523
- echo >&2 "${me}: Sent slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
564
+ info "sent slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
565
sent=$((sent + 1))
566
else
526
- echo >&2 "${me}: Failed to send slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
567
+ error "failed to send slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
568
fi
569
done
570
plugins.d/cgroup-name.sh
+59
-10
@@ -1,17 +1,66 @@
1
#!/usr/bin/env bash
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+# Script to find a better name for cgroups
9
+#
10
+
11
export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
12
export LC_ALL=C
13
14
+# -----------------------------------------------------------------------------
15
+
16
+PROGRAM_NAME="$(basename "${0}")"
17
+
18
+logdate() {
19
+ date "+%Y-%m-%d %H:%M:%S"
20
+}
21
+
22
+log() {
23
+ local status="${1}"
24
+ shift
25
+
26
+ echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
27
+
28
+}
29
+
30
+warning() {
31
+ log WARNING "${@}"
32
+}
33
+
34
+error() {
35
+ log ERROR "${@}"
36
+}
37
+
38
+info() {
39
+ log INFO "${@}"
40
+}
41
+
42
+fatal() {
43
+ log FATAL "${@}"
44
+ exit 1
45
+}
46
+
47
+debug=0
48
+debug() {
49
+ [ $debug -eq 1 ] && log DEBUG "${@}"
50
+}
51
+
52
+# -----------------------------------------------------------------------------
53
+
54
NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
55
CONFIG="${NETDATA_CONFIG_DIR}/cgroups-names.conf"
56
CGROUP="${1}"
57
NAME=
58
59
+# -----------------------------------------------------------------------------
60
+
61
if [ -z "${CGROUP}" ]
62
then
13
- echo >&2 "${0}: called without a cgroup name. Nothing to do."
14
- exit 1
63
+ fatal "called without a cgroup name. Nothing to do."
64
fi
65
66
if [ -f "${CONFIG}" ]
@@ -19,15 +68,15 @@ if [ -f "${CONFIG}" ]
68
NAME="$(grep "^${CGROUP} " "${CONFIG}" | sed "s/[[:space:]]\+/ /g" | cut -d ' ' -f 2)"
69
if [ -z "${NAME}" ]
70
then
22
- echo >&2 "${0}: cannot find cgroup '${CGROUP}' in '${CONFIG}'."
71
+ info "cannot find cgroup '${CGROUP}' in '${CONFIG}'."
72
fi
73
#else
25
-# echo >&2 "${0}: configuration file '${CONFIG}' is not available."
74
+# info "configuration file '${CONFIG}' is not available."
75
fi
76
77
function get_name_classic {
78
local DOCKERID="$1"
30
- echo >&2 "Running command: docker ps --filter=id=\"${DOCKERID}\" --format=\"{{.Names}}\""
79
+ info "Running command: docker ps --filter=id=\"${DOCKERID}\" --format=\"{{.Names}}\""
80
NAME="$( docker ps --filter=id="${DOCKERID}" --format="{{.Names}}" )"
81
return 0
82
}
@@ -36,10 +85,10 @@ function get_name_api {
85
local DOCKERID="$1"
86
if [ ! -S "/var/run/docker.sock" ]
87
then
39
- echo >&2 "Can't find /var/run/docker.sock"
88
+ warning "Can't find /var/run/docker.sock"
89
return 1
90
fi
42
- echo >&2 "Running API command: /containers/${DOCKERID}/json"
91
+ info "Running API command: /containers/${DOCKERID}/json"
92
JSON=$(echo -e "GET /containers/${DOCKERID}/json HTTP/1.0\r\n" | nc -U /var/run/docker.sock | egrep '^{.*')
93
NAME=$(echo $JSON | jq -r .Name,.Config.Hostname | grep -v null | head -n1 | sed 's|^/||')
94
return 0
@@ -62,10 +111,10 @@ if [ -z "${NAME}" ]
111
fi
112
if [ -z "${NAME}" ]
113
then
65
- echo >&2 "Cannot find the name of docker container '${DOCKERID}'"
114
+ warning "cannot find the name of docker container '${DOCKERID}'"
115
NAME="${DOCKERID:0:12}"
116
else
68
- echo >&2 "Docker container '${DOCKERID}' is named '${NAME}'"
117
+ info "docker container '${DOCKERID}' is named '${NAME}'"
118
fi
119
fi
120
fi
@@ -74,5 +123,5 @@ if [ -z "${NAME}" ]
123
[ ${#NAME} -gt 100 ] && NAME="${NAME:0:100}"
124
fi
125
77
-echo >&2 "${0}: cgroup '${CGROUP}' is called '${NAME}'"
126
+info "cgroup '${CGROUP}' is called '${NAME}'"
127
echo "${NAME}"
plugins.d/charts.d.plugin
+12
-6
@@ -1,5 +1,17 @@
1
#!/usr/bin/env bash
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+# charts.d.plugin allows easy development of BASH plugins
9
+#
10
+# if you need to run parallel charts.d processes, link this file to a different name
11
+# in the same directory, with a .plugin suffix and netdata will start both of them,
12
+# each will have a different config file and modules configuration directory.
13
+#
14
+
15
export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
16
17
PROGRAM_FILE="$0"
@@ -7,12 +19,6 @@ PROGRAM_NAME="$(basename $0)"
19
PROGRAM_NAME="${PROGRAM_NAME/.plugin}"
20
MODULE_NAME="main"
21
10
-# if you need to run parallel charts.d processes
11
-# just link this files with a different name
12
-# in the same directory, with a .plugin suffix
13
-# netdata will start multiple of them
14
-# each will have a different config file
15
-
22
# -----------------------------------------------------------------------------
23
# create temp dir
24
plugins.d/fping.plugin
+62
-25
@@ -1,17 +1,10 @@
1
#!/usr/bin/env bash
2
3
-me="${0}"
4
-
5
-# the frequency to send info to netdata
6
-# passed by netdata as the first parameter
7
-update_every="${1-1}"
8
-
9
-# the netdata configuration directory
10
-# passed by netdata as an environment variable
11
-NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
12
-
13
-# -----------------------------------------------------------------------------
14
-
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
# This plugin requires a special version of fping.
9
# Get it from https://github.com/ktsaou/fping
10
# and build it, like this:
@@ -29,6 +22,58 @@ NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
22
# Then, create /etc/netdata/fping.conf
23
# and set the configuration options given below
24
25
+export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
26
+export LC_ALL=C
27
+
28
+# -----------------------------------------------------------------------------
29
+
30
+PROGRAM_NAME="$(basename "${0}")"
31
+
32
+logdate() {
33
+ date "+%Y-%m-%d %H:%M:%S"
34
+}
35
+
36
+log() {
37
+ local status="${1}"
38
+ shift
39
+
40
+ echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
41
+
42
+}
43
+
44
+warning() {
45
+ log WARNING "${@}"
46
+}
47
+
48
+error() {
49
+ log ERROR "${@}"
50
+}
51
+
52
+info() {
53
+ log INFO "${@}"
54
+}
55
+
56
+fatal() {
57
+ log FATAL "${@}"
58
+ echo "DISABLE"
59
+ exit 1
60
+}
61
+
62
+debug=0
63
+debug() {
64
+ [ $debug -eq 1 ] && log DEBUG "${@}"
65
+}
66
+
67
+# -----------------------------------------------------------------------------
68
+
69
+# the frequency to send info to netdata
70
+# passed by netdata as the first parameter
71
+update_every="${1-1}"
72
+
73
+# the netdata configuration directory
74
+# passed by netdata as an environment variable
75
+NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
76
+
77
# -----------------------------------------------------------------------------
78
# configuration options
79
# can be overwritten at /etc/netdata/fping.conf
@@ -48,29 +93,23 @@ ping_every="$((update_every * 1000 / 2))"
93
retries=1
94
95
# -----------------------------------------------------------------------------
51
-
96
# load the configuration file
97
+
98
if [ ! -f "${NETDATA_CONFIG_DIR}/fping.conf" ]
99
then
55
- echo >&2 "${me}: configuration file '${NETDATA_CONFIG_DIR}/fping.conf' not found - nothing to do."
56
- echo "DISABLE"
57
- exit 1
100
+ fatal "configuration file '${NETDATA_CONFIG_DIR}/fping.conf' not found - nothing to do."
101
fi
102
103
source "${NETDATA_CONFIG_DIR}/fping.conf"
104
105
if [ -z "${hosts}" ]
106
then
64
- echo >&2 "${me}: no hosts configued in '${NETDATA_CONFIG_DIR}/fping.conf' - nothing to do."
65
- echo "DISABLE"
66
- exit 1
107
+ fatal "no hosts configued in '${NETDATA_CONFIG_DIR}/fping.conf' - nothing to do."
108
fi
109
110
if [ -z "${fping}" -o ! -x "${fping}" ]
111
then
71
- echo >&2 "${me}: command '${fping}' is not executable - cannot proceed."
72
- echo "DISABLE"
73
- exit 1
112
+ fatal "command '${fping}' is not executable - cannot proceed."
113
fi
114
115
# the fping options we will use
@@ -80,6 +119,4 @@ options=( -N -l -R -Q ${update_every} -p ${ping_every} -r ${retries} ${hosts} )
119
exec "${fping}" "${options[@]}"
120
121
# if we cannot execute fping, stop
83
-echo >&2 "${me}: command '${fping} ${options[@]}' failed to be executed."
84
-echo "DISABLE"
85
-exit 1
122
+fatal "command '${fping} ${options[@]}' failed to be executed."
plugins.d/tc-qos-helper.sh
+49
-2
@@ -1,11 +1,59 @@
1
#!/usr/bin/env bash
2
3
+# netdata
4
+# real-time performance and health monitoring, done right!
5
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6
+# GPL v3+
7
+#
8
+# This script is a helper to allow netdata collect tc data
9
+# parsing tc output has been implemented in C, inside netdata
10
+# This script allows setting names to dimensions.
11
+
12
export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
13
+export LC_ALL=C
14
15
PROGRAM_FILE="$0"
16
PROGRAM_NAME="$(basename $0)"
17
PROGRAM_NAME="${PROGRAM_NAME/.plugin}"
18
19
+# -----------------------------------------------------------------------------
20
+
21
+logdate() {
22
+ date "+%Y-%m-%d %H:%M:%S"
23
+}
24
+
25
+log() {
26
+ local status="${1}"
27
+ shift
28
+
29
+ echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
30
+
31
+}
32
+
33
+warning() {
34
+ log WARNING "${@}"
35
+}
36
+
37
+error() {
38
+ log ERROR "${@}"
39
+}
40
+
41
+info() {
42
+ log INFO "${@}"
43
+}
44
+
45
+fatal() {
46
+ log FATAL "${@}"
47
+ exit 1
48
+}
49
+
50
+debug=0
51
+debug() {
52
+ [ $debug -eq 1 ] && log DEBUG "${@}"
53
+}
54
+
55
+# -----------------------------------------------------------------------------
56
+
57
plugins_dir="${NETDATA_PLUGINS_DIR}"
58
[ -z "$plugins_dir" ] && plugins_dir="$( dirname $PROGRAM_FILE )"
59
@@ -39,8 +87,7 @@ loopsleepms() {
87
88
if [ -z "${tc}" -o ! -x "${tc}" ]
89
then
42
- echo >&2 "${PROGRAM_NAME}: Cannot find command 'tc' in this system."
43
- exit 1
90
+ fatal "cannot find command 'tc' in this system."
91
fi
92
93
devices=