diff options
Diffstat (limited to 'collectors/charts.d.plugin/nut')
-rw-r--r-- | collectors/charts.d.plugin/nut/README.md | 2 | ||||
-rw-r--r-- | collectors/charts.d.plugin/nut/nut.chart.sh | 35 |
2 files changed, 15 insertions, 22 deletions
diff --git a/collectors/charts.d.plugin/nut/README.md b/collectors/charts.d.plugin/nut/README.md index 71906f55..3e169936 100644 --- a/collectors/charts.d.plugin/nut/README.md +++ b/collectors/charts.d.plugin/nut/README.md @@ -57,3 +57,5 @@ nut_update_every=2 ``` --- + +[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Fcollectors%2Fcharts.d.plugin%2Fnut%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)]() diff --git a/collectors/charts.d.plugin/nut/nut.chart.sh b/collectors/charts.d.plugin/nut/nut.chart.sh index 7e252f32..933d3561 100644 --- a/collectors/charts.d.plugin/nut/nut.chart.sh +++ b/collectors/charts.d.plugin/nut/nut.chart.sh @@ -34,8 +34,7 @@ nut_get_all() { nut_get() { run -t $nut_timeout upsc "$1" - if [ "${nut_clients_chart}" -eq "1" ] - then + if [ "${nut_clients_chart}" -eq "1" ]; then printf "ups.connected_clients: " run -t $nut_timeout upsc -c "$1" | wc -l fi @@ -51,27 +50,23 @@ nut_check() { require_cmd upsc || return 1 - [ -z "$nut_ups" ] && nut_ups="$( nut_get_all )" + [ -z "$nut_ups" ] && nut_ups="$(nut_get_all)" - for x in $nut_ups - do + for x in $nut_ups; do nut_get "$x" >/dev/null # shellcheck disable=SC2181 - if [ $? -eq 0 ] - then - if [ ! -z "${nut_names[${x}]}" ] - then - nut_ids[$x]="$( fixid "${nut_names[${x}]}" )" + if [ $? -eq 0 ]; then + if [ ! -z "${nut_names[${x}]}" ]; then + nut_ids[$x]="$(fixid "${nut_names[${x}]}")" else - nut_ids[$x]="$( fixid "$x" )" + nut_ids[$x]="$(fixid "$x")" fi continue fi error "cannot get information for NUT UPS '$x'." done - if [ ${#nut_ids[@]} -eq 0 ] - then + if [ ${#nut_ids[@]} -eq 0 ]; then # shellcheck disable=SC2154 error "Cannot find UPSes - please set nut_ups='ups_name' in $confd/nut.conf" return 1 @@ -84,8 +79,7 @@ nut_create() { # create the charts local x - for x in "${nut_ids[@]}" - do + for x in "${nut_ids[@]}"; do cat <<EOF CHART nut_$x.charge '' "UPS Charge" "percentage" ups nut.charge area $((nut_priority + 1)) $nut_update_every DIMENSION battery_charge charge absolute 1 100 @@ -121,20 +115,18 @@ CHART nut_$x.temp '' "UPS Temperature" "temperature" ups nut.temperature line $( DIMENSION temp temp absolute 1 100 EOF - if [ "${nut_clients_chart}" = "1" ] - then - cat <<EOF2 + if [ "${nut_clients_chart}" = "1" ]; then + cat <<EOF2 CHART nut_$x.clients '' "UPS Connected Clients" "clients" ups nut.clients area $((nut_priority + 9)) $nut_update_every DIMENSION clients '' absolute 1 1 EOF2 - fi + fi done return 0 } - nut_update() { # the first argument to this function is the microseconds since last update # pass this parameter to the BEGIN statement (see bellow). @@ -144,8 +136,7 @@ nut_update() { # remember: KEEP IT SIMPLE AND SHORT local i x - for i in "${!nut_ids[@]}" - do + for i in "${!nut_ids[@]}"; do x="${nut_ids[$i]}" nut_get "$i" | awk " BEGIN { |