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