]> arthur.barton.de Git - netdata.git/commitdiff
uniform logging from all scripts
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 20 Oct 2016 19:39:16 +0000 (22:39 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 20 Oct 2016 19:39:16 +0000 (22:39 +0300)
24 files changed:
charts.d/ap.chart.sh
charts.d/apache.chart.sh
charts.d/apcupsd.chart.sh
charts.d/cpu_apps.chart.sh
charts.d/cpufreq.chart.sh
charts.d/example.chart.sh
charts.d/exim.chart.sh
charts.d/hddtemp.chart.sh
charts.d/load_average.chart.sh
charts.d/mem_apps.chart.sh
charts.d/mysql.chart.sh
charts.d/nginx.chart.sh
charts.d/nut.chart.sh
charts.d/opensips.chart.sh
charts.d/phpfpm.chart.sh
charts.d/postfix.chart.sh
charts.d/sensors.chart.sh
charts.d/squid.chart.sh
charts.d/tomcat.chart.sh
plugins.d/alarm-notify.sh
plugins.d/cgroup-name.sh
plugins.d/charts.d.plugin
plugins.d/fping.plugin
plugins.d/tc-qos-helper.sh

index 477d414859eb6201c8147c4293246956eb86cfaf..0e85c486dc95daedb9404d680ac37f42f5a70dfc 100755 (executable)
@@ -1,5 +1,11 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+
 # _update_every is a special variable - it holds the number of seconds
 # between the calls of the _update() function
 ap_update_every=
index d59f86ebc4d68c0640e7fbc6e411c408c20bb8f3..b503e74e3d2cdb8e8acd25e937c23d19aea858e9 100755 (executable)
@@ -1,5 +1,11 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+
 # the URL to download apache status info
 apache_url="http://127.0.0.1:80/server-status?auto"
 apache_curl_opts=
index 41cb39f9cd8134d28d823fa9d62521504f0f4a94..24905afe912ac178c428eaa0d1a799e8427b481d 100755 (executable)
@@ -1,5 +1,11 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+
 apcupsd_ip=127.0.0.1
 apcupsd_port=3551
 
index 8893b5220f044f2ad04586d16798ea70d454d54c..8e075831a5b51a9f6485ed9a410663914a9b2cef 100755 (executable)
@@ -1,5 +1,10 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
 # THIS PLUGIN IS OBSOLETE
 # USE apps.plugin INSTEAD
 
index 944541c0e3772e2376c7436d453035a22a4761af..b358ac3e74827455d95ef5753bd1b0735c27e9fa 100755 (executable)
@@ -1,5 +1,11 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+
 # if this chart is called X.chart.sh, then all functions and global variables
 # must start with X_
 
index cec5e9f7d6c4c6efb00584217a69903124d26cf2..86fde490134e077d0d84e9bcbe40ffe818659623 100755 (executable)
@@ -1,5 +1,11 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+
 # if this chart is called X.chart.sh, then all functions and global variables
 # must start with X_
 
index f9d48b8a8bb55b23b175f7a09a4c6415d816eb72..4c70f2c196328295a99c86bb7c0e0d4b995ef3f1 100644 (file)
@@ -1,5 +1,12 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+# Contributed by @jsveiga with PR #480
+
 # the exim command to run
 exim_command=
 
index 7e4f67daca596b08b3884716a6938240a47f9d69..15895c5e160a71a845a586ab1f602492b26b3061 100755 (executable)
@@ -1,5 +1,12 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+# contributed by @paulfantom with PR #511
+
 # if this chart is called X.chart.sh, then all functions and global variables
 # must start with X_
 hddtemp_host="localhost"
index e6790d8077672ec6331cca81104401fcf47e5999..70d3aec7a2dd2c086295f699780be9ae80f347fb 100755 (executable)
@@ -1,5 +1,11 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+
 load_average_update_every=5
 load_priority=100
 
index a350d88c312c5bd9ead102b10135eb573b3c7fe8..3bc65fe24004c9af4e71ebcd88b764f38e5b16eb 100755 (executable)
@@ -1,5 +1,11 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+
 mem_apps_apps=
 
 # these are required for computing memory in bytes and cpu in seconds
index 2bb80a8a9c888b5401d1c80b360630f0aa675a93..86feac997c8ac260d3f8ebc9bf23c5fd7d11e4ba 100755 (executable)
@@ -1,5 +1,11 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+
 # http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html
 #
 # https://dev.mysql.com/doc/refman/5.1/en/show-status.html
index f0092fd07439298ae6bd37cadf2499c3c927284d..0ae7d630775af82d3c4580ba0c6fc6cf401ba15e 100755 (executable)
@@ -1,5 +1,11 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+
 # if this chart is called X.chart.sh, then all functions and global variables
 # must start with X_
 
index e2b3a85c54e33d35b65fda9d71374f4501323181..e0b1b4cf981bedbb6e0a8de8c59cecb414d1c77d 100755 (executable)
@@ -1,5 +1,11 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+
 # a space separated list of UPS names
 # if empty, the list returned by 'upsc -l' will be used
 nut_ups=
index 12247fc322de717257bb5b3eea8b96d4e2d213bf..2a0249daed4d048082188e325c3894b81111f7d0 100755 (executable)
@@ -1,5 +1,11 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+
 opensips_opts="fifo get_statistics all"
 opensips_cmd=
 opensips_update_every=5
index 16669e1be065ea357d680d8d2c293a2ba436f3a8..a5ee0ad561637dd3dd30571e966d1863c019ffb4 100755 (executable)
@@ -1,9 +1,13 @@
 # no need for shebang - this file is loaded from charts.d.plugin
 
-# if this chart is called X.chart.sh, then all functions and global variables
-# must start with X_
-
-# first, you need open php-fpm status in php-fpm.conf 
+# netdata
+# real-time performance and health monitoring, done right!
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
+# GPL v3+
+#
+# Contributed by @safeie with PR #276
+
+# first, you need open php-fpm status in php-fpm.conf
 # second, you need add status location in nginx.conf
 # you can see, https://easyengine.io/tutorials/php/fpm-status-page/
 
index 3a93357947e5e843b4e56a58fe8644e592710cd9..8106414a1f6da024482f348782bb97e2e5ec0abf 100755 (executable)
@@ -1,5 +1,11 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+
 # the postqueue command
 # if empty, it will use the one found in the system path
 postfix_postqueue=
index f30177a4b19c125f12b95b3905fd3b17f846be28..125c925da7f6c031fcbf45bdc78a76cf552bd561 100755 (executable)
@@ -1,5 +1,11 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+
 # sensors docs
 # https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
 
index 4b4d43ae1fdff4739e73b7cd37532e5a9b7bb170..2c19c35d59068f11728cddc6433a786a5bed24fc 100755 (executable)
@@ -1,5 +1,11 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+
 squid_host=
 squid_port=
 squid_url=
index c692ae069b648e4965bf45b3655832e0e971e00c..44a92c86e7bf35f27fb9beb2c324ac056b08720b 100755 (executable)
@@ -1,5 +1,12 @@
 # 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 <costa@tsaousis.gr>
+# GPL v3+
+#
+# Contributed by @jgeromero with PR #277
+
 # Description: Tomcat netdata charts.d plugin
 # Author: Jorge Romero
 
index dcb5d4016b78655c61b680bea1874d91e06d2c07..acd44923f9d768f939b4ef0d51e7a5940cb116aa 100755 (executable)
@@ -5,7 +5,7 @@
 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
 # GPL v3+
 #
-# Script the send alarm notifications for netdata
+# Script to send alarm notifications for netdata
 #
 # Features:
 #  - multiple notification methods
 #  - telegram.org notifications
 #
 
-me="${0}"
+export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
+export LC_ALL=C
+
+# -----------------------------------------------------------------------------
+
+PROGRAM_NAME="$(basename "${0}")"
+
+logdate() {
+    date "+%Y-%m-%d %H:%M:%S"
+}
+
+log() {
+    local status="${1}"
+    shift
+
+    echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
+
+}
+
+warning() {
+    log WARNING "${@}"
+}
+
+error() {
+    log ERROR "${@}"
+}
+
+info() {
+    log INFO "${@}"
+}
+
+fatal() {
+    log FATAL "${@}"
+    exit 1
+}
+
+debug=0
+debug() {
+    [ $debug -eq 1 ] && log DEBUG "${@}"
+}
+
+# -----------------------------------------------------------------------------
 
 # check for BASH v4+ (required for associative arrays)
 [ $(( ${BASH_VERSINFO[0]} )) -lt 4 ] && \
-    echo >&2 "${me}: BASH version 4 or later is required (this is ${BASH_VERSION})." && \
-    exit 1
+    fatal "BASH version 4 or later is required (this is ${BASH_VERSION})."
 
+# -----------------------------------------------------------------------------
 # defaults to allow running this script by hand
+
 NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
 NETDATA_CACHE_DIR="${NETDATA_CACHE_DIR-/var/cache/netdata}"
 [ -z "${NETDATA_REGISTRY_URL}" ] && NETDATA_REGISTRY_URL="https://registry.my-netdata.io"
@@ -62,14 +104,14 @@ info="${18}"       # a short description of the alarm
 # don't do anything if this is not WARNING, CRITICAL or CLEAR
 if [ "${status}" != "WARNING" -a "${status}" != "CRITICAL" -a "${status}" != "CLEAR" ]
 then
-    echo >&2 "${me}: not sending notification for ${status} on '${chart}.${name}'"
+    info "not sending notification for ${status} on '${chart}.${name}'"
     exit 1
 fi
 
 # don't do anything if this is CLEAR, but it was not WARNING or CRITICAL
 if [ "${old_status}" != "WARNING" -a "${old_status}" != "CRITICAL" -a "${status}" = "CLEAR" ]
 then
-    echo >&2 "${me}: not sending notification for ${status} on '${chart}.${name}' (last status was ${old_status})"
+    info "not sending notification for ${status} on '${chart}.${name}' (last status was ${old_status})"
     exit 1
 fi
 
@@ -262,8 +304,7 @@ fi
 # check that we have at least a method enabled
 if [ "${SEND_EMAIL}" != "YES" -a "${SEND_PUSHOVER}" != "YES" -a "${SEND_TELEGRAM}" != "YES" -a "${SEND_SLACK}" != "YES" ]
     then
-    echo >&2 "All notification methods are disabled. Not sending a notification."
-    exit 1
+    fatal "All notification methods are disabled. Not sending a notification."
 fi
 
 # -----------------------------------------------------------------------------
@@ -372,10 +413,10 @@ send_email() {
 
         if [ $ret -eq 0 ]
         then
-            echo >&2 "${me}: Sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'"
+            info "sent email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}'"
             return 0
         else
-            echo >&2 "${me}: Failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret}."
+            error "failed to send email notification for: ${host} ${chart}.${name} is ${status} to '${to_email}' with error code ${ret}."
             return 1
         fi
     fi
@@ -417,10 +458,10 @@ send_pushover() {
 
             if [ "${httpcode}" == "200" ]
             then
-                echo >&2 "${me}: Sent pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
+                info "sent pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}'"
                 sent=$((sent + 1))
             else
-                echo >&2 "${me}: Failed to send pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
+                error "failed to send pushover notification for: ${host} ${chart}.${name} is ${status} to '${user}' with HTTP error code ${httpcode}."
             fi
         done
 
@@ -452,13 +493,13 @@ send_telegram() {
 
             if [ "${httpcode}" == "200" ]
             then
-                echo >&2 "${me}: Sent telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}'"
+                info "sent telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}'"
                 sent=$((sent + 1))
             elif [ "${httpcode}" == "401" ]
             then
-                echo >&2 "${me}: Failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}': Wrong bot token."
+                error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}': Wrong bot token."
             else
-                echo >&2 "${me}: Failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}' with HTTP error code ${httpcode}."
+                error "failed to send telegram notification for: ${host} ${chart}.${name} is ${status} to '${chatid}' with HTTP error code ${httpcode}."
             fi
         done
 
@@ -520,10 +561,10 @@ EOF
         httpcode=$(${curl} --write-out %{http_code} --silent --output /dev/null -X POST --data-urlencode "payload=${payload}" "${webhook}")
         if [ "${httpcode}" == "200" ]
         then
-            echo >&2 "${me}: Sent slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
+            info "sent slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}'"
             sent=$((sent + 1))
         else
-            echo >&2 "${me}: Failed to send slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
+            error "failed to send slack notification for: ${host} ${chart}.${name} is ${status} to '${channel}', with HTTP error code ${httpcode}."
         fi
     done
 
index 1c6f564b4c820dab31282939b63bb9ddcbd671c5..9bb3bcabbe7a426d0789ae8658adcfe08260b132 100755 (executable)
@@ -1,17 +1,66 @@
 #!/usr/bin/env bash
 
+# netdata
+# real-time performance and health monitoring, done right!
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
+# GPL v3+
+#
+# Script to find a better name for cgroups
+#
+
 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
 export LC_ALL=C
 
+# -----------------------------------------------------------------------------
+
+PROGRAM_NAME="$(basename "${0}")"
+
+logdate() {
+    date "+%Y-%m-%d %H:%M:%S"
+}
+
+log() {
+    local status="${1}"
+    shift
+
+    echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
+
+}
+
+warning() {
+    log WARNING "${@}"
+}
+
+error() {
+    log ERROR "${@}"
+}
+
+info() {
+    log INFO "${@}"
+}
+
+fatal() {
+    log FATAL "${@}"
+    exit 1
+}
+
+debug=0
+debug() {
+    [ $debug -eq 1 ] && log DEBUG "${@}"
+}
+
+# -----------------------------------------------------------------------------
+
 NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
 CONFIG="${NETDATA_CONFIG_DIR}/cgroups-names.conf"
 CGROUP="${1}"
 NAME=
 
+# -----------------------------------------------------------------------------
+
 if [ -z "${CGROUP}" ]
     then
-    echo >&2 "${0}: called without a cgroup name. Nothing to do."
-    exit 1
+    fatal "called without a cgroup name. Nothing to do."
 fi
 
 if [ -f "${CONFIG}" ]
@@ -19,15 +68,15 @@ if [ -f "${CONFIG}" ]
     NAME="$(grep "^${CGROUP} " "${CONFIG}" | sed "s/[[:space:]]\+/ /g" | cut -d ' ' -f 2)"
     if [ -z "${NAME}" ]
         then
-        echo >&2 "${0}: cannot find cgroup '${CGROUP}' in '${CONFIG}'."
+        info "cannot find cgroup '${CGROUP}' in '${CONFIG}'."
     fi
 #else
-#   echo >&2 "${0}: configuration file '${CONFIG}' is not available."
+#   info "configuration file '${CONFIG}' is not available."
 fi
 
 function get_name_classic {
     local DOCKERID="$1"
-    echo >&2 "Running command: docker ps --filter=id=\"${DOCKERID}\" --format=\"{{.Names}}\""
+    info "Running command: docker ps --filter=id=\"${DOCKERID}\" --format=\"{{.Names}}\""
     NAME="$( docker ps --filter=id="${DOCKERID}" --format="{{.Names}}" )"
     return 0
 }
@@ -36,10 +85,10 @@ function get_name_api {
     local DOCKERID="$1"
     if [ ! -S "/var/run/docker.sock" ]
         then
-        echo >&2 "Can't find /var/run/docker.sock"
+        warning "Can't find /var/run/docker.sock"
         return 1
     fi
-    echo >&2 "Running API command: /containers/${DOCKERID}/json"
+    info "Running API command: /containers/${DOCKERID}/json"
     JSON=$(echo -e "GET /containers/${DOCKERID}/json HTTP/1.0\r\n" | nc -U /var/run/docker.sock | egrep '^{.*')
     NAME=$(echo $JSON | jq -r .Name,.Config.Hostname | grep -v null | head -n1 | sed 's|^/||')
     return 0
@@ -62,10 +111,10 @@ if [ -z "${NAME}" ]
             fi
             if [ -z "${NAME}" ]
                 then
-                echo >&2 "Cannot find the name of docker container '${DOCKERID}'"
+                warning "cannot find the name of docker container '${DOCKERID}'"
                 NAME="${DOCKERID:0:12}"
             else
-                echo >&2 "Docker container '${DOCKERID}' is named '${NAME}'"
+                info "docker container '${DOCKERID}' is named '${NAME}'"
             fi
         fi
     fi
@@ -74,5 +123,5 @@ if [ -z "${NAME}" ]
     [ ${#NAME} -gt 100 ] && NAME="${NAME:0:100}"
 fi
 
-echo >&2 "${0}: cgroup '${CGROUP}' is called '${NAME}'"
+info "cgroup '${CGROUP}' is called '${NAME}'"
 echo "${NAME}"
index 08ca207b481ecc9a3efe1c7862c147c6592bc897..00206f95f96fe9844585b51c8d72b89d4e78396a 100755 (executable)
@@ -1,5 +1,17 @@
 #!/usr/bin/env bash
 
+# netdata
+# real-time performance and health monitoring, done right!
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
+# GPL v3+
+#
+# charts.d.plugin allows easy development of BASH plugins
+#
+# if you need to run parallel charts.d processes, link this file to a different name
+# in the same directory, with a .plugin suffix and netdata will start both of them,
+# each will have a different config file and modules configuration directory.
+#
+
 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
 
 PROGRAM_FILE="$0"
@@ -7,12 +19,6 @@ PROGRAM_NAME="$(basename $0)"
 PROGRAM_NAME="${PROGRAM_NAME/.plugin}"
 MODULE_NAME="main"
 
-# if you need to run parallel charts.d processes
-# just link this files with a different name
-# in the same directory, with a .plugin suffix
-# netdata will start multiple of them
-# each will have a different config file
-
 # -----------------------------------------------------------------------------
 # create temp dir
 
index fa3b62f577d896bec214ec9a876d5adbcd96483b..32e1b711444f34584e9a3380ad6f8b4862cbe244 100755 (executable)
@@ -1,17 +1,10 @@
 #!/usr/bin/env bash
 
-me="${0}"
-
-# the frequency to send info to netdata
-# passed by netdata as the first parameter
-update_every="${1-1}"
-
-# the netdata configuration directory
-# passed by netdata as an environment variable
-NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
-
-# -----------------------------------------------------------------------------
-
+# netdata
+# real-time performance and health monitoring, done right!
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
+# GPL v3+
+#
 # This plugin requires a special version of fping.
 # Get it from https://github.com/ktsaou/fping
 # and build it, like this:
@@ -29,6 +22,58 @@ NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
 # Then, create /etc/netdata/fping.conf
 # and set the configuration options given below
 
+export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
+export LC_ALL=C
+
+# -----------------------------------------------------------------------------
+
+PROGRAM_NAME="$(basename "${0}")"
+
+logdate() {
+    date "+%Y-%m-%d %H:%M:%S"
+}
+
+log() {
+    local status="${1}"
+    shift
+
+    echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
+
+}
+
+warning() {
+    log WARNING "${@}"
+}
+
+error() {
+    log ERROR "${@}"
+}
+
+info() {
+    log INFO "${@}"
+}
+
+fatal() {
+    log FATAL "${@}"
+       echo "DISABLE"
+    exit 1
+}
+
+debug=0
+debug() {
+    [ $debug -eq 1 ] && log DEBUG "${@}"
+}
+
+# -----------------------------------------------------------------------------
+
+# the frequency to send info to netdata
+# passed by netdata as the first parameter
+update_every="${1-1}"
+
+# the netdata configuration directory
+# passed by netdata as an environment variable
+NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
+
 # -----------------------------------------------------------------------------
 # configuration options
 # can be overwritten at /etc/netdata/fping.conf
@@ -48,29 +93,23 @@ ping_every="$((update_every * 1000 / 2))"
 retries=1
 
 # -----------------------------------------------------------------------------
-
 # load the configuration file
+
 if [ ! -f "${NETDATA_CONFIG_DIR}/fping.conf" ]
 then
-       echo >&2 "${me}: configuration file '${NETDATA_CONFIG_DIR}/fping.conf' not found - nothing to do."
-       echo "DISABLE"
-       exit 1
+       fatal "configuration file '${NETDATA_CONFIG_DIR}/fping.conf' not found - nothing to do."
 fi
 
 source "${NETDATA_CONFIG_DIR}/fping.conf"
 
 if [ -z "${hosts}" ]
 then
-       echo >&2 "${me}: no hosts configued in '${NETDATA_CONFIG_DIR}/fping.conf' - nothing to do."
-       echo "DISABLE"
-       exit 1
+       fatal "no hosts configued in '${NETDATA_CONFIG_DIR}/fping.conf' - nothing to do."
 fi
 
 if [ -z "${fping}" -o ! -x "${fping}" ]
 then
-       echo >&2 "${me}: command '${fping}' is not executable - cannot proceed."
-       echo "DISABLE"
-       exit 1
+       fatal "command '${fping}' is not executable - cannot proceed."
 fi
 
 # the fping options we will use
@@ -80,6 +119,4 @@ options=( -N -l -R -Q ${update_every} -p ${ping_every} -r ${retries} ${hosts} )
 exec "${fping}" "${options[@]}"
 
 # if we cannot execute fping, stop
-echo >&2 "${me}: command '${fping} ${options[@]}' failed to be executed."
-echo "DISABLE"
-exit 1
+fatal "command '${fping} ${options[@]}' failed to be executed."
index 9caef85f720cfeae0a8fb0bf54ed9efbd31898cc..ffe995f7d316616e1fc963d97078e9afad26f1b7 100755 (executable)
@@ -1,11 +1,59 @@
 #!/usr/bin/env bash
 
+# netdata
+# real-time performance and health monitoring, done right!
+# (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
+# GPL v3+
+#
+# This script is a helper to allow netdata collect tc data
+# parsing tc output has been implemented in C, inside netdata
+# This script allows setting names to dimensions.
+
 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
+export LC_ALL=C
 
 PROGRAM_FILE="$0"
 PROGRAM_NAME="$(basename $0)"
 PROGRAM_NAME="${PROGRAM_NAME/.plugin}"
 
+# -----------------------------------------------------------------------------
+
+logdate() {
+    date "+%Y-%m-%d %H:%M:%S"
+}
+
+log() {
+    local status="${1}"
+    shift
+
+    echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
+
+}
+
+warning() {
+    log WARNING "${@}"
+}
+
+error() {
+    log ERROR "${@}"
+}
+
+info() {
+    log INFO "${@}"
+}
+
+fatal() {
+    log FATAL "${@}"
+    exit 1
+}
+
+debug=0
+debug() {
+    [ $debug -eq 1 ] && log DEBUG "${@}"
+}
+
+# -----------------------------------------------------------------------------
+
 plugins_dir="${NETDATA_PLUGINS_DIR}"
 [ -z "$plugins_dir" ] && plugins_dir="$( dirname $PROGRAM_FILE )"
 
@@ -39,8 +87,7 @@ loopsleepms() {
 
 if [ -z "${tc}" -o ! -x "${tc}" ]
     then
-    echo >&2 "${PROGRAM_NAME}: Cannot find command 'tc' in this system."
-    exit 1
+    fatal "cannot find command 'tc' in this system."
 fi
 
 devices=