]> arthur.barton.de Git - netdata.git/blob - charts.d/apcupsd.chart.sh
Merge pull request #2021 from ktsaou/master
[netdata.git] / charts.d / apcupsd.chart.sh
1 # no need for shebang - this file is loaded from charts.d.plugin
2
3 # netdata
4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6 # GPL v3+
7 #
8
9 apcupsd_ip=127.0.0.1
10 apcupsd_port=3551
11
12 # how frequently to collect UPS data
13 apcupsd_update_every=10
14
15 apcupsd_timeout=3
16
17 # the priority of apcupsd related to other charts
18 apcupsd_priority=90000
19
20 apcupsd_get() {
21         run -t $apcupsd_timeout apcaccess status "$1:$2"
22 }
23
24 apcupsd_check() {
25
26         # this should return:
27         #  - 0 to enable the chart
28         #  - 1 to disable the chart
29
30         require_cmd apcaccess || return 1
31
32         run apcupsd_get $apcupsd_ip $apcupsd_port >/dev/null
33         if [ $? -ne 0 ]
34                 then
35                 error "cannot get information for apcupsd server."
36                 return 1
37         elif [ $(apcupsd_get $apcupsd_ip $apcupsd_port | awk '/^STATUS.*/{ print $3 }') != "ONLINE" ]
38                 then
39                 error "APC UPS not online."
40                 return 1
41         fi
42
43         return 0
44 }
45
46 apcupsd_create() {
47         # create the charts
48         cat <<EOF
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
51
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
55
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
60
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
63
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
67
68 CHART apcupsd.load '' "UPS Load" "percentage" ups apcupsd.load area $((apcupsd_priority)) $apcupsd_update_every
69 DIMENSION load load absolute 1 100
70
71 CHART apcupsd.temp '' "UPS Temperature" "Celsius" ups apcupsd.temperature line $((apcupsd_priority + 7)) $apcupsd_update_every
72 DIMENSION temp temp absolute 1 100
73
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
76
77 EOF
78         return 0
79 }
80
81
82 apcupsd_update() {
83         # the first argument to this function is the microseconds since last update
84         # pass this parameter to the BEGIN statement (see bellow).
85
86         # do all the work to collect / calculate the values
87         # for each dimension
88         # remember: KEEP IT SIMPLE AND SHORT
89
90         apcupsd_get $apcupsd_ip $apcupsd_port | awk "
91
92 BEGIN {
93         battery_charge = 0;
94         battery_voltage = 0;
95         battery_voltage_nominal = 0;
96         input_voltage = 0;
97         input_voltage_min = 0;
98         input_voltage_max = 0;
99         input_frequency = 0;
100         output_voltage = 0;
101         output_voltage_nominal = 0;
102         load = 0;
103         temp = 0;
104         time = 0;
105 }
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 };
118 END {
119         print \"BEGIN apcupsd.charge $1\";
120         print \"SET battery_charge = \" battery_charge;
121         print \"END\"
122
123         print \"BEGIN apcupsd.battery_voltage $1\";
124         print \"SET battery_voltage = \" battery_voltage;
125         print \"SET battery_voltage_nominal = \" battery_voltage_nominal;
126         print \"END\"
127
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;
132         print \"END\"
133
134         print \"BEGIN apcupsd.input_frequency $1\";
135         print \"SET input_frequency = \" input_frequency;
136         print \"END\"
137
138         print \"BEGIN apcupsd.output_voltage $1\";
139         print \"SET output_voltage = \" output_voltage;
140         print \"SET output_voltage_nominal = \" output_voltage_nominal;
141         print \"END\"
142
143         print \"BEGIN apcupsd.load $1\";
144         print \"SET load = \" load;
145         print \"END\"
146
147         print \"BEGIN apcupsd.temp $1\";
148         print \"SET temp = \" temp;
149         print \"END\"
150
151         print \"BEGIN apcupsd.time $1\";
152         print \"SET time = \" time;
153         print \"END\"
154 }"
155         [ $? -ne 0 ] && error "failed to get values" && return 1
156
157         return 0
158 }