50de3a6b03a0e5afa45d37e9c23d8b8821262b15
[project/luci.git] /
1 /* Licensed to the public under the Apache License 2.0. */
2
3 'use strict';
4
5 return L.Class.extend({
6 title: _('APC UPS'),
7
8 rrdargs: function(graph, host, plugin, plugin_instance, dtype) {
9 var rv = [];
10
11 /*
12 * Types and instances supported by APC UPS
13 * e.g. ups_types -> [ 'timeleft', 'charge', 'percent', 'voltage' ]
14 * e.g. ups_inst['voltage'] -> [ 'input', 'battery' ]
15 */
16
17 var ups_types = graph.dataTypes(host, plugin, plugin_instance),
18 ups_inst = {};
19
20 for (var i = 0; i < ups_types.length; i++)
21 ups_inst[ups_types[i]] = graph.dataInstances(host, plugin, plugin_instance, ups_types[i]);
22
23 /* Check if hash table or array is empty or nil-filled */
24 function empty(t) {
25 for (var k in t)
26 if (t[k] != null)
27 return false;
28
29 return true;
30 }
31
32 /* Append graph definition but only types/instances which are */
33 /* supported and available to the plugin and UPS. */
34
35 function add_supported(t, defs) {
36 var def_inst = defs['data']['instances'];
37
38 if (L.isObject(def_inst)) {
39 for (var k in def_inst) {
40 if (ups_types.filter(function(t) { return t == k }).length) {
41 for (var i = def_inst[k].length - 1; i >= 0; i--)
42 if (!ups_inst[k].filter(function(n) { return n == def_inst[k][i] }).length)
43 def_inst[k].splice(i, 1);
44
45 if (def_inst[k].length == 0)
46 def_inst[k] = null; /* can't assign v: immutable */
47 }
48 else {
49 def_inst[k] = null; /* can't assign v: immutable */
50 }
51 }
52
53 if (empty(def_inst))
54 return;
55 }
56
57 t.push(defs);
58 }
59
60
61 /* Graph definitions for APC UPS measurements MUST use only 'instances': */
62 /* e.g. instances = { voltage = { "input", "output" } } */
63
64 var voltagesdc = {
65 title: "%H: Voltages on APC UPS - Battery",
66 vlabel: "Volts DC",
67 alt_autoscale: true,
68 number_format: "%5.1lfV",
69 data: {
70 instances: {
71 voltage: [ "battery" ]
72 },
73 options: {
74 voltage: { title: "Battery voltage", noarea: true }
75 }
76 }
77 };
78 add_supported(rv, voltagesdc);
79
80 var voltagesac = {
81 title: "%H: Voltages on APC UPS - AC",
82 vlabel: "Volts AC",
83 alt_autoscale: true,
84 number_format: "%5.1lfV",
85 data: {
86 instances: {
87 voltage: [ "input", "output" ]
88 },
89 options: {
90 voltage_output : { color: "00e000", title: "Output voltage", noarea: true, overlay: true },
91 voltage_input : { color: "ffb000", title: "Input voltage", noarea: true, overlay: true }
92 }
93 }
94 };
95 add_supported(rv, voltagesac);
96
97 var percentload = {
98 title: "%H: Load on APC UPS ",
99 vlabel: "Percent",
100 y_min: "0",
101 y_max: "100",
102 number_format: "%5.1lf%%",
103 data: {
104 instances: {
105 percent: [ "load" ]
106 },
107 options: {
108 percent_load: { color: "00ff00", title: "Load level" }
109 }
110 }
111 };
112 add_supported(rv, percentload);
113
114 var charge_percent = {
115 title: "%H: Battery charge on APC UPS ",
116 vlabel: "Percent",
117 y_min: "0",
118 y_max: "100",
119 number_format: "%5.1lf%%",
120 data: {
121 instances: {
122 charge: [ "" ]
123 },
124 options: {
125 charge: { color: "00ff0b", title: "Charge level" }
126 }
127 }
128 };
129 add_supported(rv, charge_percent);
130
131 var temperature = {
132 title: "%H: Battery temperature on APC UPS ",
133 vlabel: "\u00b0C",
134 number_format: "%5.1lf\u00b0C",
135 data: {
136 instances: {
137 temperature: [ "" ]
138 },
139 options: {
140 temperature: { color: "ffb000", title: "Battery temperature" } }
141 }
142 };
143 add_supported(rv, temperature);
144
145 var timeleft = {
146 title: "%H: Time left on APC UPS ",
147 vlabel: "Minutes",
148 number_format: "%.1lfm",
149 data: {
150 instances: {
151 timeleft: [ "" ]
152 },
153 options: {
154 timeleft: { color: "0000ff", title: "Time left" }
155 }
156 }
157 };
158 add_supported(rv, timeleft);
159
160 var frequency = {
161 title: "%H: Incoming line frequency on APC UPS ",
162 vlabel: "Hz",
163 number_format: "%5.0lfhz",
164 data: {
165 instances: {
166 frequency: [ "input" ]
167 },
168 options: {
169 frequency_input: { color: "000fff", title: "Line frequency" }
170 }
171 }
172 };
173 add_supported(rv, frequency);
174
175 return rv;
176 }
177 });