1 -- Copyright 2015 Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
4 module("luci.statistics.rrdtool.definitions.apcups",package.seeall)
6 function rrdargs( graph, plugin, plugin_instance )
8 local lu = require("luci.util")
11 -- Types and instances supported by APC UPS
12 -- e.g. ups_types -> { 'timeleft', 'charge', 'percent', 'voltage' }
13 -- e.g. ups_inst['voltage'] -> { 'input', 'battery' }
15 local ups_types = graph.tree:data_types( plugin, plugin_instance )
18 for _, t in ipairs(ups_types) do
19 ups_inst[t] = graph.tree:data_instances( plugin, plugin_instance, t )
23 -- Check if hash table or array is empty or nil-filled
25 local function empty( t )
26 for _, v in pairs(t) do
27 if type(v) then return false end
33 -- Append graph definition but only types/instances which are
34 -- supported and available to the plugin and UPS.
36 local function add_supported( t, defs )
37 local def_inst = defs['data']['instances']
39 if type(def_inst) == "table" then
40 for k, v in pairs( def_inst ) do
41 if lu.contains( ups_types, k) then
43 if not lu.contains( ups_inst[k], v[j] ) then
48 def_inst[k] = nil -- can't assign v: immutable
51 def_inst[k] = nil -- can't assign v: immutable
54 if empty(def_inst) then return end
56 table.insert( t, defs )
60 -- Graph definitions for APC UPS measurements MUST use only 'instances':
61 -- e.g. instances = { voltage = { "input", "output" } }
64 title = "%H: Voltages on APC UPS - Battery",
67 number_format = "%5.1lfV",
70 voltage = { "battery" }
73 voltage = { title = "Battery voltage", noarea=true }
77 add_supported( rv, voltagesdc )
80 title = "%H: Voltages on APC UPS - AC",
83 number_format = "%5.1lfV",
86 voltage = { "input", "output" }
89 voltage_output = { color = "00e000", title = "Output voltage", noarea=true, overlay=true },
90 voltage_input = { color = "ffb000", title = "Input voltage", noarea=true, overlay=true }
94 add_supported( rv, voltagesac )
97 title = "%H: Load on APC UPS ",
101 number_format = "%5.1lf%%",
107 percent_load = { color = "00ff00", title = "Load level" }
111 add_supported( rv, percentload )
113 local charge_percent = {
114 title = "%H: Battery charge on APC UPS ",
118 number_format = "%5.1lf%%",
124 charge = { color = "00ff0b", title = "Charge level" }
128 add_supported( rv, charge_percent )
130 local temperature = {
131 title = "%H: Battery temperature on APC UPS ",
133 number_format = "%5.1lf\176C",
139 temperature = { color = "ffb000", title = "Battery temperature" } }
142 add_supported( rv, temperature )
145 title = "%H: Time left on APC UPS ",
147 number_format = "%.1lfm",
153 timeleft = { color = "0000ff", title = "Time left" }
157 add_supported( rv, timeleft )
160 title = "%H: Incoming line frequency on APC UPS ",
162 number_format = "%5.0lfhz",
165 frequency = { "input" }
168 frequency_input = { color = "000fff", title = "Line frequency" }
172 add_supported( rv, frequency )