X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=charts.d%2Fnut.chart.sh;h=6137639f982621277caa6fe21fce46133ef400eb;hb=4d0af341e3c40993ba427fe4e306f09cc6866577;hp=d756c82374d2e5cef2ae003862598b805f0a2e9f;hpb=1a989c369f68b810f1261b0261d626aa715d6d4c;p=netdata.git diff --git a/charts.d/nut.chart.sh b/charts.d/nut.chart.sh old mode 100755 new mode 100644 index d756c823..6137639f --- a/charts.d/nut.chart.sh +++ b/charts.d/nut.chart.sh @@ -1,4 +1,10 @@ -#!/bin/bash +# no need for shebang - this file is loaded from charts.d.plugin + +# netdata +# real-time performance and health monitoring, done right! +# (C) 2016-2017 Costa Tsaousis +# GPL v3+ +# # a space separated list of UPS names # if empty, the list returned by 'upsc -l' will be used @@ -7,16 +13,30 @@ nut_ups= # how frequently to collect UPS data nut_update_every=2 +# how much time in seconds, to wait for nut to respond nut_timeout=2 +# set this to 1, to enable another chart showing the number +# of UPS clients connected to upsd +nut_clients_chart=0 + +# the priority of nut related to other charts +nut_priority=90000 + declare -A nut_ids=() nut_get_all() { - timeout $nut_timeout upsc -l + run -t $nut_timeout upsc -l } nut_get() { - timeout $nut_timeout upsc "$1" + run -t $nut_timeout upsc "$1" + + if [ "${nut_clients_chart}" -eq "1" ] + then + printf "ups.connected_clients: " + run -t $nut_timeout upsc -c "$1" | wc -l + fi } nut_check() { @@ -27,9 +47,7 @@ nut_check() { local x - require_cmd timeout || return 1 require_cmd upsc || return 1 - require_cmd awk || return 1 [ -z "$nut_ups" ] && nut_ups="$( nut_get_all )" @@ -41,12 +59,12 @@ nut_check() { nut_ids[$x]="$( fixid "$x" )" continue fi - echo >&2 "nut: ERROR: Cannot get information for NUT UPS '$x'." + error "cannot get information for NUT UPS '$x'." done if [ ${#nut_ids[@]} -eq 0 ] then - echo >&2 "nut: Please set nut_ups='ups_name' in $confd/nut.conf" + error "Cannot find UPSes - please set nut_ups='ups_name' in $confd/nut.conf" return 1 fi @@ -60,36 +78,45 @@ nut_create() { for x in "${nut_ids[@]}" do cat <&2 "nut: failed to get values for '$i', disabling it." + [ $? -ne 0 ] && unset nut_ids[$i] && error "failed to get values for '$i', disabling it." done - [ ${#nut_ids[@]} -eq 0 ] && echo >&2 "nut: no UPSes left active." && return 1 + [ ${#nut_ids[@]} -eq 0 ] && error "no UPSes left active." && return 1 return 0 }