module("luci.controller.luci_statistics.luci_statistics", package.seeall)
-local fs = require("luci.fs")
-local i18n = require("luci.i18n")
-local tpl = require("luci.template")
-local rrd = require("luci.statistics.rrdtool")
-local data = require("luci.statistics.datatree").Instance()
+require("luci.fs")
+require("luci.i18n")
+require("luci.template")
+
function index()
- -- XXX: fixme
- i18n.load("statistics.en")
+ require("luci.i18n")
+ require("luci.statistics.datatree")
+
+ -- load language file
+ luci.i18n.load("statistics.en")
+ -- get rrd data tree
+ local tree = luci.statistics.datatree.Instance()
+
+ -- override entry(): check for existance <plugin>.so where <plugin> is derived from the called path
function _entry( path, ... )
local file = path[4] or path[3]
- if fs.isfile( "/usr/lib/collectd/" .. file .. ".so" ) then
+ if luci.fs.isfile( "/usr/lib/collectd/" .. file .. ".so" ) then
entry( path, ... )
end
end
+ -- override call(): call requested action function with supplied parameters
+ function _call( func, tree, plugin )
+ return function() getfenv()[func]( tree, plugin ) end
+ end
+
+ -- override i18n(): try to translate stat_<str> or fall back to <str>
function _i18n( str )
- return i18n.translate( "stat_" .. str, str )
+ return luci.i18n.translate( "stat_" .. str, str )
end
+
entry({"admin", "statistics"}, call("statistics_index"), "Statistiken", 80)
entry({"admin", "statistics", "collectd"}, cbi("luci_statistics/collectd"), "Collectd", 10)
-- public views
- entry({"freifunk", "statistics"}, call("statistics_index"), "Statistiken", 80).i18n = "statistics"
-
- for i, plugin in ipairs( data:plugins() ) do
+ entry({"freifunk", "statistics"}, call("statistics_index"), "Statistiken", 80).i18n = "statistics"
+
+ for i, plugin in ipairs( tree:plugins() ) do
-- get plugin instances
- local instances = data:plugin_instances( plugin )
+ local instances = tree:plugin_instances( plugin )
-- plugin menu entry
_entry( { "freifunk", "statistics", plugin }, call("statistics_render"), _i18n( plugin ), i )
if #instances > 1 then
for j, inst in ipairs(instances) do
-- instance menu entry
- entry( { "freifunk", "statistics", plugin, inst }, call("statistics_render"), inst, j )
+ entry(
+ { "freifunk", "statistics", plugin, inst },
+ call("statistics_render"), inst, j
+ )
end
end
end
function statistics_index()
- tpl.render("admin_statistics/index")
+ luci.template.render("admin_statistics/index")
end
function statistics_outputplugins()
csv="CSV"
}
- tpl.render("admin_statistics/outputplugins", {plugins=plugins})
+ luci.template.render("admin_statistics/outputplugins", {plugins=plugins})
end
function statistics_systemplugins()
processes="Prozesse"
}
- tpl.render("admin_statistics/systemplugins", {plugins=plugins})
+ luci.template.render("admin_statistics/systemplugins", {plugins=plugins})
end
function statistics_networkplugins()
dns="DNS"
}
- tpl.render("admin_statistics/networkplugins", {plugins=plugins})
+ luci.template.render("admin_statistics/networkplugins", {plugins=plugins})
end
-function statistics_render()
- local plugin = luci.dispatcher.request[3]
- local instances = { luci.dispatcher.request[4] }
+function statistics_render( tree )
+
+ require("luci.statistics.rrdtool")
+ require("luci.template")
+
+ local req = luci.dispatcher.request
+ local graph = luci.statistics.rrdtool.Graph()
+
+ local plugin = req[3]
+ local instances = { req[4] }
local images = { }
-- no instance requested, find all instances
if #instances == 0 then
- instances = data:plugin_instances( plugin )
+ instances = graph.tree:plugin_instances( plugin )
-- more than one available instance
if #instances > 1 then
-- redirect to first instance and return
local r = luci.dispatcher.request
+ local i = instances[1]
+ if i:len() == 0 then i = "-" end
- luci.http.redirect( luci.dispatcher.build_url(
- r[1], r[2], r[3], instances[1]
- ) )
+ luci.http.redirect( luci.dispatcher.build_url(
+ req[1], req[2], req[3], i
+ ) )
return
end
+
+ -- index instance requested
+ elseif instances[1] == "-" then
+ instances[1] = ""
end
+
-- render graphs
for i, inst in ipairs( instances ) do
- local graph = rrd.Graph()
for i, img in ipairs( graph:render( plugin, inst ) ) do
table.insert( images, img )
end
end
- tpl.render("public_statistics/graph", { images=images, plugin=plugin } )
+ luci.template.render("public_statistics/graph", { images=images, plugin=plugin } )
end
stat_wireless = "Wireless"
stat_tcpconns = "TCP Connections"
stat_interface = "Interfaces"
+stat_df = "Disk Space Usage"
-- diagrams
stat_dg_title_wireless__signal_noise = "%H: Wireless - Signal Noise Ratio"
stat_dg_label_processes = "Processes/s"
stat_ds_ps_state = "%di"
+stat_dg_title_processes__ps_cputime = "%H: Process %pi - used cpu time"
+stat_dg_label_processes__ps_cputime = "Jiffies"
+stat_ds_ps_cputime__syst = "system"
+stat_ds_ps_cputime__user = "user"
+
+stat_dg_title_processes__ps_count = "%H: Process %pi - threads and processes"
+stat_dg_label_processes__ps_count = "Count"
+stat_ds_ps_count = "%ds"
+
+stat_dg_title_processes__ps_pagefaults = "%H: Process %pi - page faults"
+stat_dg_label_processes__ps_pagefaults = "Pagefaults"
+stat_ds_ps_pagefaults = "page faults"
+
+stat_dg_title_processes__ps_rss = "%H: Process %pi - virtual memory size"
+stat_dg_label_processes__ps_rss = "Bytes"
+stat_ds_ps_rss = "virtual memory"
+
stat_dg_title_cpu = "%H: Usage on Processor #%pi"
stat_dg_label_cpu = "%"
stat_ds_cpu = "%di"
stat_dg_title_tcpconns = "%H: TCP-Connections to Port %pi"
stat_dg_label_tcpconns = "Connections/s"
stat_ds_tcp_connections = "%di"
+
+stat_dg_title_df = "%H: Disk Space Usage on %di"
+stat_dg_label_df = "Bytes"
+stat_ds_df__free = "%ds"
+stat_ds_df__used = "%ds"
+
--- /dev/null
+module("luci.statistics.rrdtool.definitions.processes", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance )
+
+ if plugin_instance == "" then
+ return {
+ data = {
+ instances = {
+ ps_state = {
+ "sleeping", "running", "paging", "blocked", "stopped", "zombies"
+ }
+ },
+
+ options = {
+ ps_state_sleeping = { color = "0000ff" },
+ ps_state_running = { color = "008000" },
+ ps_state_paging = { color = "ffff00" },
+ ps_state_blocked = { color = "ff5000" },
+ ps_state_stopped = { color = "555555" },
+ ps_state_zombies = { color = "ff0000" }
+ }
+ }
+ }
+ else
+ return {
+
+ {
+ data = {
+ sources = {
+ ps_cputime = { "syst", "user" }
+ },
+
+ options = {
+ ps_cputime__user = {
+ color = "0000ff",
+ overlay = true
+ },
+
+ ps_cputime__syst = {
+ color = "ff0000",
+ overlay = true
+ }
+ }
+ }
+ },
+
+ {
+ data = {
+ sources = {
+ ps_count = { "threads", "processes" }
+ },
+
+ options = {
+ ps_count__threads = { color = "00ff00" },
+ ps_count__processes = { color = "0000bb" }
+ }
+ }
+ },
+
+ {
+ data = {
+ sources = {
+ ps_pagefaults = { "minflt", "majflt" }
+ },
+
+ options = {
+ ps_pagefaults__minflt = { color = "ff0000" },
+ ps_pagefaults__majflt = { color = "ff5500" }
+ }
+ }
+ },
+
+ {
+ number_format = "%5.1lf%s",
+
+ data = {
+ types = { "ps_rss" },
+
+ options = {
+ ps_rss = { color = "0000ff" }
+ }
+ }
+ }
+ }
+ end
+end