1 module("luci.controller.luci_statistics.luci_statistics", package.seeall)
5 require("luci.template")
11 require("luci.statistics.datatree")
14 luci.i18n.load("statistics.en")
17 local tree = luci.statistics.datatree.Instance()
19 -- override entry(): check for existance <plugin>.so where <plugin> is derived from the called path
20 function _entry( path, ... )
21 local file = path[4] or path[3]
22 if luci.fs.isfile( "/usr/lib/collectd/" .. file .. ".so" ) then
27 -- override call(): call requested action function with supplied parameters
28 function _call( func, tree, plugin )
29 return function() getfenv()[func]( tree, plugin ) end
32 -- override i18n(): try to translate stat_<str> or fall back to <str>
34 return luci.i18n.translate( "stat_" .. str, str )
38 entry({"admin", "statistics"}, call("statistics_index"), "Statistiken", 80)
39 entry({"admin", "statistics", "collectd"}, cbi("luci_statistics/collectd"), "Collectd", 10)
41 entry({"admin", "statistics", "output"}, call("statistics_outputplugins"), "Ausgabeplugins", 20)
42 _entry({"admin", "statistics", "output", "rrdtool"}, cbi("luci_statistics/rrdtool"), "RRDTool", 10)
43 _entry({"admin", "statistics", "output", "network"}, cbi("luci_statistics/network"), "Netzwerk", 20)
44 _entry({"admin", "statistics", "output", "unixsock"}, cbi("luci_statistics/unixsock"), "Unix Socket", 30)
45 _entry({"admin", "statistics", "output", "csv"}, cbi("luci_statistics/csv"), "CSV", 40)
47 entry({"admin", "statistics", "system"}, call("statistics_systemplugins"), "Systemplugins", 30)
48 _entry({"admin", "statistics", "system", "exec"}, cbi("luci_statistics/exec"), "Exec", 10)
49 _entry({"admin", "statistics", "system", "email"}, cbi("luci_statistics/email"), "E-Mail", 20)
50 _entry({"admin", "statistics", "system", "cpu"}, cbi("luci_statistics/cpu"), "Prozessor", 30)
51 _entry({"admin", "statistics", "system", "df"}, cbi("luci_statistics/df"), "Speicherplatz", 40)
52 _entry({"admin", "statistics", "system", "disk"}, cbi("luci_statistics/disk"), "Datenträger", 50)
53 _entry({"admin", "statistics", "system", "irq"}, cbi("luci_statistics/irq"), "Interrupts", 60)
54 _entry({"admin", "statistics", "system", "processes"}, cbi("luci_statistics/processes"), "Prozesse", 70)
56 entry({"admin", "statistics", "network"}, call("statistics_networkplugins"), "Netzwerkplugins", 40)
57 _entry({"admin", "statistics", "network", "interface"}, cbi("luci_statistics/interface"), "Schnittstellen", 10)
58 _entry({"admin", "statistics", "network", "netlink"}, cbi("luci_statistics/netlink"), "Netlink", 20)
59 _entry({"admin", "statistics", "network", "iptables"}, cbi("luci_statistics/iptables"), "Firewall", 30)
60 _entry({"admin", "statistics", "network", "tcpconns"}, cbi("luci_statistics/tcpconns"), "Verbindungen", 40)
61 _entry({"admin", "statistics", "network", "ping"}, cbi("luci_statistics/ping"), "Ping", 50)
62 _entry({"admin", "statistics", "network", "dns"}, cbi("luci_statistics/dns"), "DNS", 60)
63 _entry({"admin", "statistics", "network", "wireless"}, cbi("luci_statistics/wireless"), "Drahtlos", 70)
67 entry({"freifunk", "statistics"}, call("statistics_index"), "Statistiken", 80).i18n = "statistics"
69 for i, plugin in ipairs( tree:plugins() ) do
71 -- get plugin instances
72 local instances = tree:plugin_instances( plugin )
75 _entry( { "freifunk", "statistics", plugin }, call("statistics_render"), _i18n( plugin ), i )
77 -- if more then one instance is found then generate submenu
78 if #instances > 1 then
79 for j, inst in ipairs(instances) do
80 -- instance menu entry
82 { "freifunk", "statistics", plugin, inst },
83 call("statistics_render"), inst, j
91 function statistics_index()
92 luci.template.render("admin_statistics/index")
95 function statistics_outputplugins()
99 unixsock="Unix Socket",
103 luci.template.render("admin_statistics/outputplugins", {plugins=plugins})
106 function statistics_systemplugins()
115 luci.template.render("admin_statistics/systemplugins", {plugins=plugins})
118 function statistics_networkplugins()
120 interface="Schnittstellen",
123 tcpconns="Verbindungen",
128 luci.template.render("admin_statistics/networkplugins", {plugins=plugins})
132 function statistics_render( tree )
134 require("luci.statistics.rrdtool")
135 require("luci.template")
137 local req = luci.dispatcher.request
138 local graph = luci.statistics.rrdtool.Graph()
140 local plugin = req[3]
141 local instances = { req[4] }
144 -- no instance requested, find all instances
145 if #instances == 0 then
147 instances = graph.tree:plugin_instances( plugin )
149 -- more than one available instance
150 if #instances > 1 then
152 -- redirect to first instance and return
153 local r = luci.dispatcher.request
154 local i = instances[1]
155 if i:len() == 0 then i = "-" end
157 luci.http.redirect( luci.dispatcher.build_url(
158 req[1], req[2], req[3], i
164 -- index instance requested
165 elseif instances[1] == "-" then
171 for i, inst in ipairs( instances ) do
172 for i, img in ipairs( graph:render( plugin, inst ) ) do
173 table.insert( images, graph:strippngpath( img ) )
177 luci.template.render("public_statistics/graph", { images=images, plugin=plugin } )