]> arthur.barton.de Git - netdata.git/blob - charts.d/apcupsd.chart.sh
better log management for charts.d.plugin - fixes #1144
[netdata.git] / charts.d / apcupsd.chart.sh
1 # no need for shebang - this file is loaded from charts.d.plugin
2
3 apcupsd_ip=127.0.0.1
4 apcupsd_port=3551
5
6 # how frequently to collect UPS data
7 apcupsd_update_every=10
8
9 apcupsd_timeout=3
10
11 # the priority of apcupsd related to other charts
12 apcupsd_priority=90000
13
14 apcupsd_get() {
15         run -t $apcupsd_timeout apcaccess status "$1:$2"
16 }
17
18 apcupsd_check() {
19
20         # this should return:
21         #  - 0 to enable the chart
22         #  - 1 to disable the chart
23
24         require_cmd apcaccess || return 1
25
26         run apcupsd_get $apcupsd_ip $apcupsd_port >/dev/null
27         if [ $? -ne 0 ]
28                 then
29                 error "cannot get information for apcupsd server."
30                 return 1
31         elif [ $(apcupsd_get $apcupsd_ip $apcupsd_port | awk '/^STATUS.*/{ print $3 }') != "ONLINE" ]
32                 then
33                 error "APC UPS not online."
34                 return 1
35         fi
36
37         return 0
38 }
39
40 apcupsd_create() {
41         # create the charts
42         cat <<EOF
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
45
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
49
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
54
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
57
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
61
62 CHART apcupsd.load '' "UPS Load" "percentage" ups apcupsd.load area $((apcupsd_priority)) $apcupsd_update_every
63 DIMENSION load load absolute 1 100
64
65 CHART apcupsd.temp '' "UPS Temperature" "Celcius" ups apcupsd.temperature line $((apcupsd_priority + 7)) $apcupsd_update_every
66 DIMENSION temp temp absolute 1 100
67
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
70
71 EOF
72         return 0
73 }
74
75
76 apcupsd_update() {
77         # the first argument to this function is the microseconds since last update
78         # pass this parameter to the BEGIN statement (see bellow).
79
80         # do all the work to collect / calculate the values
81         # for each dimension
82         # remember: KEEP IT SIMPLE AND SHORT
83
84         apcupsd_get $apcupsd_ip $apcupsd_port | awk "
85
86 BEGIN {
87         battery_charge = 0;
88         battery_voltage = 0;
89         battery_voltage_nominal = 0;
90         input_voltage = 0;
91         input_voltage_min = 0;
92         input_voltage_max = 0;
93         input_frequency = 0;
94         output_voltage = 0;
95         output_voltage_nominal = 0;
96         load = 0;
97         temp = 0;
98         time = 0;
99 }
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 };
112 END {
113         print \"BEGIN apcupsd.charge $1\";
114         print \"SET battery_charge = \" battery_charge;
115         print \"END\"
116
117         print \"BEGIN apcupsd.battery_voltage $1\";
118         print \"SET battery_voltage = \" battery_voltage;
119         print \"SET battery_voltage_nominal = \" battery_voltage_nominal;
120         print \"END\"
121
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;
126         print \"END\"
127
128         print \"BEGIN apcupsd.input_frequency $1\";
129         print \"SET input_frequency = \" input_frequency;
130         print \"END\"
131
132         print \"BEGIN apcupsd.output_voltage $1\";
133         print \"SET output_voltage = \" output_voltage;
134         print \"SET output_voltage_nominal = \" output_voltage_nominal;
135         print \"END\"
136
137         print \"BEGIN apcupsd.load $1\";
138         print \"SET load = \" load;
139         print \"END\"
140
141         print \"BEGIN apcupsd.temp $1\";
142         print \"SET temp = \" temp;
143         print \"END\"
144
145         print \"BEGIN apcupsd.time $1\";
146         print \"SET time = \" time;
147         print \"END\"
148 }"
149         [ $? -ne 0 ] && error "failed to get values" && return 1
150
151         return 0
152 }