diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-02-08 07:30:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2019-02-08 07:30:37 +0000 |
commit | 8a7b72f7cd1ccd547a03eb4243294e741d661d3f (patch) | |
tree | 7bc7be4a8e9e298daa1349348400aa2a653866f2 /collectors/charts.d.plugin/apcupsd | |
parent | New upstream version 1.11.1+dfsg (diff) | |
download | netdata-8a7b72f7cd1ccd547a03eb4243294e741d661d3f.tar.xz netdata-8a7b72f7cd1ccd547a03eb4243294e741d661d3f.zip |
Adding upstream version 1.12.0.upstream/1.12.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'collectors/charts.d.plugin/apcupsd')
-rw-r--r-- | collectors/charts.d.plugin/apcupsd/README.md | 7 | ||||
-rw-r--r-- | collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh | 189 |
2 files changed, 102 insertions, 94 deletions
diff --git a/collectors/charts.d.plugin/apcupsd/README.md b/collectors/charts.d.plugin/apcupsd/README.md index e69de29b..59739efc 100644 --- a/collectors/charts.d.plugin/apcupsd/README.md +++ b/collectors/charts.d.plugin/apcupsd/README.md @@ -0,0 +1,7 @@ +# apcupsd + +*Under construction* + +Collects UPS metrics + +[![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%2Fapcupsd%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)]() diff --git a/collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh b/collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh index e26ef566..b4b92cdc 100644 --- a/collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh +++ b/collectors/charts.d.plugin/apcupsd/apcupsd.chart.sh @@ -11,7 +11,7 @@ apcupsd_ip= apcupsd_port= declare -A apcupsd_sources=( - ["local"]="127.0.0.1:3551" + ["local"]="127.0.0.1:3551" ) # how frequently to collect UPS data @@ -35,46 +35,40 @@ apcupsd_check() { require_cmd apcaccess || return 1 # backwards compatibility - if [ "${apcupsd_ip}:${apcupsd_port}" != ":" ] - then - apcupsd_sources["local"]="${apcupsd_ip}:${apcupsd_port}" + if [ "${apcupsd_ip}:${apcupsd_port}" != ":" ]; then + apcupsd_sources["local"]="${apcupsd_ip}:${apcupsd_port}" fi - local host working=0 failed=0 - for host in "${!apcupsd_sources[@]}" - do - run apcupsd_get "${apcupsd_sources[${host}]}" >/dev/null - # shellcheck disable=2181 - if [ $? -ne 0 ] - then - error "cannot get information for apcupsd server ${host} on ${apcupsd_sources[${host}]}." - failed=$((failed + 1)) - elif [ "$(apcupsd_get "${apcupsd_sources[${host}]}" | awk '/^STATUS.*/{ print $3 }')" != "ONLINE" ] - then - error "APC UPS ${host} on ${apcupsd_sources[${host}]} is not online." - failed=$((failed + 1)) - else - working=$((working + 1)) - fi - done - - if [ ${working} -eq 0 ] - then - error "No APC UPSes found available." - return 1 - fi + local host working=0 failed=0 + for host in "${!apcupsd_sources[@]}"; do + run apcupsd_get "${apcupsd_sources[${host}]}" >/dev/null + # shellcheck disable=2181 + if [ $? -ne 0 ]; then + error "cannot get information for apcupsd server ${host} on ${apcupsd_sources[${host}]}." + failed=$((failed + 1)) + elif [ "$(apcupsd_get "${apcupsd_sources[${host}]}" | awk '/^STATUS.*/{ print $3 }')" != "ONLINE" ]; then + error "APC UPS ${host} on ${apcupsd_sources[${host}]} is not online." + failed=$((failed + 1)) + else + working=$((working + 1)) + fi + done + + if [ ${working} -eq 0 ]; then + error "No APC UPSes found available." + return 1 + fi return 0 } apcupsd_create() { - local host src - for host in "${!apcupsd_sources[@]}" - do - src=${apcupsd_sources[${host}]} + local host src + for host in "${!apcupsd_sources[@]}"; do + src=${apcupsd_sources[${host}]} - # create the charts - cat <<EOF + # create the charts + cat <<EOF CHART apcupsd_${host}.charge '' "UPS Charge for ${host} on ${src}" "percentage" ups apcupsd.charge area $((apcupsd_priority + 1)) $apcupsd_update_every DIMENSION battery_charge charge absolute 1 100 @@ -103,12 +97,14 @@ DIMENSION temp temp absolute 1 100 CHART apcupsd_${host}.time '' "UPS Time Remaining for ${host} on ${src}" "Minutes" ups apcupsd.time area $((apcupsd_priority + 2)) $apcupsd_update_every DIMENSION time time absolute 1 100 +CHART apcupsd_${host}.online '' "UPS ONLINE flag for ${host} on ${src}" "boolean" ups apcupsd.online line $((apcupsd_priority + 8)) $apcupsd_update_every +DIMENSION online online absolute 0 1 + EOF - done + done return 0 } - apcupsd_update() { # the first argument to this function is the microseconds since last update # pass this parameter to the BEGIN statement (see bellow). @@ -117,10 +113,9 @@ apcupsd_update() { # for each dimension # remember: KEEP IT SIMPLE AND SHORT - local host working=0 failed=0 - for host in "${!apcupsd_sources[@]}" - do - apcupsd_get "${apcupsd_sources[${host}]}" | awk " + local host working=0 failed=0 + for host in "${!apcupsd_sources[@]}"; do + apcupsd_get "${apcupsd_sources[${host}]}" | awk " BEGIN { battery_charge = 0; @@ -130,70 +125,76 @@ BEGIN { input_voltage_min = 0; input_voltage_max = 0; input_frequency = 0; - output_voltage = 0; + output_voltage = 0; output_voltage_nominal = 0; load = 0; temp = 0; time = 0; } -/^BCHARGE.*/ { battery_charge = \$3 * 100 }; -/^BATTV.*/ { battery_voltage = \$3 * 100 }; -/^NOMBATTV.*/ { battery_voltage_nominal = \$3 * 100 }; -/^LINEV.*/ { input_voltage = \$3 * 100 }; -/^MINLINEV.*/ { input_voltage_min = \$3 * 100 }; -/^MAXLINEV.*/ { input_voltage_max = \$3 * 100 }; -/^LINEFREQ.*/ { input_frequency = \$3 * 100 }; -/^OUTPUTV.*/ { output_voltage = \$3 * 100 }; -/^NOMOUTV.*/ { output_voltage_nominal = \$3 * 100 }; -/^LOADPCT.*/ { load = \$3 * 100 }; -/^ITEMP.*/ { temp = \$3 * 100 }; -/^TIMELEFT.*/ { time = \$3 * 100 }; +/^BCHARGE.*/ { battery_charge = \$3 * 100 }; +/^BATTV.*/ { battery_voltage = \$3 * 100 }; +/^NOMBATTV.*/ { battery_voltage_nominal = \$3 * 100 }; +/^LINEV.*/ { input_voltage = \$3 * 100 }; +/^MINLINEV.*/ { input_voltage_min = \$3 * 100 }; +/^MAXLINEV.*/ { input_voltage_max = \$3 * 100 }; +/^LINEFREQ.*/ { input_frequency = \$3 * 100 }; +/^OUTPUTV.*/ { output_voltage = \$3 * 100 }; +/^NOMOUTV.*/ { output_voltage_nominal = \$3 * 100 }; +/^LOADPCT.*/ { load = \$3 * 100 }; +/^ITEMP.*/ { temp = \$3 * 100 }; +/^TIMELEFT.*/ { time = \$3 * 100 }; +/^STATUS.*/ { online=(\$3 == \"ONLINE\")?1:0 }; END { - print \"BEGIN apcupsd_${host}.charge $1\"; - print \"SET battery_charge = \" battery_charge; - print \"END\" - - print \"BEGIN apcupsd_${host}.battery_voltage $1\"; - print \"SET battery_voltage = \" battery_voltage; - print \"SET battery_voltage_nominal = \" battery_voltage_nominal; - print \"END\" - - print \"BEGIN apcupsd_${host}.input_voltage $1\"; - print \"SET input_voltage = \" input_voltage; - print \"SET input_voltage_min = \" input_voltage_min; - print \"SET input_voltage_max = \" input_voltage_max; - print \"END\" - - print \"BEGIN apcupsd_${host}.input_frequency $1\"; - print \"SET input_frequency = \" input_frequency; - print \"END\" - - print \"BEGIN apcupsd_${host}.output_voltage $1\"; - print \"SET output_voltage = \" output_voltage; - print \"SET output_voltage_nominal = \" output_voltage_nominal; - print \"END\" - - print \"BEGIN apcupsd_${host}.load $1\"; - print \"SET load = \" load; - print \"END\" - - print \"BEGIN apcupsd_${host}.temp $1\"; - print \"SET temp = \" temp; + print \"BEGIN apcupsd_${host}.online $1\"; + print \"SET online = \" online; print \"END\" - print \"BEGIN apcupsd_${host}.time $1\"; - print \"SET time = \" time; - print \"END\" + if (online == 1) { + print \"BEGIN apcupsd_${host}.charge $1\"; + print \"SET battery_charge = \" battery_charge; + print \"END\" + + print \"BEGIN apcupsd_${host}.battery_voltage $1\"; + print \"SET battery_voltage = \" battery_voltage; + print \"SET battery_voltage_nominal = \" battery_voltage_nominal; + print \"END\" + + print \"BEGIN apcupsd_${host}.input_voltage $1\"; + print \"SET input_voltage = \" input_voltage; + print \"SET input_voltage_min = \" input_voltage_min; + print \"SET input_voltage_max = \" input_voltage_max; + print \"END\" + + print \"BEGIN apcupsd_${host}.input_frequency $1\"; + print \"SET input_frequency = \" input_frequency; + print \"END\" + + print \"BEGIN apcupsd_${host}.output_voltage $1\"; + print \"SET output_voltage = \" output_voltage; + print \"SET output_voltage_nominal = \" output_voltage_nominal; + print \"END\" + + print \"BEGIN apcupsd_${host}.load $1\"; + print \"SET load = \" load; + print \"END\" + + print \"BEGIN apcupsd_${host}.temp $1\"; + print \"SET temp = \" temp; + print \"END\" + + print \"BEGIN apcupsd_${host}.time $1\"; + print \"SET time = \" time; + print \"END\" + } }" - # shellcheck disable=SC2181 - if [ $? -ne 0 ] - then - failed=$((failed + 1)) - error "failed to get values for APC UPS ${host} on ${apcupsd_sources[${host}]}" && return 1 - else - working=$((working + 1)) - fi - done + # shellcheck disable=SC2181 + if [ $? -ne 0 ]; then + failed=$((failed + 1)) + error "failed to get values for APC UPS ${host} on ${apcupsd_sources[${host}]}" && return 1 + else + working=$((working + 1)) + fi + done [ $working -eq 0 ] && error "failed to get values from all APC UPSes" && return 1 |