1 # no need for shebang - this file is loaded from charts.d.plugin
4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
12 # how frequently to collect UPS data
13 apcupsd_update_every=10
17 # the priority of apcupsd related to other charts
18 apcupsd_priority=90000
21 run -t $apcupsd_timeout apcaccess status "$1:$2"
27 # - 0 to enable the chart
28 # - 1 to disable the chart
30 require_cmd apcaccess || return 1
32 run apcupsd_get $apcupsd_ip $apcupsd_port >/dev/null
35 error "cannot get information for apcupsd server."
37 elif [ $(apcupsd_get $apcupsd_ip $apcupsd_port | awk '/^STATUS.*/{ print $3 }') != "ONLINE" ]
39 error "APC UPS not online."
49 CHART apcupsd.charge '' "UPS Charge" "percentage" ups apcupsd.charge area $((apcupsd_priority + 1)) $apcupsd_update_every
50 DIMENSION battery_charge charge absolute 1 100
52 CHART apcupsd.battery_voltage '' "UPS Battery Voltage" "Volts" ups apcupsd.battery.voltage line $((apcupsd_priority + 3)) $apcupsd_update_every
53 DIMENSION battery_voltage voltage absolute 1 100
54 DIMENSION battery_voltage_nominal nominal absolute 1 100
56 CHART apcupsd.input_voltage '' "UPS Input Voltage" "Volts" input apcupsd.input.voltage line $((apcupsd_priority + 4)) $apcupsd_update_every
57 DIMENSION input_voltage voltage absolute 1 100
58 DIMENSION input_voltage_min min absolute 1 100
59 DIMENSION input_voltage_max max absolute 1 100
61 CHART apcupsd.input_frequency '' "UPS Input Frequency" "Hz" input apcupsd.input.frequency line $((apcupsd_priority + 5)) $apcupsd_update_every
62 DIMENSION input_frequency frequency absolute 1 100
64 CHART apcupsd.output_voltage '' "UPS Output Voltage" "Volts" output apcupsd.output.voltage line $((apcupsd_priority + 6)) $apcupsd_update_every
65 DIMENSION output_voltage voltage absolute 1 100
66 DIMENSION output_voltage_nominal nominal absolute 1 100
68 CHART apcupsd.load '' "UPS Load" "percentage" ups apcupsd.load area $((apcupsd_priority)) $apcupsd_update_every
69 DIMENSION load load absolute 1 100
71 CHART apcupsd.temp '' "UPS Temperature" "Celsius" ups apcupsd.temperature line $((apcupsd_priority + 7)) $apcupsd_update_every
72 DIMENSION temp temp absolute 1 100
74 CHART apcupsd.time '' "UPS Time Remaining" "Minutes" ups apcupsd.time area $((apcupsd_priority + 2)) $apcupsd_update_every
75 DIMENSION time time absolute 1 100
83 # the first argument to this function is the microseconds since last update
84 # pass this parameter to the BEGIN statement (see bellow).
86 # do all the work to collect / calculate the values
88 # remember: KEEP IT SIMPLE AND SHORT
90 apcupsd_get $apcupsd_ip $apcupsd_port | awk "
95 battery_voltage_nominal = 0;
97 input_voltage_min = 0;
98 input_voltage_max = 0;
101 output_voltage_nominal = 0;
106 /^BCHARGE.*/ { battery_charge = \$3 * 100 };
107 /^BATTV.*/ { battery_voltage = \$3 * 100 };
108 /^NOMBATTV.*/ { battery_voltage_nominal = \$3 * 100 };
109 /^LINEV.*/ { input_voltage = \$3 * 100 };
110 /^MINLINEV.*/ { input_voltage_min = \$3 * 100 };
111 /^MAXLINEV.*/ { input_voltage_max = \$3 * 100 };
112 /^LINEFREQ.*/ { input_frequency = \$3 * 100 };
113 /^OUTPUTV.*/ { output_voltage = \$3 * 100 };
114 /^NOMOUTV.*/ { output_voltage_nominal = \$3 * 100 };
115 /^LOADPCT.*/ { load = \$3 * 100 };
116 /^ITEMP.*/ { temp = \$3 * 100 };
117 /^TIMELEFT.*/ { time = \$3 * 100 };
119 print \"BEGIN apcupsd.charge $1\";
120 print \"SET battery_charge = \" battery_charge;
123 print \"BEGIN apcupsd.battery_voltage $1\";
124 print \"SET battery_voltage = \" battery_voltage;
125 print \"SET battery_voltage_nominal = \" battery_voltage_nominal;
128 print \"BEGIN apcupsd.input_voltage $1\";
129 print \"SET input_voltage = \" input_voltage;
130 print \"SET input_voltage_min = \" input_voltage_min;
131 print \"SET input_voltage_max = \" input_voltage_max;
134 print \"BEGIN apcupsd.input_frequency $1\";
135 print \"SET input_frequency = \" input_frequency;
138 print \"BEGIN apcupsd.output_voltage $1\";
139 print \"SET output_voltage = \" output_voltage;
140 print \"SET output_voltage_nominal = \" output_voltage_nominal;
143 print \"BEGIN apcupsd.load $1\";
144 print \"SET load = \" load;
147 print \"BEGIN apcupsd.temp $1\";
148 print \"SET temp = \" temp;
151 print \"BEGIN apcupsd.time $1\";
152 print \"SET time = \" time;
155 [ $? -ne 0 ] && error "failed to get values" && return 1