From 0a26e46c36e7fc1c343f9512ae6ade05a78349a1 Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Thu, 20 Oct 2016 22:39:16 +0300 Subject: [PATCH] uniform logging from all scripts --- charts.d/ap.chart.sh | 6 +++ charts.d/apache.chart.sh | 6 +++ charts.d/apcupsd.chart.sh | 6 +++ charts.d/cpu_apps.chart.sh | 5 ++ charts.d/cpufreq.chart.sh | 6 +++ charts.d/example.chart.sh | 6 +++ charts.d/exim.chart.sh | 7 +++ charts.d/hddtemp.chart.sh | 7 +++ charts.d/load_average.chart.sh | 6 +++ charts.d/mem_apps.chart.sh | 6 +++ charts.d/mysql.chart.sh | 6 +++ charts.d/nginx.chart.sh | 6 +++ charts.d/nut.chart.sh | 6 +++ charts.d/opensips.chart.sh | 6 +++ charts.d/phpfpm.chart.sh | 12 +++-- charts.d/postfix.chart.sh | 6 +++ charts.d/sensors.chart.sh | 6 +++ charts.d/squid.chart.sh | 6 +++ charts.d/tomcat.chart.sh | 7 +++ plugins.d/alarm-notify.sh | 75 ++++++++++++++++++++++------- plugins.d/cgroup-name.sh | 69 +++++++++++++++++++++++---- plugins.d/charts.d.plugin | 18 ++++--- plugins.d/fping.plugin | 87 ++++++++++++++++++++++++---------- plugins.d/tc-qos-helper.sh | 51 +++++++++++++++++++- 24 files changed, 358 insertions(+), 64 deletions(-) diff --git a/charts.d/ap.chart.sh b/charts.d/ap.chart.sh index 477d4148..0e85c486 100755 --- a/charts.d/ap.chart.sh +++ b/charts.d/ap.chart.sh @@ -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 +# GPL v3+ +# + # _update_every is a special variable - it holds the number of seconds # between the calls of the _update() function ap_update_every= diff --git a/charts.d/apache.chart.sh b/charts.d/apache.chart.sh index d59f86eb..b503e74e 100755 --- a/charts.d/apache.chart.sh +++ b/charts.d/apache.chart.sh @@ -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 +# GPL v3+ +# + # the URL to download apache status info apache_url="http://127.0.0.1:80/server-status?auto" apache_curl_opts= diff --git a/charts.d/apcupsd.chart.sh b/charts.d/apcupsd.chart.sh index 41cb39f9..24905afe 100755 --- a/charts.d/apcupsd.chart.sh +++ b/charts.d/apcupsd.chart.sh @@ -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 +# GPL v3+ +# + apcupsd_ip=127.0.0.1 apcupsd_port=3551 diff --git a/charts.d/cpu_apps.chart.sh b/charts.d/cpu_apps.chart.sh index 8893b522..8e075831 100755 --- a/charts.d/cpu_apps.chart.sh +++ b/charts.d/cpu_apps.chart.sh @@ -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 +# GPL v3+ +# # THIS PLUGIN IS OBSOLETE # USE apps.plugin INSTEAD diff --git a/charts.d/cpufreq.chart.sh b/charts.d/cpufreq.chart.sh index 944541c0..b358ac3e 100755 --- a/charts.d/cpufreq.chart.sh +++ b/charts.d/cpufreq.chart.sh @@ -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 +# GPL v3+ +# + # if this chart is called X.chart.sh, then all functions and global variables # must start with X_ diff --git a/charts.d/example.chart.sh b/charts.d/example.chart.sh index cec5e9f7..86fde490 100755 --- a/charts.d/example.chart.sh +++ b/charts.d/example.chart.sh @@ -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 +# GPL v3+ +# + # if this chart is called X.chart.sh, then all functions and global variables # must start with X_ diff --git a/charts.d/exim.chart.sh b/charts.d/exim.chart.sh index f9d48b8a..4c70f2c1 100644 --- a/charts.d/exim.chart.sh +++ b/charts.d/exim.chart.sh @@ -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 +# GPL v3+ +# +# Contributed by @jsveiga with PR #480 + # the exim command to run exim_command= diff --git a/charts.d/hddtemp.chart.sh b/charts.d/hddtemp.chart.sh index 7e4f67da..15895c5e 100755 --- a/charts.d/hddtemp.chart.sh +++ b/charts.d/hddtemp.chart.sh @@ -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 +# 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" diff --git a/charts.d/load_average.chart.sh b/charts.d/load_average.chart.sh index e6790d80..70d3aec7 100755 --- a/charts.d/load_average.chart.sh +++ b/charts.d/load_average.chart.sh @@ -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 +# GPL v3+ +# + load_average_update_every=5 load_priority=100 diff --git a/charts.d/mem_apps.chart.sh b/charts.d/mem_apps.chart.sh index a350d88c..3bc65fe2 100755 --- a/charts.d/mem_apps.chart.sh +++ b/charts.d/mem_apps.chart.sh @@ -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 +# GPL v3+ +# + mem_apps_apps= # these are required for computing memory in bytes and cpu in seconds diff --git a/charts.d/mysql.chart.sh b/charts.d/mysql.chart.sh index 2bb80a8a..86feac99 100755 --- a/charts.d/mysql.chart.sh +++ b/charts.d/mysql.chart.sh @@ -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 +# 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 diff --git a/charts.d/nginx.chart.sh b/charts.d/nginx.chart.sh index f0092fd0..0ae7d630 100755 --- a/charts.d/nginx.chart.sh +++ b/charts.d/nginx.chart.sh @@ -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 +# GPL v3+ +# + # if this chart is called X.chart.sh, then all functions and global variables # must start with X_ diff --git a/charts.d/nut.chart.sh b/charts.d/nut.chart.sh index e2b3a85c..e0b1b4cf 100755 --- a/charts.d/nut.chart.sh +++ b/charts.d/nut.chart.sh @@ -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 +# GPL v3+ +# + # a space separated list of UPS names # if empty, the list returned by 'upsc -l' will be used nut_ups= diff --git a/charts.d/opensips.chart.sh b/charts.d/opensips.chart.sh index 12247fc3..2a0249da 100755 --- a/charts.d/opensips.chart.sh +++ b/charts.d/opensips.chart.sh @@ -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 +# GPL v3+ +# + opensips_opts="fifo get_statistics all" opensips_cmd= opensips_update_every=5 diff --git a/charts.d/phpfpm.chart.sh b/charts.d/phpfpm.chart.sh index 16669e1b..a5ee0ad5 100755 --- a/charts.d/phpfpm.chart.sh +++ b/charts.d/phpfpm.chart.sh @@ -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 +# 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/ diff --git a/charts.d/postfix.chart.sh b/charts.d/postfix.chart.sh index 3a933579..8106414a 100755 --- a/charts.d/postfix.chart.sh +++ b/charts.d/postfix.chart.sh @@ -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 +# GPL v3+ +# + # the postqueue command # if empty, it will use the one found in the system path postfix_postqueue= diff --git a/charts.d/sensors.chart.sh b/charts.d/sensors.chart.sh index f30177a4..125c925d 100755 --- a/charts.d/sensors.chart.sh +++ b/charts.d/sensors.chart.sh @@ -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 +# GPL v3+ +# + # sensors docs # https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface diff --git a/charts.d/squid.chart.sh b/charts.d/squid.chart.sh index 4b4d43ae..2c19c35d 100755 --- a/charts.d/squid.chart.sh +++ b/charts.d/squid.chart.sh @@ -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 +# GPL v3+ +# + squid_host= squid_port= squid_url= diff --git a/charts.d/tomcat.chart.sh b/charts.d/tomcat.chart.sh index c692ae06..44a92c86 100755 --- a/charts.d/tomcat.chart.sh +++ b/charts.d/tomcat.chart.sh @@ -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 +# GPL v3+ +# +# Contributed by @jgeromero with PR #277 + # Description: Tomcat netdata charts.d plugin # Author: Jorge Romero diff --git a/plugins.d/alarm-notify.sh b/plugins.d/alarm-notify.sh index dcb5d401..acd44923 100755 --- a/plugins.d/alarm-notify.sh +++ b/plugins.d/alarm-notify.sh @@ -5,7 +5,7 @@ # (C) 2016 Costa Tsaousis # GPL v3+ # -# Script the send alarm notifications for netdata +# Script to send alarm notifications for netdata # # Features: # - multiple notification methods @@ -20,14 +20,56 @@ # - 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 diff --git a/plugins.d/cgroup-name.sh b/plugins.d/cgroup-name.sh index 1c6f564b..9bb3bcab 100755 --- a/plugins.d/cgroup-name.sh +++ b/plugins.d/cgroup-name.sh @@ -1,17 +1,66 @@ #!/usr/bin/env bash +# netdata +# real-time performance and health monitoring, done right! +# (C) 2016 Costa Tsaousis +# 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}" diff --git a/plugins.d/charts.d.plugin b/plugins.d/charts.d.plugin index 08ca207b..00206f95 100755 --- a/plugins.d/charts.d.plugin +++ b/plugins.d/charts.d.plugin @@ -1,5 +1,17 @@ #!/usr/bin/env bash +# netdata +# real-time performance and health monitoring, done right! +# (C) 2016 Costa Tsaousis +# 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 diff --git a/plugins.d/fping.plugin b/plugins.d/fping.plugin index fa3b62f5..32e1b711 100755 --- a/plugins.d/fping.plugin +++ b/plugins.d/fping.plugin @@ -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 +# 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." diff --git a/plugins.d/tc-qos-helper.sh b/plugins.d/tc-qos-helper.sh index 9caef85f..ffe995f7 100755 --- a/plugins.d/tc-qos-helper.sh +++ b/plugins.d/tc-qos-helper.sh @@ -1,11 +1,59 @@ #!/usr/bin/env bash +# netdata +# real-time performance and health monitoring, done right! +# (C) 2016 Costa Tsaousis +# 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= -- 2.39.2