]> arthur.barton.de Git - netdata.git/blobdiff - charts.d/nut.chart.sh
Merge pull request #1441 from l2isbad/freeradius_bug_fix
[netdata.git] / charts.d / nut.chart.sh
index 156e9bdec601fced759a34c698e741302de884e1..e0b1b4cf981bedbb6e0a8de8c59cecb414d1c77d 100755 (executable)
@@ -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 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
@@ -9,14 +15,17 @@ nut_update_every=2
 
 nut_timeout=2
 
+# 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"
 }
 
 nut_check() {
@@ -27,9 +36,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 +48,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,34 +67,34 @@ nut_create() {
        for x in "${nut_ids[@]}"
        do
                cat <<EOF
-CHART nut_$x.charge '' "UPS Charge" "percentage" $x nut area 21001 $nut_update_every
+CHART nut_$x.charge '' "UPS Charge" "percentage" ups nut.charge area $((nut_priority + 1)) $nut_update_every
 DIMENSION battery_charge charge absolute 1 100
 
-CHART nut_$x.battery_voltage '' "UPS Battery Voltage" "Volts" $x nut line 21002 $nut_update_every
+CHART nut_$x.battery_voltage '' "UPS Battery Voltage" "Volts" ups nut.battery.voltage line $((nut_priority + 2)) $nut_update_every
 DIMENSION battery_voltage voltage absolute 1 100
 DIMENSION battery_voltage_high high absolute 1 100
 DIMENSION battery_voltage_low low absolute 1 100
 DIMENSION battery_voltage_nominal nominal absolute 1 100
 
-CHART nut_$x.input_voltage '' "UPS Input Voltage" "Volts" $x nut line 21003 $nut_update_every
+CHART nut_$x.input_voltage '' "UPS Input Voltage" "Volts" input nut.input.voltage line $((nut_priority + 3)) $nut_update_every
 DIMENSION input_voltage voltage absolute 1 100
 DIMENSION input_voltage_fault fault absolute 1 100
 DIMENSION input_voltage_nominal nominal absolute 1 100
 
-CHART nut_$x.input_current '' "UPS Input Current" "Ampere" $x nut line 21004 $nut_update_every
+CHART nut_$x.input_current '' "UPS Input Current" "Ampere" input nut.input.current line $((nut_priority + 4)) $nut_update_every
 DIMENSION input_current_nominal nominal absolute 1 100
 
-CHART nut_$x.input_frequency '' "UPS Input Frequency" "Hz" $x nut line 21005 $nut_update_every
+CHART nut_$x.input_frequency '' "UPS Input Frequency" "Hz" input nut.input.frequency line $((nut_priority + 5)) $nut_update_every
 DIMENSION input_frequency frequency absolute 1 100
 DIMENSION input_frequency_nominal nominal absolute 1 100
 
-CHART nut_$x.output_voltage '' "UPS Output Voltage" "Volts" $x nut line 21006 $nut_update_every
+CHART nut_$x.output_voltage '' "UPS Output Voltage" "Volts" output nut.output.voltage line $((nut_priority + 6)) $nut_update_every
 DIMENSION output_voltage voltage absolute 1 100
 
-CHART nut_$x.load '' "UPS Load" "percentage" $x nut area 21000 $nut_update_every
+CHART nut_$x.load '' "UPS Load" "percentage" ups nut.load area $((nut_priority)) $nut_update_every
 DIMENSION load load absolute 1 100
 
-CHART nut_$x.temp '' "UPS Temperature" "temperature" $x nut line 21007 $nut_update_every
+CHART nut_$x.temp '' "UPS Temperature" "temperature" ups nut.temperature line $((nut_priority + 7)) $nut_update_every
 DIMENSION temp temp absolute 1 100
 EOF
        done
@@ -178,9 +185,9 @@ END {
        print \"SET temp = \" temp;
        print \"END\"
 }"
-               [ $? -ne 0 ] && unset nut_ids[$i] && echo >&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
 }