1 # no need for shebang - this file is loaded from charts.d.plugin
6 # how frequently to collect UPS data
7 apcupsd_update_every=10
11 # the priority of apcupsd related to other charts
12 apcupsd_priority=90000
15 timeout $apcupsd_timeout apcaccess status "$1:$2"
21 # - 0 to enable the chart
22 # - 1 to disable the chart
24 require_cmd apcaccess || return 1
26 apcupsd_get $apcupsd_ip $apcupsd_port >/dev/null
29 echo >&2 "apcupsd: ERROR: Cannot get information for apcupsd server."
31 elif [ $(apcupsd_get $apcupsd_ip $apcupsd_port | awk '/^STATUS.*/{ print $3 }') != "ONLINE" ]
33 echo >&2 "apcupsd: ERROR: UPS not online."
43 CHART apcupsd.charge '' "UPS Charge" "percentage" ups apcupsd.charge area $((apcupsd_priority + 1)) $apcupsd_update_every
44 DIMENSION battery_charge charge absolute 1 100
46 CHART apcupsd.battery_voltage '' "UPS Battery Voltage" "Volts" ups apcupsd.battery.voltage line $((apcupsd_priority + 3)) $apcupsd_update_every
47 DIMENSION battery_voltage voltage absolute 1 100
48 DIMENSION battery_voltage_nominal nominal absolute 1 100
50 CHART apcupsd.input_voltage '' "UPS Input Voltage" "Volts" input apcupsd.input.voltage line $((apcupsd_priority + 4)) $apcupsd_update_every
51 DIMENSION input_voltage voltage absolute 1 100
52 DIMENSION input_voltage_min min absolute 1 100
53 DIMENSION input_voltage_max max absolute 1 100
55 CHART apcupsd.input_frequency '' "UPS Input Frequency" "Hz" input apcupsd.input.frequency line $((apcupsd_priority + 5)) $apcupsd_update_every
56 DIMENSION input_frequency frequency absolute 1 100
58 CHART apcupsd.output_voltage '' "UPS Output Voltage" "Volts" output apcupsd.output.voltage line $((apcupsd_priority + 6)) $apcupsd_update_every
59 DIMENSION output_voltage voltage absolute 1 100
60 DIMENSION output_voltage_nominal nominal absolute 1 100
62 CHART apcupsd.load '' "UPS Load" "percentage" ups apcupsd.load area $((apcupsd_priority)) $apcupsd_update_every
63 DIMENSION load load absolute 1 100
65 CHART apcupsd.temp '' "UPS Temperature" "Celcius" ups apcupsd.temperature line $((apcupsd_priority + 7)) $apcupsd_update_every
66 DIMENSION temp temp absolute 1 100
68 CHART apcupsd.time '' "UPS Time Remaining" "Minutes" ups apcupsd.time area $((apcupsd_priority + 2)) $apcupsd_update_every
69 DIMENSION time time absolute 1 100
77 # the first argument to this function is the microseconds since last update
78 # pass this parameter to the BEGIN statement (see bellow).
80 # do all the work to collect / calculate the values
82 # remember: KEEP IT SIMPLE AND SHORT
84 apcupsd_get $apcupsd_ip $apcupsd_port | awk "
89 battery_voltage_nominal = 0;
91 input_voltage_min = 0;
92 input_voltage_max = 0;
95 output_voltage_nominal = 0;
100 /^BCHARGE.*/ { battery_charge = \$3 * 100 };
101 /^BATTV.*/ { battery_voltage = \$3 * 100 };
102 /^NOMBATTV.*/ { battery_voltage_nominal = \$3 * 100 };
103 /^LINEV.*/ { input_voltage = \$3 * 100 };
104 /^MINLINEV.*/ { input_voltage_min = \$3 * 100 };
105 /^MAXLINEV.*/ { input_voltage_max = \$3 * 100 };
106 /^LINEFREQ.*/ { input_frequency = \$3 * 100 };
107 /^OUTPUTV.*/ { output_voltage = \$3 * 100 };
108 /^NOMOUTV.*/ { output_voltage_nominal = \$3 * 100 };
109 /^LOADPCT.*/ { load = \$3 * 100 };
110 /^ITEMP.*/ { temp = \$3 * 100 };
111 /^TIMELEFT.*/ { time = \$3 * 100 };
113 print \"BEGIN apcupsd.charge $1\";
114 print \"SET battery_charge = \" battery_charge;
117 print \"BEGIN apcupsd.battery_voltage $1\";
118 print \"SET battery_voltage = \" battery_voltage;
119 print \"SET battery_voltage_nominal = \" battery_voltage_nominal;
122 print \"BEGIN apcupsd.input_voltage $1\";
123 print \"SET input_voltage = \" input_voltage;
124 print \"SET input_voltage_min = \" input_voltage_min;
125 print \"SET input_voltage_max = \" input_voltage_max;
128 print \"BEGIN apcupsd.input_frequency $1\";
129 print \"SET input_frequency = \" input_frequency;
132 print \"BEGIN apcupsd.output_voltage $1\";
133 print \"SET output_voltage = \" output_voltage;
134 print \"SET output_voltage_nominal = \" output_voltage_nominal;
137 print \"BEGIN apcupsd.load $1\";
138 print \"SET load = \" load;
141 print \"BEGIN apcupsd.temp $1\";
142 print \"SET temp = \" temp;
145 print \"BEGIN apcupsd.time $1\";
146 print \"SET time = \" time;
149 [ $? -ne 0 ] && echo >&2 "apcupsd: failed to get values" && return 1