X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=charts.d%2Fnut.chart.sh;h=6137639f982621277caa6fe21fce46133ef400eb;hb=8a870a65d0afc49455b4b5ff2b0ce585e0bd8339;hp=551ee4074b582db7d90e30d6cc8a40170ba653c7;hpb=5aff09af4fd7cdd042661bb5330c905af85c4779;p=netdata.git diff --git a/charts.d/nut.chart.sh b/charts.d/nut.chart.sh old mode 100755 new mode 100644 index 551ee407..6137639f --- a/charts.d/nut.chart.sh +++ b/charts.d/nut.chart.sh @@ -1,19 +1,70 @@ -#!/bin/sh +# 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 nut_ups= + +# how frequently to collect UPS data nut_update_every=2 -nut_check() { - if [ -z "${nut_ups}" ] +# 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() { + run -t $nut_timeout upsc -l +} + +nut_get() { + run -t $nut_timeout upsc "$1" + + if [ "${nut_clients_chart}" -eq "1" ] then - echo >&2 "nut: Please set nut_ups='ups_name' in $confd/nut.conf" - return 1 + printf "ups.connected_clients: " + run -t $nut_timeout upsc -c "$1" | wc -l fi +} + +nut_check() { + + # this should return: + # - 0 to enable the chart + # - 1 to disable the chart - upsc "${nut_ups}" >/dev/null - if [ ! $? -eq 0 ] - then - echo >&2 "nut: failed to fetch info for ups '$nut_ups'. Please set nut_ups='ups_name' in $confd/nut.conf" + local x + + require_cmd upsc || return 1 + + [ -z "$nut_ups" ] && nut_ups="$( nut_get_all )" + + for x in $nut_ups + do + nut_get "$x" >/dev/null + if [ $? -eq 0 ] + then + nut_ids[$x]="$( fixid "$x" )" + continue + fi + error "cannot get information for NUT UPS '$x'." + done + + if [ ${#nut_ids[@]} -eq 0 ] + then + error "Cannot find UPSes - please set nut_ups='ups_name' in $confd/nut.conf" return 1 fi @@ -22,38 +73,52 @@ nut_check() { nut_create() { # create the charts - cat <