summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-statistics/luasrc
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2014-12-03 15:17:05 +0100
committerJo-Philipp Wich <jow@openwrt.org>2015-01-08 16:26:20 +0100
commit1bb4822dca6113f73e3bc89e2acf15935e6f8e92 (patch)
tree35e16f100466e4e00657199b38bb3d87d52bf73f /applications/luci-app-statistics/luasrc
parent9edd0e46c3f880727738ce8ca6ff1c8b85f99ef4 (diff)
Rework LuCI build system
* Rename subdirectories to their repective OpenWrt package names * Make each LuCI module its own standalone package * Deploy a shared luci.mk which is used by each module Makefile Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'applications/luci-app-statistics/luasrc')
-rw-r--r--applications/luci-app-statistics/luasrc/controller/luci_statistics/luci_statistics.lua209
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/collectd.lua74
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/conntrack.lua21
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/cpu.lua27
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/csv.lua41
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/df.lua53
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/disk.lua41
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/dns.lua48
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/email.lua60
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/exec.lua89
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/interface.lua47
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/iptables.lua132
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/irq.lua42
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/iwinfo.lua38
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/load.lua29
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/memory.lua21
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/netlink.lua95
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/network.lua98
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/nut.lua28
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/olsrd.lua54
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/ping.lua47
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/processes.lua36
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/rrdtool.lua108
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/splash_leases.lua24
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/tcpconns.lua45
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/unixsock.lua49
-rw-r--r--applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/uptime.lua22
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/datatree.lua209
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/i18n.lua108
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool.lua561
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/colors.lua73
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/conntrack.lua35
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua42
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/df.lua46
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/disk.lua74
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/dns.lua81
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/interface.lua117
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/iptables.lua53
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/irq.lua30
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/iwinfo.lua102
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/load.lua36
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/memory.lua33
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/netlink.lua203
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/nut.lua106
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/olsrd.lua146
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/ping.lua41
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/processes.lua110
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/splash_leases.lua37
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/tcpconns.lua37
-rw-r--r--applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/uptime.lua27
-rw-r--r--applications/luci-app-statistics/luasrc/view/admin_statistics/index.htm22
-rw-r--r--applications/luci-app-statistics/luasrc/view/public_statistics/graph.htm48
52 files changed, 3955 insertions, 0 deletions
diff --git a/applications/luci-app-statistics/luasrc/controller/luci_statistics/luci_statistics.lua b/applications/luci-app-statistics/luasrc/controller/luci_statistics/luci_statistics.lua
new file mode 100644
index 0000000000..5729bb186a
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/controller/luci_statistics/luci_statistics.lua
@@ -0,0 +1,209 @@
+--[[
+
+Luci statistics - statistics controller module
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+(c) 2012 Jo-Philipp Wich <xm@subsignal.org>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+]]--
+
+module("luci.controller.luci_statistics.luci_statistics", package.seeall)
+
+function index()
+
+ require("nixio.fs")
+ require("luci.util")
+ require("luci.statistics.datatree")
+
+ -- override entry(): check for existance <plugin>.so where <plugin> is derived from the called path
+ function _entry( path, ... )
+ local file = path[5] or path[4]
+ if nixio.fs.access( "/usr/lib/collectd/" .. file .. ".so" ) then
+ entry( path, ... )
+ end
+ end
+
+ local labels = {
+ s_output = _("Output plugins"),
+ s_system = _("System plugins"),
+ s_network = _("Network plugins"),
+
+ conntrack = _("Conntrack"),
+ cpu = _("Processor"),
+ csv = _("CSV Output"),
+ df = _("Disk Space Usage"),
+ disk = _("Disk Usage"),
+ dns = _("DNS"),
+ email = _("Email"),
+ exec = _("Exec"),
+ interface = _("Interfaces"),
+ iptables = _("Firewall"),
+ irq = _("Interrupts"),
+ iwinfo = _("Wireless"),
+ load = _("System Load"),
+ memory = _("Memory"),
+ netlink = _("Netlink"),
+ network = _("Network"),
+ nut = _("UPS"),
+ olsrd = _("OLSRd"),
+ ping = _("Ping"),
+ processes = _("Processes"),
+ rrdtool = _("RRDTool"),
+ splash_leases = _("Splash Leases"),
+ tcpconns = _("TCP Connections"),
+ unixsock = _("UnixSock"),
+ uptime = _("Uptime")
+ }
+
+ -- our collectd menu
+ local collectd_menu = {
+ output = { "csv", "network", "rrdtool", "unixsock" },
+ system = { "cpu", "df", "disk", "email", "exec", "irq", "load", "memory", "nut", "processes", "uptime" },
+ network = { "conntrack", "dns", "interface", "iptables", "netlink", "olsrd", "ping", "splash_leases", "tcpconns", "iwinfo" }
+ }
+
+ -- create toplevel menu nodes
+ local st = entry({"admin", "statistics"}, template("admin_statistics/index"), _("Statistics"), 80)
+ st.index = true
+
+ entry({"admin", "statistics", "collectd"}, cbi("luci_statistics/collectd"), _("Collectd"), 10).subindex = true
+
+
+ -- populate collectd plugin menu
+ local index = 1
+ for section, plugins in luci.util.kspairs( collectd_menu ) do
+ local e = entry(
+ { "admin", "statistics", "collectd", section },
+ firstchild(), labels["s_"..section], index * 10
+ )
+
+ e.index = true
+
+ for j, plugin in luci.util.vspairs( plugins ) do
+ _entry(
+ { "admin", "statistics", "collectd", section, plugin },
+ cbi("luci_statistics/" .. plugin ),
+ labels[plugin], j * 10
+ )
+ end
+
+ index = index + 1
+ end
+
+ -- output views
+ local page = entry( { "admin", "statistics", "graph" }, template("admin_statistics/index"), _("Graphs"), 80)
+ page.setuser = "nobody"
+ page.setgroup = "nogroup"
+
+ local vars = luci.http.formvalue(nil, true)
+ local span = vars.timespan or nil
+ local host = vars.host or nil
+
+ -- get rrd data tree
+ local tree = luci.statistics.datatree.Instance(host)
+
+ local _, plugin, idx
+ for _, plugin, idx in luci.util.vspairs( tree:plugins() ) do
+
+ -- get plugin instances
+ local instances = tree:plugin_instances( plugin )
+
+ -- plugin menu entry
+ entry(
+ { "admin", "statistics", "graph", plugin },
+ call("statistics_render"), labels[plugin], idx
+ ).query = { timespan = span , host = host }
+
+ -- if more then one instance is found then generate submenu
+ if #instances > 1 then
+ local _, inst, idx2
+ for _, inst, idx2 in luci.util.vspairs(instances) do
+ -- instance menu entry
+ entry(
+ { "admin", "statistics", "graph", plugin, inst },
+ call("statistics_render"), inst, idx2
+ ).query = { timespan = span , host = host }
+ end
+ end
+ end
+end
+
+function statistics_render()
+
+ require("luci.statistics.rrdtool")
+ require("luci.template")
+ require("luci.model.uci")
+
+ local vars = luci.http.formvalue()
+ local req = luci.dispatcher.context.request
+ local path = luci.dispatcher.context.path
+ local uci = luci.model.uci.cursor()
+ local spans = luci.util.split( uci:get( "luci_statistics", "collectd_rrdtool", "RRATimespans" ), "%s+", nil, true )
+ local span = vars.timespan or uci:get( "luci_statistics", "rrdtool", "default_timespan" ) or spans[1]
+ local host = vars.host or uci:get( "luci_statistics", "collectd", "Hostname" ) or luci.sys.hostname()
+ local opts = { host = vars.host }
+ local graph = luci.statistics.rrdtool.Graph( luci.util.parse_units( span ), opts )
+ local hosts = graph.tree:host_instances()
+
+ local is_index = false
+ local i, p, inst, idx
+
+ -- deliver image
+ if vars.img then
+ local l12 = require "luci.ltn12"
+ local png = io.open(graph.opts.imgpath .. "/" .. vars.img:gsub("%.+", "."), "r")
+ if png then
+ luci.http.prepare_content("image/png")
+ l12.pump.all(l12.source.file(png), luci.http.write)
+ png:close()
+ end
+ return
+ end
+
+ local plugin, instances
+ local images = { }
+
+ -- find requested plugin and instance
+ for i, p in ipairs( luci.dispatcher.context.path ) do
+ if luci.dispatcher.context.path[i] == "graph" then
+ plugin = luci.dispatcher.context.path[i+1]
+ instances = { luci.dispatcher.context.path[i+2] }
+ end
+ end
+
+ -- no instance requested, find all instances
+ if #instances == 0 then
+ --instances = { graph.tree:plugin_instances( plugin )[1] }
+ instances = graph.tree:plugin_instances( plugin )
+ is_index = true
+
+ -- index instance requested
+ elseif instances[1] == "-" then
+ instances[1] = ""
+ is_index = true
+ end
+
+
+ -- render graphs
+ for i, inst in luci.util.vspairs( instances ) do
+ for i, img in luci.util.vspairs( graph:render( plugin, inst, is_index ) ) do
+ table.insert( images, graph:strippngpath( img ) )
+ images[images[#images]] = inst
+ end
+ end
+
+ luci.template.render( "public_statistics/graph", {
+ images = images,
+ plugin = plugin,
+ timespans = spans,
+ current_timespan = span,
+ hosts = hosts,
+ current_host = host,
+ is_index = is_index
+ } )
+end
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/collectd.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/collectd.lua
new file mode 100644
index 0000000000..2343854f66
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/collectd.lua
@@ -0,0 +1,74 @@
+--[[
+
+Luci configuration model for statistics - general collectd configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+require("luci.sys")
+
+
+m = Map("luci_statistics",
+ translate("Collectd Settings"),
+ translate(
+ "Collectd is a small daemon for collecting data from " ..
+ "various sources through different plugins. On this page " ..
+ "you can change general settings for the collectd daemon."
+ ))
+
+-- general config section
+s = m:section( NamedSection, "collectd", "luci_statistics" )
+
+-- general.hostname (Hostname)
+hostname = s:option( Value, "Hostname", translate("Hostname") )
+hostname.default = luci.sys.hostname()
+hostname.optional = true
+
+-- general.basedir (BaseDir)
+basedir = s:option( Value, "BaseDir", translate("Base Directory") )
+basedir.default = "/var/run/collectd"
+
+-- general.include (Include)
+include = s:option( Value, "Include", translate("Directory for sub-configurations") )
+include.default = "/etc/collectd/conf.d/*.conf"
+
+-- general.plugindir (PluginDir)
+plugindir = s:option( Value, "PluginDir", translate("Directory for collectd plugins") )
+plugindir.default = "/usr/lib/collectd/"
+
+-- general.pidfile (PIDFile)
+pidfile = s:option( Value, "PIDFile", translate("Used PID file") )
+pidfile.default = "/var/run/collectd.pid"
+
+-- general.typesdb (TypesDB)
+typesdb = s:option( Value, "TypesDB", translate("Datasets definition file") )
+typesdb.default = "/etc/collectd/types.db"
+
+-- general.interval (Interval)
+interval = s:option( Value, "Interval", translate("Data collection interval"), translate("Seconds") )
+interval.default = 60
+interval.isnumber = true
+
+-- general.readthreads (ReadThreads)
+readthreads = s:option( Value, "ReadThreads", translate("Number of threads for data collection") )
+readthreads.default = 5
+readthreads.isnumber = true
+
+-- general.fqdnlookup (FQDNLookup)
+fqdnlookup = s:option( Flag, "FQDNLookup", translate("Try to lookup fully qualified hostname") )
+fqdnlookup.enabled = "true"
+fqdnlookup.disabled = "false"
+fqdnlookup.default = "false"
+fqdnlookup.optional = true
+fqdnlookup:depends( "Hostname", "" )
+
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/conntrack.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/conntrack.lua
new file mode 100644
index 0000000000..81e9c05a55
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/conntrack.lua
@@ -0,0 +1,21 @@
+--[[
+
+Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+]]--
+
+m = Map("luci_statistics",
+ translate("Conntrack Plugin Configuration"),
+ translate("The conntrack plugin collects statistics about the number of tracked connections."))
+
+s = m:section( NamedSection, "collectd_conntrack", "luci_statistics" )
+
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/cpu.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/cpu.lua
new file mode 100644
index 0000000000..26d5f07c84
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/cpu.lua
@@ -0,0 +1,27 @@
+--[[
+
+Luci configuration model for statistics - collectd cpu plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+m = Map("luci_statistics",
+ translate("CPU Plugin Configuration"),
+ translate("The cpu plugin collects basic statistics about the processor usage."))
+
+-- collectd_cpu config section
+s = m:section( NamedSection, "collectd_cpu", "luci_statistics" )
+
+-- collectd_cpu.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/csv.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/csv.lua
new file mode 100644
index 0000000000..4f5aeef1d0
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/csv.lua
@@ -0,0 +1,41 @@
+--[[
+
+Luci configuration model for statistics - collectd csv plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+m = Map("luci_statistics",
+ translate("CSV Plugin Configuration"),
+ translate(
+ "The csv plugin stores collected data in csv file format " ..
+ "for further processing by external programs."
+ ))
+
+-- collectd_csv config section
+s = m:section( NamedSection, "collectd_csv", "luci_statistics" )
+
+-- collectd_csv.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+-- collectd_csv.datadir (DataDir)
+datadir = s:option( Value, "DataDir", translate("Storage directory for the csv files") )
+datadir.default = "127.0.0.1"
+datadir:depends( "enable", 1 )
+
+-- collectd_csv.storerates (StoreRates)
+storerates = s:option( Flag, "StoreRates", translate("Store data values as rates instead of absolute values") )
+storerates.default = 0
+storerates:depends( "enable", 1 )
+
+return m
+
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/df.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/df.lua
new file mode 100644
index 0000000000..1a3245fc04
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/df.lua
@@ -0,0 +1,53 @@
+--[[
+
+Luci configuration model for statistics - collectd df plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+m = Map("luci_statistics",
+ translate("DF Plugin Configuration"),
+ translate(
+ "The df plugin collects statistics about the disk space " ..
+ "usage on different devices, mount points or filesystem types."
+ ))
+
+-- collectd_df config section
+s = m:section( NamedSection, "collectd_df", "luci_statistics" )
+
+-- collectd_df.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+-- collectd_df.devices (Device)
+devices = s:option( Value, "Devices", translate("Monitor devices") )
+devices.default = "/dev/mtdblock/4"
+devices.optional = true
+devices:depends( "enable", 1 )
+
+-- collectd_df.mountpoints (MountPoint)
+mountpoints = s:option( Value, "MountPoints", translate("Monitor mount points") )
+mountpoints.default = "/overlay"
+mountpoints.optional = true
+mountpoints:depends( "enable", 1 )
+
+-- collectd_df.fstypes (FSType)
+fstypes = s:option( Value, "FSTypes", translate("Monitor filesystem types") )
+fstypes.default = "tmpfs"
+fstypes.optional = true
+fstypes:depends( "enable", 1 )
+
+-- collectd_df.ignoreselected (IgnoreSelected)
+ignoreselected = s:option( Flag, "IgnoreSelected", translate("Monitor all except specified") )
+ignoreselected.default = 0
+ignoreselected:depends( "enable", 1 )
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/disk.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/disk.lua
new file mode 100644
index 0000000000..7592b44403
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/disk.lua
@@ -0,0 +1,41 @@
+--[[
+
+Luci configuration model for statistics - collectd disk plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+m = Map("luci_statistics",
+ translate("Disk Plugin Configuration"),
+ translate(
+ "The disk plugin collects detailled usage statistics " ..
+ "for selected partitions or whole disks."
+ ))
+
+-- collectd_disk config section
+s = m:section( NamedSection, "collectd_disk", "luci_statistics" )
+
+-- collectd_disk.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+-- collectd_disk.disks (Disk)
+devices = s:option( Value, "Disks", translate("Monitor disks and partitions") )
+devices.default = "hda1 hdb"
+devices.rmempty = true
+devices:depends( "enable", 1 )
+
+-- collectd_disk.ignoreselected (IgnoreSelected)
+ignoreselected = s:option( Flag, "IgnoreSelected", translate("Monitor all except specified") )
+ignoreselected.default = 0
+ignoreselected:depends( "enable", 1 )
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/dns.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/dns.lua
new file mode 100644
index 0000000000..28d9e5de33
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/dns.lua
@@ -0,0 +1,48 @@
+--[[
+
+Luci configuration model for statistics - collectd dns plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+require("luci.sys")
+
+
+m = Map("luci_statistics",
+ translate("DNS Plugin Configuration"),
+ translate(
+ "The dns plugin collects detailled statistics about dns " ..
+ "related traffic on selected interfaces."
+ ))
+
+-- collectd_dns config section
+s = m:section( NamedSection, "collectd_dns", "luci_statistics" )
+
+-- collectd_dns.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+-- collectd_dns.interfaces (Interface)
+interfaces = s:option( MultiValue, "Interfaces", translate("Monitor interfaces") )
+interfaces.widget = "select"
+interfaces.size = 5
+interfaces:depends( "enable", 1 )
+interfaces:value("any")
+for k, v in pairs(luci.sys.net.devices()) do
+ interfaces:value(v)
+end
+
+-- collectd_dns.ignoresources (IgnoreSource)
+ignoresources = s:option( Value, "IgnoreSources", translate("Ignore source addresses") )
+ignoresources.default = "127.0.0.1"
+ignoresources:depends( "enable", 1 )
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/email.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/email.lua
new file mode 100644
index 0000000000..c5733d8cf8
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/email.lua
@@ -0,0 +1,60 @@
+--[[
+
+Luci configuration model for statistics - collectd email plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+m = Map("luci_statistics",
+ translate("E-Mail Plugin Configuration"),
+ translate(
+ "The email plugin creates a unix socket which can be used " ..
+ "to transmit email-statistics to a running collectd daemon. " ..
+ "This plugin is primarily intended to be used in conjunction " ..
+ "with Mail::SpamAssasin::Plugin::Collectd but can be used in " ..
+ "other ways as well."
+ ))
+
+-- collectd_email config section
+s = m:section( NamedSection, "collectd_email", "luci_statistics" )
+
+-- collectd_email.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+-- collectd_email.socketfile (SocketFile)
+socketfile = s:option( Value, "SocketFile", translate("Socket file") )
+socketfile.default = "/var/run/collect-email.sock"
+socketfile:depends( "enable", 1 )
+
+-- collectd_email.socketgroup (SocketGroup)
+socketgroup = s:option( Value, "SocketGroup", translate("Socket group") )
+socketgroup.default = "nobody"
+socketgroup.rmempty = true
+socketgroup.optional = true
+socketgroup:depends( "enable", 1 )
+
+-- collectd_email.socketperms (SocketPerms)
+socketperms = s:option( Value, "SocketPerms", translate("Socket permissions") )
+socketperms.default = "0770"
+socketperms.rmempty = true
+socketperms.optional = true
+socketperms:depends( "enable", 1 )
+
+-- collectd_email.maxconns (MaxConns)
+maxconns = s:option( Value, "MaxConns", translate("Maximum allowed connections") )
+maxconns.default = 5
+maxconns.isinteger = true
+maxconns.rmempty = true
+maxconns.optional = true
+maxconns:depends( "enable", 1 )
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/exec.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/exec.lua
new file mode 100644
index 0000000000..997d455d9a
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/exec.lua
@@ -0,0 +1,89 @@
+--[[
+
+Luci configuration model for statistics - collectd exec plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+m = Map("luci_statistics",
+ translate("Exec Plugin Configuration"),
+ translate(
+ "The exec plugin starts external commands to read values " ..
+ "from or to notify external processes when certain threshold " ..
+ "values have been reached."
+ ))
+
+-- collectd_exec config section
+s = m:section( NamedSection, "collectd_exec", "luci_statistics" )
+
+-- collectd_exec.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+
+-- collectd_exec_input config section (Exec directives)
+exec = m:section( TypedSection, "collectd_exec_input",
+ translate("Add command for reading values"),
+ translate(
+ "Here you can define external commands which will be " ..
+ "started by collectd in order to read certain values. " ..
+ "The values will be read from stdout."
+ ))
+exec.addremove = true
+exec.anonymous = true
+
+-- collectd_exec_input.cmdline
+exec_cmdline = exec:option( Value, "cmdline", translate("Script") )
+exec_cmdline.default = "/usr/bin/stat-dhcpusers"
+
+-- collectd_exec_input.cmdline
+exec_cmduser = exec:option( Value, "cmduser", translate("User") )
+exec_cmduser.default = "nobody"
+exec_cmduser.rmempty = true
+exec_cmduser.optional = true
+
+-- collectd_exec_input.cmdline
+exec_cmdgroup = exec:option( Value, "cmdgroup", translate("Group") )
+exec_cmdgroup.default = "nogroup"
+exec_cmdgroup.rmempty = true
+exec_cmdgroup.optional = true
+
+
+-- collectd_exec_notify config section (NotifyExec directives)
+notify = m:section( TypedSection, "collectd_exec_notify",
+ translate("Add notification command"),
+ translate(
+ "Here you can define external commands which will be " ..
+ "started by collectd when certain threshold values have " ..
+ "been reached. The values leading to invokation will be " ..
+ "feeded to the the called programs stdin."
+ ))
+notify.addremove = true
+notify.anonymous = true
+
+-- collectd_notify_input.cmdline
+notify_cmdline = notify:option( Value, "cmdline", translate("Script") )
+notify_cmdline.default = "/usr/bin/stat-dhcpusers"
+
+-- collectd_notify_input.cmdline
+notify_cmduser = notify:option( Value, "cmduser", translate("User") )
+notify_cmduser.default = "nobody"
+notify_cmduser.rmempty = true
+notify_cmduser.optional = true
+
+-- collectd_notify_input.cmdline
+notify_cmdgroup = notify:option( Value, "cmdgroup", translate("Group") )
+notify_cmdgroup.default = "nogroup"
+notify_cmdgroup.rmempty = true
+notify_cmdgroup.optional = true
+
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/interface.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/interface.lua
new file mode 100644
index 0000000000..dbb3e9dc06
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/interface.lua
@@ -0,0 +1,47 @@
+--[[
+
+Luci configuration model for statistics - collectd interface plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+require("luci.sys")
+
+
+m = Map("luci_statistics",
+ translate("Interface Plugin Configuration"),
+ translate(
+ "The interface plugin collects traffic statistics on " ..
+ "selected interfaces."
+ ))
+
+-- collectd_interface config section
+s = m:section( NamedSection, "collectd_interface", "luci_statistics" )
+
+-- collectd_interface.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+-- collectd_interface.interfaces (Interface)
+interfaces = s:option( MultiValue, "Interfaces", translate("Monitor interfaces") )
+interfaces.widget = "select"
+interfaces.size = 5
+interfaces:depends( "enable", 1 )
+for k, v in pairs(luci.sys.net.devices()) do
+ interfaces:value(v)
+end
+
+-- collectd_interface.ignoreselected (IgnoreSelected)
+ignoreselected = s:option( Flag, "IgnoreSelected", translate("Monitor all except specified") )
+ignoreselected.default = 0
+ignoreselected:depends( "enable", 1 )
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/iptables.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/iptables.lua
new file mode 100644
index 0000000000..1f7341c46e
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/iptables.lua
@@ -0,0 +1,132 @@
+--[[
+
+Luci configuration model for statistics - collectd iptables plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+require("luci.sys.iptparser")
+
+ip = luci.sys.iptparser.IptParser()
+chains = { }
+targets = { }
+
+for i, rule in ipairs( ip:find() ) do
+ if rule.chain and rule.target then
+ chains[rule.chain] = true
+ targets[rule.target] = true
+ end
+end
+
+
+m = Map("luci_statistics",
+ translate("Iptables Plugin Configuration"),
+ translate(
+ "The iptables plugin will monitor selected firewall rules and " ..
+ "collect informations about processed bytes and packets per rule."
+ ))
+
+-- collectd_iptables config section
+s = m:section( NamedSection, "collectd_iptables", "luci_statistics" )
+
+-- collectd_iptables.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+
+-- collectd_iptables_match config section (Chain directives)
+rule = m:section( TypedSection, "collectd_iptables_match",
+ translate("Add matching rule"),
+ translate(
+ "Here you can define various criteria by which the monitored " ..
+ "iptables rules are selected."
+ ))
+rule.addremove = true
+rule.anonymous = true
+
+
+-- collectd_iptables_match.name
+rule_table = rule:option( Value, "name",
+ translate("Name of the rule"), translate("max. 16 chars") )
+
+-- collectd_iptables_match.table
+rule_table = rule:option( ListValue, "table", translate("Table") )
+rule_table.default = "filter"
+rule_table.rmempty = true
+rule_table.optional = true
+rule_table:value("")
+rule_table:value("filter")
+rule_table:value("nat")
+rule_table:value("mangle")
+
+
+-- collectd_iptables_match.chain
+rule_chain = rule:option( ListValue, "chain", translate("Chain") )
+rule_chain.rmempty = true
+rule_chain.optional = true
+rule_chain:value("")
+
+for chain, void in pairs( chains ) do
+ rule_chain:value( chain )
+end
+
+
+-- collectd_iptables_match.target
+rule_target = rule:option( ListValue, "target", translate("Action (target)") )
+rule_target.rmempty = true
+rule_target.optional = true
+rule_target:value("")
+
+for target, void in pairs( targets ) do
+ rule_target:value( target )
+end
+
+
+-- collectd_iptables_match.protocol
+rule_protocol = rule:option( ListValue, "protocol", translate("Network protocol") )
+rule_protocol.rmempty = true
+rule_protocol.optional = true
+rule_protocol:value("")
+rule_protocol:value("tcp")
+rule_protocol:value("udp")
+rule_protocol:value("icmp")
+
+-- collectd_iptables_match.source
+rule_source = rule:option( Value, "source", translate("Source ip range") )
+rule_source.default = "0.0.0.0/0"
+rule_source.rmempty = true
+rule_source.optional = true
+
+-- collectd_iptables_match.destination
+rule_destination = rule:option( Value, "destination", translate("Destination ip range") )
+rule_destination.default = "0.0.0.0/0"
+rule_destination.rmempty = true
+rule_destination.optional = true
+
+-- collectd_iptables_match.inputif
+rule_inputif = rule:option( Value, "inputif",
+ translate("Incoming interface"), translate("e.g. br-lan") )
+rule_inputif.rmempty = true
+rule_inputif.optional = true
+
+-- collectd_iptables_match.outputif
+rule_outputif = rule:option( Value, "outputif",
+ translate("Outgoing interface"), translate("e.g. br-ff") )
+rule_outputif.rmempty = true
+rule_outputif.optional = true
+
+-- collectd_iptables_match.options
+rule_options = rule:option( Value, "options",
+ translate("Options"), translate("e.g. reject-with tcp-reset") )
+rule_options.rmempty = true
+rule_options.optional = true
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/irq.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/irq.lua
new file mode 100644
index 0000000000..d6aa2e96c3
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/irq.lua
@@ -0,0 +1,42 @@
+--[[
+
+Luci configuration model for statistics - collectd irq plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+m = Map("luci_statistics",
+ translate("IRQ Plugin Configuration"),
+ translate(
+ "The irq plugin will monitor the rate of issues per second for " ..
+ "each selected interrupt. If no interrupt is selected then all " ..
+ "interrupts are monitored."
+ ))
+
+-- collectd_irq config section
+s = m:section( NamedSection, "collectd_irq", "luci_statistics" )
+
+-- collectd_irq.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+-- collectd_irq.irqs (Irq)
+irqs = s:option( Value, "Irqs", translate("Monitor interrupts") )
+irqs.optional = true
+irqs:depends( "enable", 1 )
+
+-- collectd_irq.ignoreselected (IgnoreSelected)
+ignoreselected = s:option( Flag, "IgnoreSelected", translate("Monitor all except specified") )
+ignoreselected.default = 0
+ignoreselected.optional = "true"
+ignoreselected:depends( "enable", 1 )
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/iwinfo.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/iwinfo.lua
new file mode 100644
index 0000000000..5e9340dc46
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/iwinfo.lua
@@ -0,0 +1,38 @@
+--[[
+
+Luci configuration model for statistics - collectd interface plugin configuration
+(c) 2011 Jo-Philipp Wich <xm@subsignal.org>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+local m, s, o
+
+m = Map("luci_statistics",
+ translate("Wireless iwinfo Plugin Configuration"),
+ translate("The iwinfo plugin collects statistics about wireless signal strength, noise and quality."))
+
+s = m:section(NamedSection, "collectd_iwinfo", "luci_statistics")
+
+o = s:option(Flag, "enable", translate("Enable this plugin"))
+o.default = 0
+
+o = s:option(Value, "Interfaces", translate("Monitor interfaces"),
+ translate("Leave unselected to automatically determine interfaces to monitor."))
+o.template = "cbi/network_ifacelist"
+o.widget = "checkbox"
+o.nocreate = true
+o:depends("enable", 1)
+
+o = s:option(Flag, "IgnoreSelected", translate("Monitor all except specified"))
+o.default = 0
+o:depends("enable", 1)
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/load.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/load.lua
new file mode 100644
index 0000000000..e59a4b8f7e
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/load.lua
@@ -0,0 +1,29 @@
+--[[
+
+Luci configuration model for statistics - collectd load plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+m = Map("luci_statistics",
+ translate("Load Plugin Configuration"),
+ translate(
+ "The load plugin collects statistics about the general system load."
+ ))
+
+-- collectd_wireless config section
+s = m:section( NamedSection, "collectd_load", "luci_statistics" )
+
+-- collectd_wireless.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/memory.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/memory.lua
new file mode 100644
index 0000000000..5510a5a8e8
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/memory.lua
@@ -0,0 +1,21 @@
+--[[
+
+Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+]]--
+
+m = Map("luci_statistics",
+ translate("Memory Plugin Configuration"),
+ translate("The memory plugin collects statistics about the memory usage."))
+
+s = m:section( NamedSection, "collectd_memory", "luci_statistics" )
+
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/netlink.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/netlink.lua
new file mode 100644
index 0000000000..3417d0902d
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/netlink.lua
@@ -0,0 +1,95 @@
+--[[
+
+Luci configuration model for statistics - collectd netlink plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+require("luci.sys")
+
+local devices = luci.sys.net.devices()
+
+
+m = Map("luci_statistics",
+ translate("Netlink Plugin Configuration"),
+ translate(
+ "The netlink plugin collects extended informations like " ..
+ "qdisc-, class- and filter-statistics for selected interfaces."
+ ))
+
+-- collectd_netlink config section
+s = m:section( NamedSection, "collectd_netlink", "luci_statistics" )
+
+-- collectd_netlink.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+-- collectd_netlink.interfaces (Interface)
+interfaces = s:option( MultiValue, "Interfaces", translate("Basic monitoring") )
+interfaces.widget = "select"
+interfaces.optional = true
+interfaces.size = #devices + 1
+interfaces:depends( "enable", 1 )
+interfaces:value("")
+for i, v in ipairs(devices) do
+ interfaces:value(v)
+end
+
+-- collectd_netlink.verboseinterfaces (VerboseInterface)
+verboseinterfaces = s:option( MultiValue, "VerboseInterfaces", translate("Verbose monitoring") )
+verboseinterfaces.widget = "select"
+verboseinterfaces.optional = true
+verboseinterfaces.size = #devices + 1
+verboseinterfaces:depends( "enable", 1 )
+verboseinterfaces:value("")
+for i, v in ipairs(devices) do
+ verboseinterfaces:value(v)
+end
+
+-- collectd_netlink.qdiscs (QDisc)
+qdiscs = s:option( MultiValue, "QDiscs", translate("Qdisc monitoring") )
+qdiscs.widget = "select"
+qdiscs.optional = true
+qdiscs.size = #devices + 1
+qdiscs:depends( "enable", 1 )
+qdiscs:value("")
+for i, v in ipairs(devices) do
+ qdiscs:value(v)
+end
+
+-- collectd_netlink.classes (Class)
+classes = s:option( MultiValue, "Classes", translate("Shaping class monitoring") )
+classes.widget = "select"
+classes.optional = true
+classes.size = #devices + 1
+classes:depends( "enable", 1 )
+classes:value("")
+for i, v in ipairs(devices) do
+ classes:value(v)
+end
+
+-- collectd_netlink.filters (Filter)
+filters = s:option( MultiValue, "Filters", translate("Filter class monitoring") )
+filters.widget = "select"
+filters.optional = true
+filters.size = #devices + 1
+filters:depends( "enable", 1 )
+filters:value("")
+for i, v in ipairs(devices) do
+ filters:value(v)
+end
+
+-- collectd_netlink.ignoreselected (IgnoreSelected)
+ignoreselected = s:option( Flag, "IgnoreSelected", translate("Monitor all except specified") )
+ignoreselected.default = 0
+ignoreselected:depends( "enable", 1 )
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/network.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/network.lua
new file mode 100644
index 0000000000..8a0068973e
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/network.lua
@@ -0,0 +1,98 @@
+--[[
+
+Luci configuration model for statistics - collectd network plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+
+m = Map("luci_statistics",
+ translate("Network Plugin Configuration"),
+ translate(
+ "The network plugin provides network based communication between " ..
+ "different collectd instances. Collectd can operate both in client " ..
+ "and server mode. In client mode locally collected date is " ..
+ "transferred to a collectd server instance, in server mode the " ..
+ "local instance receives data from other hosts."
+ ))
+
+-- collectd_network config section
+s = m:section( NamedSection, "collectd_network", "luci_statistics" )
+
+-- collectd_network.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+
+-- collectd_network_listen config section (Listen)
+listen = m:section( TypedSection, "collectd_network_listen",
+ translate("Listener interfaces"),
+ translate(
+ "This section defines on which interfaces collectd will wait " ..
+ "for incoming connections."
+ ))
+listen.addremove = true
+listen.anonymous = true
+
+-- collectd_network_listen.host
+listen_host = listen:option( Value, "host", translate("Listen host") )
+listen_host.default = "0.0.0.0"
+
+-- collectd_network_listen.port
+listen_port = listen:option( Value, "port", translate("Listen port") )
+listen_port.default = 25826
+listen_port.isinteger = true
+listen_port.optional = true
+
+
+-- collectd_network_server config section (Server)
+server = m:section( TypedSection, "collectd_network_server",
+ translate("server interfaces"),
+ translate(
+ "This section defines to which servers the locally collected " ..
+ "data is sent to."
+ ))
+server.addremove = true
+server.anonymous = true
+
+-- collectd_network_server.host
+server_host = server:option( Value, "host", translate("Server host") )
+server_host.default = "0.0.0.0"
+
+-- collectd_network_server.port
+server_port = server:option( Value, "port", translate("Server port") )
+server_port.default = 25826
+server_port.isinteger = true
+server_port.optional = true
+
+-- collectd_network.timetolive (TimeToLive)
+ttl = s:option( Value, "TimeToLive", translate("TTL for network packets") )
+ttl.default = 128
+ttl.isinteger = true
+ttl.optional = true
+ttl:depends( "enable", 1 )
+
+-- collectd_network.forward (Forward)
+forward = s:option( Flag, "Forward", translate("Forwarding between listen and server addresses") )
+forward.default = 0
+forward.optional = true
+forward:depends( "enable", 1 )
+
+-- collectd_network.cacheflush (CacheFlush)
+cacheflush = s:option( Value, "CacheFlush",
+ translate("Cache flush interval"), translate("Seconds") )
+cacheflush.default = 86400
+cacheflush.isinteger = true
+cacheflush.optional = true
+cacheflush:depends( "enable", 1 )
+
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/nut.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/nut.lua
new file mode 100644
index 0000000000..ad030718cf
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/nut.lua
@@ -0,0 +1,28 @@
+--[[
+LuCI - Lua Configuration Interface
+
+Copyright © 2011 Manuel Munz <freifunk at somakoma dot de>
+Copyright © 2012 David Woodhouse <dwmw2@infradead.org>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+]]--
+
+m = Map("luci_statistics",
+ translate("UPS Plugin Configuration"),
+ translate("The NUT plugin reads information about Uninterruptible Power Supplies."))
+
+s = m:section(NamedSection, "collectd_nut", "luci_statistics" )
+
+enable = s:option(Flag, "enable", translate("Enable this plugin"))
+enable.default = 0
+
+host = s:option(Value, "UPS", translate("UPS"), translate("UPS name in NUT ups@host format"))
+host.placeholder = "myupsname"
+host.datatype = "string"
+host.rmempty = true
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/olsrd.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/olsrd.lua
new file mode 100644
index 0000000000..e3eb7b2c4b
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/olsrd.lua
@@ -0,0 +1,54 @@
+--[[
+LuCI - Lua Configuration Interface
+
+Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+]]--
+
+m = Map("luci_statistics",
+ translate("OLSRd Plugin Configuration"),
+ translate("The OLSRd plugin reads information about meshed networks from the txtinfo plugin of OLSRd."))
+
+s = m:section(NamedSection, "collectd_olsrd", "luci_statistics" )
+
+enable = s:option(Flag, "enable", translate("Enable this plugin"))
+enable.default = 0
+
+host = s:option(Value, "Host", translate("Host"), translate("IP or hostname where to get the txtinfo output from"))
+host.placeholder = "127.0.0.1"
+host.datatype = "host"
+host.rmempty = true
+
+port = s:option(Value, "Port", translate("Port"))
+port.placeholder = "2006"
+port.datatype = "range(0,65535)"
+port.rmempty = true
+port.cast = "string"
+
+cl = s:option(ListValue, "CollectLinks", translate("CollectLinks"),
+ translate("Specifies what information to collect about links."))
+cl:value("No")
+cl:value("Summary")
+cl:value("Detail")
+cl.default = "Detail"
+
+cr = s:option(ListValue, "CollectRoutes", translate("CollectRoutes"),
+ translate("Specifies what information to collect about routes."))
+cr:value("No")
+cr:value("Summary")
+cr:value("Detail")
+cr.default = "Summary"
+
+ct = s:option(ListValue, "CollectTopology", translate("CollectTopology"),
+ translate("Specifies what information to collect about the global topology."))
+ct:value("No")
+ct:value("Summary")
+ct:value("Detail")
+ct.default = "Summary"
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/ping.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/ping.lua
new file mode 100644
index 0000000000..c55ac87368
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/ping.lua
@@ -0,0 +1,47 @@
+--[[
+
+Luci configuration model for statistics - collectd ping plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+m = Map("luci_statistics",
+ translate("Ping Plugin Configuration"),
+ translate(
+ "The ping plugin will send icmp echo replies to selected " ..
+ "hosts and measure the roundtrip time for each host."
+ ))
+
+-- collectd_ping config section
+s = m:section( NamedSection, "collectd_ping", "luci_statistics" )
+
+-- collectd_ping.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+-- collectd_ping.hosts (Host)
+hosts = s:option( Value, "Hosts", translate("Monitor hosts"), translate ("Add multiple hosts separated by space."))
+hosts.default = "127.0.0.1"
+hosts:depends( "enable", 1 )
+
+-- collectd_ping.ttl (TTL)
+ttl = s:option( Value, "TTL", translate("TTL for ping packets") )
+ttl.isinteger = true
+ttl.default = 128
+ttl:depends( "enable", 1 )
+
+-- collectd_ping.interval (Interval)
+interval = s:option( Value, "Interval", translate("Interval for pings"), translate ("Seconds") )
+interval.isinteger = true
+interval.default = 30
+interval:depends( "enable", 1 )
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/processes.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/processes.lua
new file mode 100644
index 0000000000..3aea6b3c71
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/processes.lua
@@ -0,0 +1,36 @@
+--[[
+
+Luci configuration model for statistics - collectd processes plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+m = Map("luci_statistics",
+ translate("Processes Plugin Configuration"),
+ translate(
+ "The processes plugin collects informations like cpu time, " ..
+ "page faults and memory usage of selected processes."
+ ))
+
+-- collectd_processes config section
+s = m:section( NamedSection, "collectd_processes", "luci_statistics" )
+
+-- collectd_processes.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+-- collectd_processes.processes (Process)
+processes = s:option( Value, "Processes", translate("Monitor processes"),
+ translate("Processes to monitor separated by space") )
+processes:depends( "enable", 1 )
+processes.default = "uhttpd dropbear dnsmasq"
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/rrdtool.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/rrdtool.lua
new file mode 100644
index 0000000000..75716341c8
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/rrdtool.lua
@@ -0,0 +1,108 @@
+--[[
+
+Luci configuration model for statistics - collectd rrdtool plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+m = Map("luci_statistics",
+ translate("RRDTool Plugin Configuration"),
+ translate(
+ "The rrdtool plugin stores the collected data in rrd database " ..
+ "files, the foundation of the diagrams.<br /><br />" ..
+ "<strong>Warning: Setting the wrong values will result in a very " ..
+ "high memory consumption in the temporary directory. " ..
+ "This can render the device unusable!</strong>"
+ ))
+
+-- collectd_rrdtool config section
+s = m:section( NamedSection, "collectd_rrdtool", "luci_statistics" )
+
+-- collectd_rrdtool.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 1
+
+-- collectd_rrdtool.datadir (DataDir)
+datadir = s:option( Value, "DataDir", translate("Storage directory") )
+datadir.default = "/tmp"
+datadir.rmempty = true
+datadir.optional = true
+datadir:depends( "enable", 1 )
+
+-- collectd_rrdtool.stepsize (StepSize)
+stepsize = s:option( Value, "StepSize",
+ translate("RRD step interval"), translate("Seconds") )
+stepsize.default = 30
+stepsize.isinteger = true
+stepsize.rmempty = true
+stepsize.optional = true
+stepsize:depends( "enable", 1 )
+
+-- collectd_rrdtool.heartbeat (HeartBeat)
+heartbeat = s:option( Value, "HeartBeat",
+ translate("RRD heart beat interval"), translate("Seconds") )
+heartbeat.default = 60
+heartbeat.isinteger = true
+heartbeat.rmempty = true
+heartbeat.optional = true
+heartbeat:depends( "enable", 1 )
+
+-- collectd_rrdtool.rrasingle (RRASingle)
+rrasingle = s:option( Flag, "RRASingle",
+ translate("Only create average RRAs"), translate("reduces rrd size") )
+rrasingle.default = true
+rrasingle.rmempty = true
+rrasingle.optional = true
+rrasingle:depends( "enable", 1 )
+
+-- collectd_rrdtool.rratimespans (RRATimespan)
+rratimespans = s:option( Value, "RRATimespans",
+ translate("Stored timespans"), translate("seconds; multiple separated by space") )
+rratimespans.default = "600 86400 604800 2678400 31622400"
+rratimespans.rmempty = true
+rratimespans.optional = true
+rratimespans:depends( "enable", 1 )
+
+-- collectd_rrdtool.rrarows (RRARows)
+rrarows = s:option( Value, "RRARows", translate("Rows per RRA") )
+rrarows.isinteger = true
+rrarows.default = 100
+rrarows.rmempty = true
+rrarows.optional = true
+rrarows:depends( "enable", 1 )
+
+-- collectd_rrdtool.xff (XFF)
+xff = s:option( Value, "XFF", translate("RRD XFiles Factor") )
+xff.default = 0.1
+xff.isnumber = true
+xff.rmempty = true
+xff.optional = true
+xff:depends( "enable", 1 )
+
+-- collectd_rrdtool.cachetimeout (CacheTimeout)
+cachetimeout = s:option( Value, "CacheTimeout",
+ translate("Cache collected data for"), translate("Seconds") )
+cachetimeout.isinteger = true
+cachetimeout.default = 100
+cachetimeout.rmempty = true
+cachetimeout.optional = true
+cachetimeout:depends( "enable", 1 )
+
+-- collectd_rrdtool.cacheflush (CacheFlush)
+cacheflush = s:option( Value, "CacheFlush",
+ translate("Flush cache after"), translate("Seconds") )
+cacheflush.isinteger = true
+cacheflush.default = 100
+cacheflush.rmempty = true
+cacheflush.optional = true
+cacheflush:depends( "enable", 1 )
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/splash_leases.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/splash_leases.lua
new file mode 100644
index 0000000000..a15ed0ecce
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/splash_leases.lua
@@ -0,0 +1,24 @@
+--[[
+
+Luci configuration model for statistics - collectd splash_leases plugin configuration
+(c) 2013 Freifunk Augsburg / Michael Wendland <michael@michiwend.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+]]--
+
+m = Map("luci_statistics",
+ translate("Splash Leases Plugin Configuration"),
+ translate("The splash leases plugin uses libuci to collect statistics about splash leases."))
+
+s = m:section( NamedSection, "collectd_splash_leases", "luci_statistics" )
+
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 1
+
+return m
+
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/tcpconns.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/tcpconns.lua
new file mode 100644
index 0000000000..9d0f6e137c
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/tcpconns.lua
@@ -0,0 +1,45 @@
+--[[
+
+Luci configuration model for statistics - collectd tcpconns plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+m = Map("luci_statistics",
+ translate("TCPConns Plugin Configuration"),
+ translate(
+ "The tcpconns plugin collects informations about open tcp " ..
+ "connections on selected ports."
+ ))
+
+-- collectd_tcpconns config section
+s = m:section( NamedSection, "collectd_tcpconns", "luci_statistics" )
+
+-- collectd_tcpconns.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+-- collectd_tcpconns.listeningports (ListeningPorts)
+listeningports = s:option( Flag, "ListeningPorts", translate("Monitor all local listen ports") )
+listeningports.default = 1
+listeningports:depends( "enable", 1 )
+
+-- collectd_tcpconns.localports (LocalPort)
+localports = s:option( Value, "LocalPorts", translate("Monitor local ports") )
+localports.optional = true
+localports:depends( "enable", 1 )
+
+-- collectd_tcpconns.remoteports (RemotePort)
+remoteports = s:option( Value, "RemotePorts", translate("Monitor remote ports") )
+remoteports.optional = true
+remoteports:depends( "enable", 1 )
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/unixsock.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/unixsock.lua
new file mode 100644
index 0000000000..cbd52ec1fe
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/unixsock.lua
@@ -0,0 +1,49 @@
+--[[
+
+Luci configuration model for statistics - collectd unixsock plugin configuration
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+m = Map("luci_statistics",
+ translate("Unixsock Plugin Configuration"),
+ translate(
+ "The unixsock plugin creates a unix socket which can be used " ..
+ "to read collected data from a running collectd instance."
+ ))
+
+-- collectd_unixsock config section
+s = m:section( NamedSection, "collectd_unixsock", "luci_statistics" )
+
+-- collectd_unixsock.enable
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+-- collectd_unixsock.socketfile (SocketFile)
+socketfile = s:option( Value, "SocketFile" )
+socketfile.default = "/var/run/collect-query.socket"
+socketfile:depends( "enable", 1 )
+
+-- collectd_unixsock.socketgroup (SocketGroup)
+socketgroup = s:option( Value, "SocketGroup" )
+socketgroup.default = "nobody"
+socketgroup.rmempty = true
+socketgroup.optional = true
+socketgroup:depends( "enable", 1 )
+
+-- collectd_unixsock.socketperms (SocketPerms)
+socketperms = s:option( Value, "SocketPerms" )
+socketperms.default = "0770"
+socketperms.rmempty = true
+socketperms.optional = true
+socketperms:depends( "enable", 1 )
+
+return m
diff --git a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/uptime.lua b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/uptime.lua
new file mode 100644
index 0000000000..3a6c4644e3
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/uptime.lua
@@ -0,0 +1,22 @@
+--[[
+
+Copyright 2013 Thomas Endt <tmo26@gmx.de>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+]]--
+
+m = Map("luci_statistics",
+ translate("Uptime Plugin Configuration"),
+ translate("The uptime plugin collects statistics about the uptime of the system."))
+
+s = m:section( NamedSection, "collectd_uptime", "luci_statistics" )
+
+enable = s:option( Flag, "enable", translate("Enable this plugin") )
+enable.default = 0
+
+return m
+
diff --git a/applications/luci-app-statistics/luasrc/statistics/datatree.lua b/applications/luci-app-statistics/luasrc/statistics/datatree.lua
new file mode 100644
index 0000000000..850b83a998
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/datatree.lua
@@ -0,0 +1,209 @@
+--[[
+
+Luci statistics - rrd data tree builder
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+module("luci.statistics.datatree", package.seeall)
+
+local util = require("luci.util")
+local sys = require("luci.sys")
+local fs = require("nixio.fs")
+local uci = require("luci.model.uci").cursor()
+local sections = uci:get_all("luci_statistics")
+
+
+Instance = util.class()
+
+function Instance.__init__( self, host )
+ self._host = host or sections.collectd.Hostname or sys.hostname()
+ self._libdir = sections.collectd.PluginDir or "/usr/lib/collectd"
+ self._rrddir = sections.collectd_rrdtool.DataDir or "/tmp/rrd"
+
+ self._libdir = self._libdir:gsub("/$","")
+ self._rrddir = self._rrddir:gsub("/$","")
+ self._plugins = { }
+
+ self:_scan()
+end
+
+function Instance._mkpath( self, plugin, pinstance )
+ local dir = self._rrddir .. "/" .. self._host
+
+ if type(plugin) == "string" and plugin:len() > 0 then
+ dir = dir .. "/" .. plugin
+
+ if type(pinstance) == "string" and pinstance:len() > 0 then
+ dir = dir .. "-" .. pinstance
+ end
+ end
+
+ return dir
+end
+
+function Instance._ls( self, ... )
+ local ditr = fs.dir(self:_mkpath(...))
+ if ditr then
+ local dirs = { }
+ while true do
+ local d = ditr()
+ if not d then break end
+ dirs[#dirs+1] = d
+ end
+ return dirs
+ end
+end
+
+function Instance._notzero( self, table )
+ for k in pairs(table) do
+ return true
+ end
+
+ return false
+end
+
+function Instance._scan( self )
+ local dirs = self:_ls()
+ if not dirs then
+ return
+ end
+
+-- for i, plugin in ipairs( dirs ) do
+-- if plugin:match("%w+.so") then
+-- self._plugins[ plugin:gsub("%.so$", "") ] = { }
+-- end
+-- end
+
+ for _, dir in ipairs(dirs) do
+ if dir ~= "." and dir ~= ".." and
+ fs.stat(self:_mkpath(dir)).type == "dir"
+ then
+ local plugin = dir:gsub("%-.+$", "")
+ if not self._plugins[plugin] then
+ self._plugins[plugin] = { }
+ end
+ end
+ end
+
+ for plugin, instances in pairs( self._plugins ) do
+
+ local dirs = self:_ls()
+
+ if type(dirs) == "table" then
+ for i, dir in ipairs(dirs) do
+ if dir:find( plugin .. "%-" ) or dir == plugin then
+ local instance = ""
+
+ if dir ~= plugin then
+ instance = dir:gsub( plugin .. "%-", "", 1 )
+ end
+
+ instances[instance] = { }
+ end
+ end
+ end
+
+ for instance, data_instances in pairs( instances ) do
+
+ dirs = self:_ls(plugin, instance)
+
+ if type(dirs) == "table" then
+ for i, file in ipairs(dirs) do
+ if file:find("%.rrd") then
+ file = file:gsub("%.rrd","")
+
+ local data_type
+ local data_instance
+
+ if file:find("%-") then
+ data_type = file:gsub( "%-.+","" )
+ data_instance = file:gsub( "[^%-]-%-", "", 1 )
+ else
+ data_type = file
+ data_instance = ""
+ end
+
+ if not data_instances[data_type] then
+ data_instances[data_type] = { data_instance }
+ else
+ table.insert( data_instances[data_type], data_instance )
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+
+function Instance.plugins( self )
+ local rv = { }
+
+ for plugin, val in pairs( self._plugins ) do
+ if self:_notzero( val ) then
+ table.insert( rv, plugin )
+ end
+ end
+
+ return rv
+end
+
+function Instance.plugin_instances( self, plugin )
+ local rv = { }
+
+ for instance, val in pairs( self._plugins[plugin] ) do
+ table.insert( rv, instance )
+ end
+
+ return rv
+end
+
+function Instance.data_types( self, plugin, instance )
+ local rv = { }
+ local p = self._plugins[plugin]
+
+ if type(p) == "table" and type(p[instance]) == "table" then
+ for type, val in pairs(p[instance]) do
+ table.insert( rv, type )
+ end
+ end
+
+ return rv
+end
+
+function Instance.data_instances( self, plugin, instance, dtype )
+ local rv = { }
+ local p = self._plugins[plugin]
+
+ if type(p) == "table" and type(p[instance]) == "table" and type(p[instance][dtype]) == "table" then
+ for i, instance in ipairs(p[instance][dtype]) do
+ table.insert( rv, instance )
+ end
+ end
+
+ return rv
+end
+
+function Instance.host_instances( self )
+ local hosts_path = fs.glob(self._rrddir..'/*')
+ local hosts = { }
+
+ if hosts_path then
+ local path
+ for path in hosts_path do
+ hosts[#hosts+1] = fs.basename(path)
+ end
+ end
+
+ return hosts
+end
+
diff --git a/applications/luci-app-statistics/luasrc/statistics/i18n.lua b/applications/luci-app-statistics/luasrc/statistics/i18n.lua
new file mode 100644
index 0000000000..a1a2fa9de3
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/i18n.lua
@@ -0,0 +1,108 @@
+--[[
+
+Luci statistics - diagram i18n helper
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+module("luci.statistics.i18n", package.seeall)
+
+require("luci.util")
+require("luci.i18n")
+
+
+Instance = luci.util.class()
+
+
+function Instance.__init__( self, graph )
+ self.i18n = luci.i18n
+ self.graph = graph
+end
+
+function Instance._subst( self, str, val )
+ str = str:gsub( "%%H", self.graph.opts.host or "" )
+ str = str:gsub( "%%pn", val.plugin or "" )
+ str = str:gsub( "%%pi", val.pinst or "" )
+ str = str:gsub( "%%dt", val.dtype or "" )
+ str = str:gsub( "%%di", val.dinst or "" )
+ str = str:gsub( "%%ds", val.dsrc or "" )
+
+ return str
+end
+
+function Instance._translate( self, key, alt )
+ local val = self.i18n.string(key)
+ if val ~= key then
+ return val
+ else
+ return alt
+ end
+end
+
+function Instance.title( self, plugin, pinst, dtype, dinst, user_title )
+
+ local title = user_title or
+ "p=%s/pi=%s/dt=%s/di=%s" % {
+ plugin,
+ (pinst and #pinst > 0) and pinst or "(nil)",
+ (dtype and #dtype > 0) and dtype or "(nil)",
+ (dinst and #dinst > 0) and dinst or "(nil)"
+ }
+
+ return self:_subst( title, {
+ plugin = plugin,
+ pinst = pinst,
+ dtype = dtype,
+ dinst = dinst
+ } )
+
+end
+
+function Instance.label( self, plugin, pinst, dtype, dinst, user_label )
+
+ local label = user_label or
+ "dt=%s/di=%s" % {
+ (dtype and #dtype > 0) and dtype or "(nil)",
+ (dinst and #dinst > 0) and dinst or "(nil)"
+ }
+
+ return self:_subst( label, {
+ plugin = plugin,
+ pinst = pinst,
+ dtype = dtype,
+ dinst = dinst
+ } )
+
+end
+
+function Instance.ds( self, source )
+
+ local label = source.title or self:_translate(
+ string.format( "stat_ds_%s_%s_%s", source.type, source.instance, source.ds ),
+ self:_translate(
+ string.format( "stat_ds_%s_%s", source.type, source.instance ),
+ self:_translate(
+ string.format( "stat_ds_label_%s__%s", source.type, source.ds ),
+ self:_translate(
+ string.format( "stat_ds_%s", source.type ),
+ source.type .. "_" .. source.instance:gsub("[^%w]","_") .. "_" .. source.ds
+ )
+ )
+ )
+ )
+
+ return self:_subst( label, {
+ dtype = source.type,
+ dinst = source.instance,
+ dsrc = source.ds
+ } )
+
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool.lua
new file mode 100644
index 0000000000..dbcae9dc6b
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool.lua
@@ -0,0 +1,561 @@
+--[[
+
+Luci statistics - rrdtool interface library / diagram model interpreter
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+module("luci.statistics.rrdtool", package.seeall)
+
+require("luci.statistics.datatree")
+require("luci.statistics.rrdtool.colors")
+require("luci.statistics.i18n")
+require("luci.model.uci")
+require("luci.util")
+require("luci.sys")
+
+local fs = require "nixio.fs"
+
+
+Graph = luci.util.class()
+
+function Graph.__init__( self, timespan, opts )
+
+ opts = opts or { }
+
+ local uci = luci.model.uci.cursor()
+ local sections = uci:get_all( "luci_statistics" )
+
+ -- options
+ opts.timespan = timespan or sections.rrdtool.default_timespan or 900
+ opts.rrasingle = opts.rrasingle or ( sections.collectd_rrdtool.RRASingle == "1" )
+ opts.host = opts.host or sections.collectd.Hostname or luci.sys.hostname()
+ opts.width = opts.width or sections.rrdtool.image_width or 400
+ opts.rrdpath = opts.rrdpath or sections.collectd_rrdtool.DataDir or "/tmp/rrd"
+ opts.imgpath = opts.imgpath or sections.rrdtool.image_path or "/tmp/rrdimg"
+ opts.rrdpath = opts.rrdpath:gsub("/$","")
+ opts.imgpath = opts.imgpath:gsub("/$","")
+
+ -- helper classes
+ self.colors = luci.statistics.rrdtool.colors.Instance()
+ self.tree = luci.statistics.datatree.Instance(opts.host)
+ self.i18n = luci.statistics.i18n.Instance( self )
+
+ -- rrdtool default args
+ self.args = {
+ "-a", "PNG",
+ "-s", "NOW-" .. opts.timespan,
+ "-w", opts.width
+ }
+
+ -- store options
+ self.opts = opts
+end
+
+function Graph._mkpath( self, plugin, plugin_instance, dtype, dtype_instance )
+ local t = self.opts.host .. "/" .. plugin
+ if type(plugin_instance) == "string" and plugin_instance:len() > 0 then
+ t = t .. "-" .. plugin_instance
+ end
+ t = t .. "/" .. dtype
+ if type(dtype_instance) == "string" and dtype_instance:len() > 0 then
+ t = t .. "-" .. dtype_instance
+ end
+ return t
+end
+
+function Graph.mkrrdpath( self, ... )
+ return string.format( "%s/%s.rrd", self.opts.rrdpath, self:_mkpath( ... ) )
+end
+
+function Graph.mkpngpath( self, ... )
+ return string.format( "%s/%s.%i.png", self.opts.imgpath, self:_mkpath( ... ), self.opts.timespan )
+end
+
+function Graph.strippngpath( self, path )
+ return path:sub( self.opts.imgpath:len() + 2 )
+end
+
+function Graph._forcelol( self, list )
+ if type(list[1]) ~= "table" then
+ return( { list } )
+ end
+ return( list )
+end
+
+function Graph._rrdtool( self, def, rrd )
+
+ -- prepare directory
+ local dir = def[1]:gsub("/[^/]+$","")
+ fs.mkdirr( dir )
+
+ -- construct commandline
+ local cmdline = "rrdtool graph"
+
+ -- copy default arguments to def stack
+ for i, opt in ipairs(self.args) do
+ table.insert( def, 1 + i, opt )
+ end
+
+ -- construct commandline from def stack
+ for i, opt in ipairs(def) do
+ opt = opt .. "" -- force string
+
+ if rrd then
+ opt = opt:gsub( "{file}", rrd )
+ end
+
+ if opt:match("[^%w]") then
+ cmdline = cmdline .. " '" .. opt .. "'"
+ else
+ cmdline = cmdline .. " " .. opt
+ end
+ end
+
+ -- execute rrdtool
+ local rrdtool = io.popen( cmdline )
+ rrdtool:close()
+end
+
+function Graph._generic( self, opts, plugin, plugin_instance, dtype, index )
+
+ -- generated graph defs
+ local defs = { }
+
+ -- internal state variables
+ local _args = { }
+ local _sources = { }
+ local _stack_neg = { }
+ local _stack_pos = { }
+ local _longest_name = 0
+ local _has_totals = false
+
+ -- some convenient aliases
+ local _ti = table.insert
+ local _sf = string.format
+
+ -- local helper: append a string.format() formatted string to given table
+ function _tif( list, fmt, ... )
+ table.insert( list, string.format( fmt, ... ) )
+ end
+
+ -- local helper: create definitions for min, max, avg and create *_nnl (not null) variable from avg
+ function __def(source)
+
+ local inst = source.sname
+ local rrd = source.rrd
+ local ds = source.ds
+
+ if not ds or ds:len() == 0 then ds = "value" end
+
+ _tif( _args, "DEF:%s_avg_raw=%s:%s:AVERAGE", inst, rrd, ds )
+ _tif( _args, "CDEF:%s_avg=%s_avg_raw,%s", inst, inst, source.transform_rpn )
+
+ if not self.opts.rrasingle then
+ _tif( _args, "DEF:%s_min_raw=%s:%s:MIN", inst, rrd, ds )
+ _tif( _args, "CDEF:%s_min=%s_min_raw,%s", inst, inst, source.transform_rpn )
+ _tif( _args, "DEF:%s_max_raw=%s:%s:MAX", inst, rrd, ds )
+ _tif( _args, "CDEF:%s_max=%s_max_raw,%s", inst, inst, source.transform_rpn )
+ end
+
+ _tif( _args, "CDEF:%s_nnl=%s_avg,UN,0,%s_avg,IF", inst, inst, inst )
+ end
+
+ -- local helper: create cdefs depending on source options like flip and overlay
+ function __cdef(source)
+
+ local prev
+
+ -- find previous source, choose stack depending on flip state
+ if source.flip then
+ prev = _stack_neg[#_stack_neg]
+ else
+ prev = _stack_pos[#_stack_pos]
+ end
+
+ -- is first source in stack or overlay source: source_stk = source_nnl
+ if not prev or source.overlay then
+ -- create cdef statement for cumulative stack (no NaNs) and also
+ -- for display (preserving NaN where no points should be displayed)
+ _tif( _args, "CDEF:%s_stk=%s_nnl", source.sname, source.sname )
+ _tif( _args, "CDEF:%s_plot=%s_avg", source.sname, source.sname )
+
+ -- is subsequent source without overlay: source_stk = source_nnl + previous_stk
+ else
+ -- create cdef statement
+ _tif( _args, "CDEF:%s_stk=%s_nnl,%s_stk,+", source.sname, source.sname, prev )
+ _tif( _args, "CDEF:%s_plot=%s_avg,%s_stk,+", source.sname, source.sname, prev )
+ end
+
+ -- create multiply by minus one cdef if flip is enabled
+ if source.flip then
+
+ -- create cdef statement: source_stk = source_stk * -1
+ _tif( _args, "CDEF:%s_neg=%s_plot,-1,*", source.sname, source.sname )
+
+ -- push to negative stack if overlay is disabled
+ if not source.overlay then
+ _ti( _stack_neg, source.sname )
+ end
+
+ -- no flipping, push to positive stack if overlay is disabled
+ elseif not source.overlay then
+
+ -- push to positive stack
+ _ti( _stack_pos, source.sname )
+ end
+
+ -- calculate total amount of data if requested
+ if source.total then
+ _tif( _args,
+ "CDEF:%s_avg_sample=%s_avg,UN,0,%s_avg,IF,sample_len,*",
+ source.sname, source.sname, source.sname
+ )
+
+ _tif( _args,
+ "CDEF:%s_avg_sum=PREV,UN,0,PREV,IF,%s_avg_sample,+",
+ source.sname, source.sname, source.sname
+ )
+ end
+ end
+
+ -- local helper: create cdefs required for calculating total values
+ function __cdef_totals()
+ if _has_totals then
+ _tif( _args, "CDEF:mytime=%s_avg,TIME,TIME,IF", _sources[1].sname )
+ _ti( _args, "CDEF:sample_len_raw=mytime,PREV(mytime),-" )
+ _ti( _args, "CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF" )
+ end
+ end
+
+ -- local helper: create line and area statements
+ function __line(source)
+
+ local line_color
+ local area_color
+ local legend
+ local var
+
+ -- find colors: try source, then opts.colors; fall back to random color
+ if type(source.color) == "string" then
+ line_color = source.color
+ area_color = self.colors:from_string( line_color )
+ elseif type(opts.colors[source.name:gsub("[^%w]","_")]) == "string" then
+ line_color = opts.colors[source.name:gsub("[^%w]","_")]
+ area_color = self.colors:from_string( line_color )
+ else
+ area_color = self.colors:random()
+ line_color = self.colors:to_string( area_color )
+ end
+
+ -- derive area background color from line color
+ area_color = self.colors:to_string( self.colors:faded( area_color ) )
+
+ -- choose source_plot or source_neg variable depending on flip state
+ if source.flip then
+ var = "neg"
+ else
+ var = "plot"
+ end
+
+ -- create legend
+ legend = _sf( "%-" .. _longest_name .. "s", source.title )
+
+ -- create area if not disabled
+ if not source.noarea then
+ _tif( _args, "AREA:%s_%s#%s", source.sname, var, area_color )
+ end
+
+ -- create line1 statement
+ _tif( _args, "LINE%d:%s_%s#%s:%s",
+ source.noarea and 2 or 1,
+ source.sname, var, line_color, legend )
+ end
+
+ -- local helper: create gprint statements
+ function __gprint(source)
+
+ local numfmt = opts.number_format or "%6.1lf"
+ local totfmt = opts.totals_format or "%5.1lf%s"
+
+ -- don't include MIN if rrasingle is enabled
+ if not self.opts.rrasingle then
+ _tif( _args, "GPRINT:%s_min:MIN:\tMin\\: %s", source.sname, numfmt )
+ end
+
+ -- always include AVERAGE
+ _tif( _args, "GPRINT:%s_avg:AVERAGE:\tAvg\\: %s", source.sname, numfmt )
+
+ -- don't include MAX if rrasingle is enabled
+ if not self.opts.rrasingle then
+ _tif( _args, "GPRINT:%s_max:MAX:\tMax\\: %s", source.sname, numfmt )
+ end
+
+ -- include total count if requested else include LAST
+ if source.total then
+ _tif( _args, "GPRINT:%s_avg_sum:LAST:(ca. %s Total)\\l", source.sname, totfmt )
+ else
+ _tif( _args, "GPRINT:%s_avg:LAST:\tLast\\: %s\\l", source.sname, numfmt )
+ end
+ end
+
+
+ --
+ -- find all data sources
+ --
+
+ -- find data types
+ local data_types
+
+ if dtype then
+ data_types = { dtype }
+ else
+ data_types = opts.data.types or { }
+ end
+
+ if not ( dtype or opts.data.types ) then
+ if opts.data.instances then
+ for k, v in pairs(opts.data.instances) do
+ _ti( data_types, k )
+ end
+ elseif opts.data.sources then
+ for k, v in pairs(opts.data.sources) do
+ _ti( data_types, k )
+ end
+ end
+ end
+
+
+ -- iterate over data types
+ for i, dtype in ipairs(data_types) do
+
+ -- find instances
+
+ local data_instances
+
+ if not opts.per_instance then
+ if type(opts.data.instances) == "table" and type(opts.data.instances[dtype]) == "table" then
+ data_instances = opts.data.instances[dtype]
+ else
+ data_instances = self.tree:data_instances( plugin, plugin_instance, dtype )
+ end
+ end
+
+ if type(data_instances) ~= "table" or #data_instances == 0 then data_instances = { "" } end
+
+
+ -- iterate over data instances
+ for i, dinst in ipairs(data_instances) do
+
+ -- construct combined data type / instance name
+ local dname = dtype
+
+ if dinst:len() > 0 then
+ dname = dname .. "_" .. dinst
+ end
+
+
+ -- find sources
+ local data_sources = { "value" }
+
+ if type(opts.data.sources) == "table" then
+ if type(opts.data.sources[dname]) == "table" then
+ data_sources = opts.data.sources[dname]
+ elseif type(opts.data.sources[dtype]) == "table" then
+ data_sources = opts.data.sources[dtype]
+ end
+ end
+
+
+ -- iterate over data sources
+ for i, dsource in ipairs(data_sources) do
+
+ local dsname = dtype .. "_" .. dinst:gsub("[^%w]","_") .. "_" .. dsource
+ local altname = dtype .. "__" .. dsource
+
+ --assert(dtype ~= "ping", dsname .. " or " .. altname)
+
+ -- find datasource options
+ local dopts = { }
+
+ if type(opts.data.options) == "table" then
+ if type(opts.data.options[dsname]) == "table" then
+ dopts = opts.data.options[dsname]
+ elseif type(opts.data.options[altname]) == "table" then
+ dopts = opts.data.options[altname]
+ elseif type(opts.data.options[dname]) == "table" then
+ dopts = opts.data.options[dname]
+ elseif type(opts.data.options[dtype]) == "table" then
+ dopts = opts.data.options[dtype]
+ end
+ end
+
+
+ -- store values
+ _ti( _sources, {
+ rrd = dopts.rrd or self:mkrrdpath( plugin, plugin_instance, dtype, dinst ),
+ color = dopts.color or self.colors:to_string( self.colors:random() ),
+ flip = dopts.flip or false,
+ total = dopts.total or false,
+ overlay = dopts.overlay or false,
+ transform_rpn = dopts.transform_rpn or "0,+",
+ noarea = dopts.noarea or false,
+ title = dopts.title or nil,
+ ds = dsource,
+ type = dtype,
+ instance = dinst,
+ index = #_sources + 1,
+ sname = ( #_sources + 1 ) .. dtype
+ } )
+
+
+ -- generate datasource title
+ _sources[#_sources].title = self.i18n:ds( _sources[#_sources] )
+
+
+ -- find longest name ...
+ if _sources[#_sources].title:len() > _longest_name then
+ _longest_name = _sources[#_sources].title:len()
+ end
+
+
+ -- has totals?
+ if _sources[#_sources].total then
+ _has_totals = true
+ end
+ end
+ end
+ end
+
+
+ --
+ -- construct diagrams
+ --
+
+ -- if per_instance is enabled then find all instances from the first datasource in diagram
+ -- if per_instance is disabled then use an empty pseudo instance and use model provided values
+ local instances = { "" }
+
+ if opts.per_instance then
+ instances = self.tree:data_instances( plugin, plugin_instance, _sources[1].type )
+ end
+
+
+ -- iterate over instances
+ for i, instance in ipairs(instances) do
+
+ -- store title and vlabel
+ _ti( _args, "-t" )
+ _ti( _args, self.i18n:title( plugin, plugin_instance, _sources[1].type, instance, opts.title ) )
+ _ti( _args, "-v" )
+ _ti( _args, self.i18n:label( plugin, plugin_instance, _sources[1].type, instance, opts.vlabel ) )
+ if opts.y_max then
+ _ti ( _args, "-u" )
+ _ti ( _args, opts.y_max )
+ end
+ if opts.y_min then
+ _ti ( _args, "-l" )
+ _ti ( _args, opts.y_min )
+ end
+ if opts.units_exponent then
+ _ti ( _args, "-X" )
+ _ti ( _args, opts.units_exponent )
+ end
+
+ -- store additional rrd options
+ if opts.rrdopts then
+ for i, o in ipairs(opts.rrdopts) do _ti( _args, o ) end
+ end
+
+
+ -- create DEF statements for each instance
+ for i, source in ipairs(_sources) do
+ -- fixup properties for per instance mode...
+ if opts.per_instance then
+ source.instance = instance
+ source.rrd = self:mkrrdpath( plugin, plugin_instance, source.type, instance )
+ end
+
+ __def( source )
+ end
+
+ -- create CDEF required for calculating totals
+ __cdef_totals()
+
+ -- create CDEF statements for each instance in reversed order
+ for i, source in ipairs(_sources) do
+ __cdef( _sources[1 + #_sources - i] )
+ end
+
+ -- create LINE1, AREA and GPRINT statements for each instance
+ for i, source in ipairs(_sources) do
+ __line( source )
+ __gprint( source )
+ end
+
+ -- prepend image path to arg stack
+ _ti( _args, 1, self:mkpngpath( plugin, plugin_instance, index .. instance ) )
+
+ -- push arg stack to definition list
+ _ti( defs, _args )
+
+ -- reset stacks
+ _args = { }
+ _stack_pos = { }
+ _stack_neg = { }
+ end
+
+ return defs
+end
+
+function Graph.render( self, plugin, plugin_instance, is_index )
+
+ dtype_instances = dtype_instances or { "" }
+ local pngs = { }
+
+ -- check for a whole graph handler
+ local plugin_def = "luci.statistics.rrdtool.definitions." .. plugin
+ local stat, def = pcall( require, plugin_def )
+
+ if stat and def and type(def.rrdargs) == "function" then
+
+ -- temporary image matrix
+ local _images = { }
+
+ -- get diagram definitions
+ for i, opts in ipairs( self:_forcelol( def.rrdargs( self, plugin, plugin_instance, nil, is_index ) ) ) do
+ if not is_index or not opts.detail then
+ _images[i] = { }
+
+ -- get diagram definition instances
+ local diagrams = self:_generic( opts, plugin, plugin_instance, nil, i )
+
+ -- render all diagrams
+ for j, def in ipairs( diagrams ) do
+ -- remember image
+ _images[i][j] = def[1]
+
+ -- exec
+ self:_rrdtool( def )
+ end
+ end
+ end
+
+ -- remember images - XXX: fixme (will cause probs with asymmetric data)
+ for y = 1, #_images[1] do
+ for x = 1, #_images do
+ table.insert( pngs, _images[x][y] )
+ end
+ end
+ end
+
+ return pngs
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/colors.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/colors.lua
new file mode 100644
index 0000000000..2da9f5a08a
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/colors.lua
@@ -0,0 +1,73 @@
+--[[
+
+Luci statistics - diagram color helper class
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+module("luci.statistics.rrdtool.colors", package.seeall)
+
+require("luci.util")
+
+
+Instance = luci.util.class()
+
+function Instance.from_string( self, s )
+ return {
+ tonumber(s:sub(1,2), 16),
+ tonumber(s:sub(3,4), 16),
+ tonumber(s:sub(5,6), 16)
+ }
+end
+
+function Instance.to_string( self, c )
+ return string.format(
+ "%02x%02x%02x",
+ math.floor(c[1]),
+ math.floor(c[2]),
+ math.floor(c[3])
+ )
+end
+
+function Instance.random( self )
+ local r = math.random(255)
+ local g = math.random(255)
+ local min = 0
+ local max = 255
+
+ if ( r + g ) < 255 then
+ min = 255 - r - g
+ else
+ max = 511 - r - g
+ end
+
+ local b = min + math.floor( math.random() * ( max - min ) )
+
+ return { r, g, b }
+end
+
+function Instance.faded( self, fg, opts )
+ opts = opts or {}
+ opts.background = opts.background or { 255, 255, 255 }
+ opts.alpha = opts.alpha or 0.25
+
+ if type(opts.background) == "string" then
+ opts.background = _string_to_color(opts.background)
+ end
+
+ local bg = opts.background
+
+ return {
+ ( opts.alpha * fg[1] ) + ( ( 1.0 - opts.alpha ) * bg[1] ),
+ ( opts.alpha * fg[2] ) + ( ( 1.0 - opts.alpha ) * bg[2] ),
+ ( opts.alpha * fg[3] ) + ( ( 1.0 - opts.alpha ) * bg[3] )
+ }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/conntrack.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/conntrack.lua
new file mode 100644
index 0000000000..0da546c0b4
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/conntrack.lua
@@ -0,0 +1,35 @@
+--[[
+
+Luci statistics - conntrack plugin diagram definition
+(c) 2011 Jo-Philipp Wich <xm@subsignal.org>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+module("luci.statistics.rrdtool.definitions.conntrack",package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+ return {
+ title = "%H: Conntrack entries",
+ vlabel = "Count",
+ number_format = "%5.0lf",
+ data = {
+ sources = {
+ conntrack = { "value" }
+ },
+ options = {
+ conntrack = {
+ color = "0000ff",
+ title = "Tracked connections"
+ }
+ }
+ }
+ }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua
new file mode 100644
index 0000000000..c0e86245c0
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua
@@ -0,0 +1,42 @@
+--[[
+
+Luci statistics - cpu plugin diagram definition
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id: cpu.lua 2274 2008-06-03 23:15:16Z jow $
+
+]]--
+
+module("luci.statistics.rrdtool.definitions.cpu",package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+
+ return {
+ title = "%H: Processor usage on core #%pi",
+ y_min = "0",
+ vlabel = "Percent",
+ number_format = "%5.1lf%%",
+ data = {
+ instances = {
+ cpu = { "idle", "user", "system", "nice" }
+ },
+
+ options = {
+ cpu_idle = { color = "ffffff" },
+ cpu_nice = { color = "00e000" },
+ cpu_user = { color = "0000ff" },
+ cpu_wait = { color = "ffb000" },
+ cpu_system = { color = "ff0000" },
+ cpu_softirq = { color = "ff00ff" },
+ cpu_interrupt = { color = "a000a0" },
+ cpu_steal = { color = "000000" }
+ }
+ }
+ }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/df.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/df.lua
new file mode 100644
index 0000000000..fa206badbd
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/df.lua
@@ -0,0 +1,46 @@
+--[[
+
+Luci statistics - df plugin diagram definition
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id: df.lua 2274 2008-06-03 23:15:16Z jow $
+
+]]--
+
+module("luci.statistics.rrdtool.definitions.df", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+
+ return {
+ title = "%H: Disk space usage on %di",
+ vlabel = "Bytes",
+ per_instance = true,
+ number_format = "%5.1lf%sB",
+
+ data = {
+ sources = {
+ df = { "free", "used" }
+ },
+
+ options = {
+ df__free = {
+ color = "00ff00",
+ overlay = false,
+ title = "free"
+ },
+
+ df__used = {
+ color = "ff0000",
+ overlay = false,
+ title = "used"
+ }
+ }
+ }
+ }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/disk.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/disk.lua
new file mode 100644
index 0000000000..ebc37ef3a4
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/disk.lua
@@ -0,0 +1,74 @@
+--[[
+
+Luci statistics - df plugin diagram definition
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id: df.lua 2274 2008-06-03 23:15:16Z jow $
+
+]]--
+
+module("luci.statistics.rrdtool.definitions.disk", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+ return {
+ {
+ title = "%H: Disk I/O operations on %pi",
+ vlabel = "Operations/s",
+ number_format = "%5.1lf%sOp/s",
+
+ data = {
+ types = { "disk_ops" },
+ sources = {
+ disk_ops = { "read", "write" },
+ },
+
+ options = {
+ disk_ops__read = {
+ title = "Reads",
+ color = "00ff00",
+ flip = false
+ },
+
+ disk_ops__write = {
+ title = "Writes",
+ color = "ff0000",
+ flip = true
+ }
+ }
+ }
+ },
+
+ {
+ title = "%H: Disk I/O bandwidth on %pi",
+ vlabel = "Bytes/s",
+ number_format = "%5.1lf%sB/s",
+
+ detail = true,
+
+ data = {
+ types = { "disk_octets" },
+ sources = {
+ disk_octets = { "read", "write" }
+ },
+ options = {
+ disk_octets__read = {
+ title = "Read",
+ color = "00ff00",
+ flip = false
+ },
+ disk_octets__write = {
+ title = "Write",
+ color = "ff0000",
+ flip = true
+ }
+ }
+ }
+ }
+ }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/dns.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/dns.lua
new file mode 100644
index 0000000000..94a148d810
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/dns.lua
@@ -0,0 +1,81 @@
+--[[
+
+Luci statistics - dns plugin diagram definition
+
+Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+]]--
+
+module("luci.statistics.rrdtool.definitions.dns", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance )
+
+ local traffic = {
+ title = "%H: DNS traffic", vlabel = "Bit/s",
+
+ data = {
+ sources = {
+ dns_octets = { "queries", "responses" }
+ },
+
+ options = {
+ dns_octets__responses = {
+ total = true,
+ color = "00ff00",
+ title = "Responses"
+ },
+
+ dns_octets__queries = {
+ total = true,
+ color = "0000ff",
+ title = "Queries"
+ }
+ }
+ }
+ }
+
+ local opcode_query = {
+ title = "%H: DNS Opcode Query", vlabel = "Queries/s",
+ data = {
+ instances = { dns_opcode = { "Query" } },
+ options = {
+ dns_opcode_Query_value = {
+ total = true,
+ color = "0000ff",
+ title = "Queries/s"
+ },
+ }
+ }
+ }
+
+ local qtype = {
+ title = "%H: DNS QType", vlabel = "Queries/s",
+ data = {
+ sources = { dns_qtype = { "" } },
+ options = {
+ dns_qtype_AAAA_ = { title = "AAAA", noarea = true, total = true },
+ dns_qtype_A_ = { title = "A", noarea = true, total = true },
+ dns_qtype_A6_ = { title = "A6", noarea = true, total = true },
+ dns_qtype_TXT_ = { title = "TXT", noarea = true, total = true },
+ dns_qtype_MX_ = { title = "MX", noarea = true, total = true },
+ dns_qtype_NS_ = { title = "NS", noarea = true, total = true },
+ dns_qtype_ANY_ = { title = "ANY", noarea = true, total = true },
+ dns_qtype_CNAME_= { title = "CNAME", noarea = true, total = true },
+ dns_qtype_SOA_ = { title = "SOA", noarea = true, total = true },
+ dns_qtype_SRV_ = { title = "SRV", noarea = true, total = true },
+ dns_qtype_PTR_ = { title = "PTR", noarea = true, total = true },
+ dns_qtype_RP_ = { title = "RP", noarea = true, total = true },
+ dns_qtype_MAILB_= { title = "MAILB", noarea = true, total = true },
+ dns_qtype_IXFR_ = { title = "IXFR", noarea = true, total = true },
+ dns_qtype_HINFO_= { title = "HINFO", noarea = true, total = true },
+ },
+ }
+ }
+
+ return { traffic, opcode_query, qtype }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/interface.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/interface.lua
new file mode 100644
index 0000000000..a6f3b5c6a6
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/interface.lua
@@ -0,0 +1,117 @@
+--[[
+
+Luci statistics - interface plugin diagram definition
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+module("luci.statistics.rrdtool.definitions.interface", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance )
+
+ --
+ -- traffic diagram
+ --
+ local traffic = {
+
+ -- draw this diagram for each plugin instance
+ per_instance = true,
+ title = "%H: Transfer on %pi",
+ vlabel = "Bytes/s",
+
+ -- diagram data description
+ data = {
+ -- defined sources for data types, if ommitted assume a single DS named "value" (optional)
+ sources = {
+ if_octets = { "tx", "rx" }
+ },
+
+ -- special options for single data lines
+ options = {
+ if_octets__tx = {
+ total = true, -- report total amount of bytes
+ color = "00ff00", -- tx is green
+ title = "Bytes (TX)"
+ },
+
+ if_octets__rx = {
+ flip = true, -- flip rx line
+ total = true, -- report total amount of bytes
+ color = "0000ff", -- rx is blue
+ title = "Bytes (RX)"
+ }
+ }
+ }
+ }
+
+
+ --
+ -- packet diagram
+ --
+ local packets = {
+
+ -- draw this diagram for each plugin instance
+ per_instance = true,
+ title = "%H: Packets on %pi",
+ vlabel = "Packets/s",
+
+ -- diagram data description
+ data = {
+ -- data type order
+ types = { "if_packets", "if_errors" },
+
+ -- defined sources for data types
+ sources = {
+ if_packets = { "tx", "rx" },
+ if_errors = { "tx", "rx" }
+ },
+
+ -- special options for single data lines
+ options = {
+ -- processed packets (tx DS)
+ if_packets__tx = {
+ overlay = true, -- don't summarize
+ total = true, -- report total amount of bytes
+ color = "00ff00", -- processed tx is green
+ title = "Processed (tx)"
+ },
+
+ -- processed packets (rx DS)
+ if_packets__rx = {
+ overlay = true, -- don't summarize
+ flip = true, -- flip rx line
+ total = true, -- report total amount of bytes
+ color = "0000ff", -- processed rx is blue
+ title = "Processed (rx)"
+ },
+
+ -- packet errors (tx DS)
+ if_errors__tx = {
+ overlay = true, -- don't summarize
+ total = true, -- report total amount of packets
+ color = "ff5500", -- tx errors are orange
+ title = "Errors (tx)"
+ },
+
+ -- packet errors (rx DS)
+ if_errors__rx = {
+ overlay = true, -- don't summarize
+ flip = true, -- flip rx line
+ total = true, -- report total amount of packets
+ color = "ff0000", -- rx errors are red
+ title = "Errors (rx)"
+ }
+ }
+ }
+ }
+
+ return { traffic, packets }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/iptables.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/iptables.lua
new file mode 100644
index 0000000000..c1adbdc619
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/iptables.lua
@@ -0,0 +1,53 @@
+--[[
+
+Luci statistics - iptables plugin diagram definition
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id: ipt_bytes.lua 2276 2008-06-03 23:18:37Z jow $
+
+]]--
+
+module("luci.statistics.rrdtool.definitions.iptables", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+
+ return {
+ {
+ title = "%H: Firewall: Processed bytes in %pi",
+ vlabel = "Bytes/s",
+ number_format = "%5.0lf%sB/s",
+ totals_format = "%5.0lf%sB",
+ data = {
+ types = { "ipt_bytes" },
+ options = {
+ ipt_bytes = {
+ total = true,
+ title = "%di"
+ }
+ }
+ }
+ },
+
+ {
+ title = "%H: Firewall: Processed packets in %pi",
+ vlabel = "Packets/s",
+ number_format = "%5.1lf P/s",
+ totals_format = "%5.0lf%s",
+ data = {
+ types = { "ipt_packets" },
+ options = {
+ ipt_packets = {
+ total = true,
+ title = "%di"
+ }
+ }
+ }
+ }
+ }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/irq.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/irq.lua
new file mode 100644
index 0000000000..aabe14a037
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/irq.lua
@@ -0,0 +1,30 @@
+--[[
+
+Luci statistics - irq plugin diagram definition
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id: irq.lua 2276 2008-06-03 23:18:37Z jow $
+
+]]--
+
+module("luci.statistics.rrdtool.definitions.irq", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+
+ return {
+ title = "%H: Interrupts", vlabel = "Issues/s",
+ number_format = "%5.0lf", data = {
+ types = { "irq" },
+ options = {
+ irq = { title = "IRQ %di", noarea = true }
+ }
+ }
+ }
+
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/iwinfo.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/iwinfo.lua
new file mode 100644
index 0000000000..0c6eed9936
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/iwinfo.lua
@@ -0,0 +1,102 @@
+--[[
+
+Luci statistics - wireless plugin diagram definition
+(c) 2011 Jo-Philipp Wich <xm@subsignal.org>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+module("luci.statistics.rrdtool.definitions.iwinfo", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance )
+
+ --
+ -- signal/noise diagram
+ --
+ local snr = {
+ title = "%H: Signal and noise on %pi",
+ vlabel = "dBm",
+ number_format = "%5.1lf dBm",
+ data = {
+ types = { "signal_noise", "signal_power" },
+ options = {
+ signal_power = {
+ title = "Signal",
+ overlay = true,
+ color = "0000ff"
+ },
+ signal_noise = {
+ title = "Noise",
+ overlay = true,
+ color = "ff0000"
+ }
+ }
+ }
+ }
+
+
+ --
+ -- signal quality diagram
+ --
+ local quality = {
+ title = "%H: Signal quality on %pi",
+ vlabel = "Quality",
+ number_format = "%3.0lf",
+ data = {
+ types = { "signal_quality" },
+ options = {
+ signal_quality = {
+ title = "Quality",
+ noarea = true,
+ color = "0000ff"
+ }
+ }
+ }
+ }
+
+
+ --
+ -- phy rate diagram
+ --
+ local bitrate = {
+ title = "%H: Average phy rate on %pi",
+ vlabel = "MBit/s",
+ number_format = "%5.1lf%sBit/s",
+ data = {
+ types = { "bitrate" },
+ options = {
+ bitrate = {
+ title = "Rate",
+ color = "00ff00"
+ }
+ }
+ }
+ }
+
+ --
+ -- associated stations
+ --
+ local stations = {
+ title = "%H: Associated stations on %pi",
+ vlabel = "Stations",
+ number_format = "%3.0lf",
+ data = {
+ types = { "stations" },
+ options = {
+ stations = {
+ title = "Stations",
+ color = "0000ff"
+ }
+ }
+ }
+ }
+
+ return { snr, quality, bitrate, stations }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/load.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/load.lua
new file mode 100644
index 0000000000..4cb4795ef6
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/load.lua
@@ -0,0 +1,36 @@
+--[[
+
+Luci statistics - load plugin diagram definition
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id: load.lua 2329 2008-06-08 21:51:55Z jow $
+
+]]--
+
+module("luci.statistics.rrdtool.definitions.load", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+
+ return {
+ title = "%H: Load", vlabel = "Load",
+ y_min = "0",
+ units_exponent = "0",
+ number_format = "%5.2lf", data = {
+ sources = {
+ load = { "shortterm", "midterm", "longterm" }
+ },
+
+ options = {
+ load__shortterm = { color = "ff0000", title = "1 minute", noarea = true },
+ load__midterm = { color = "ff6600", title = "5 minutes", noarea = true },
+ load__longterm = { color = "ffaa00", title = "15 minutes", noarea = true }
+ }
+ }
+ }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/memory.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/memory.lua
new file mode 100644
index 0000000000..a1c65f56d7
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/memory.lua
@@ -0,0 +1,33 @@
+--[[
+
+(c) 2011 Manuel Munz <freifunk at somakoma dot de>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+]]--
+
+module("luci.statistics.rrdtool.definitions.memory",package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+
+ return {
+ title = "%H: Memory usage",
+ vlabel = "MB",
+ number_format = "%5.1lf%s",
+ data = {
+ instances = {
+ memory = { "free", "buffered", "cached", "used" }
+ },
+
+ options = {
+ memory_buffered = { color = "0000ff", title = "Buffered" },
+ memory_cached = { color = "ff00ff", title = "Cached" },
+ memory_used = { color = "ff0000", title = "Used" },
+ memory_free = { color = "00ff00", title = "Free" }
+ }
+ }
+ }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/netlink.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/netlink.lua
new file mode 100644
index 0000000000..9313952518
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/netlink.lua
@@ -0,0 +1,203 @@
+--[[
+
+Luci statistics - netlink plugin diagram definition
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+module("luci.statistics.rrdtool.definitions.netlink", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance )
+
+ --
+ -- traffic diagram
+ --
+ local traffic = {
+ title = "%H: Netlink - Transfer on %pi",
+ vlabel = "Bytes/s",
+
+ -- diagram data description
+ data = {
+ -- defined sources for data types, if ommitted assume a single DS named "value" (optional)
+ sources = {
+ if_octets = { "tx", "rx" }
+ },
+
+ -- special options for single data lines
+ options = {
+ if_octets__tx = {
+ total = true, -- report total amount of bytes
+ color = "00ff00" -- tx is green
+ },
+
+ if_octets__rx = {
+ flip = true, -- flip rx line
+ total = true, -- report total amount of bytes
+ color = "0000ff" -- rx is blue
+ }
+ }
+ }
+ }
+
+
+ --
+ -- packet diagram
+ --
+ local packets = {
+ title = "%H: Netlink - Packets on %pi",
+ vlabel = "Packets/s", detail = true,
+
+ -- diagram data description
+ data = {
+ -- data type order
+ types = { "if_packets", "if_dropped", "if_errors" },
+
+ -- defined sources for data types
+ sources = {
+ if_packets = { "tx", "rx" },
+ if_dropped = { "tx", "rx" },
+ if_errors = { "tx", "rx" }
+ },
+
+ -- special options for single data lines
+ options = {
+ -- processed packets (tx DS)
+ if_packets__tx = {
+ overlay = true, -- don't summarize
+ total = true, -- report total amount of bytes
+ color = "00ff00" -- processed tx is green
+ },
+
+ -- processed packets (rx DS)
+ if_packets__rx = {
+ overlay = true, -- don't summarize
+ flip = true, -- flip rx line
+ total = true, -- report total amount of bytes
+ color = "0000ff" -- processed rx is blue
+ },
+
+ -- dropped packets (tx DS)
+ if_dropped__tx = {
+ overlay = true, -- don't summarize
+ total = true, -- report total amount of bytes
+ color = "660055" -- dropped tx is ... dunno ;)
+ },
+
+ -- dropped packets (rx DS)
+ if_dropped__rx = {
+ overlay = true, -- don't summarize
+ flip = true, -- flip rx line
+ total = true, -- report total amount of bytes
+ color = "440066" -- dropped rx is violett
+ },
+
+ -- packet errors (tx DS)
+ if_errors__tx = {
+ overlay = true, -- don't summarize
+ total = true, -- report total amount of packets
+ color = "ff5500" -- tx errors are orange
+ },
+
+ -- packet errors (rx DS)
+ if_errors__rx = {
+ overlay = true, -- don't summarize
+ flip = true, -- flip rx line
+ total = true, -- report total amount of packets
+ color = "ff0000" -- rx errors are red
+ }
+ }
+ }
+ }
+
+
+ --
+ -- multicast diagram
+ --
+ local multicast = {
+ title = "%H: Netlink - Multicast on %pi",
+ vlabel = "Packets/s", detail = true,
+
+ -- diagram data description
+ data = {
+ -- data type order
+ types = { "if_multicast" },
+
+ -- special options for single data lines
+ options = {
+ -- multicast packets
+ if_multicast = {
+ total = true, -- report total amount of packets
+ color = "0000ff" -- multicast is blue
+ }
+ }
+ }
+ }
+
+
+ --
+ -- collision diagram
+ --
+ local collisions = {
+ title = "%H: Netlink - Collisions on %pi",
+ vlabel = "Collisions/s", detail = true,
+
+ -- diagram data description
+ data = {
+ -- data type order
+ types = { "if_collisions" },
+
+ -- special options for single data lines
+ options = {
+ -- collision rate
+ if_collisions = {
+ total = true, -- report total amount of packets
+ color = "ff0000" -- collsions are red
+ }
+ }
+ }
+ }
+
+
+ --
+ -- error diagram
+ --
+ local errors = {
+ title = "%H: Netlink - Errors on %pi",
+ vlabel = "Errors/s", detail = true,
+
+ -- diagram data description
+ data = {
+ -- data type order
+ types = { "if_tx_errors", "if_rx_errors" },
+
+ -- data type instances
+ instances = {
+ if_tx_errors = { "aborted", "carrier", "fifo", "heartbeat", "window" },
+ if_rx_errors = { "length", "missed", "over", "crc", "fifo", "frame" }
+ },
+
+ -- special options for single data lines
+ options = { -- XXX: fixme (define colors...)
+ if_tx_errors = {
+ total = true
+ },
+
+ if_rx_errors = {
+ flip = true,
+ total = true
+ }
+ }
+ }
+ }
+
+
+ return { traffic, packets, multicast, collisions, errors }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/nut.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/nut.lua
new file mode 100644
index 0000000000..69f1ae305c
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/nut.lua
@@ -0,0 +1,106 @@
+--[[
+
+Luci statistics - ups plugin diagram definition
+Copyright © 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+Copyright © 2012 David Woodhouse <dwmw2@infradead.org>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+]]--
+
+
+module("luci.statistics.rrdtool.definitions.nut",package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+
+ local voltages = {
+ title = "%H: Voltages on UPS \"%pi\"",
+ vlabel = "V",
+ number_format = "%5.1lfV",
+ data = {
+ instances = {
+ voltage = { "battery", "input", "output" }
+ },
+
+ options = {
+ voltage_output = { color = "00e000", title = "Output voltage", noarea=true, overlay=true },
+ voltage_battery = { color = "0000ff", title = "Battery voltage", noarea=true, overlay=true },
+ voltage_input = { color = "ffb000", title = "Input voltage", noarea=true, overlay=true }
+ }
+ }
+ }
+
+ local currents = {
+ title = "%H: Current on UPS \"%pi\"",
+ vlabel = "A",
+ number_format = "%5.3lfA",
+ data = {
+ instances = {
+ current = { "battery", "output" }
+ },
+
+ options = {
+ current_output = { color = "00e000", title = "Output current", noarea=true, overlay=true },
+ current_battery = { color = "0000ff", title = "Battery current", noarea=true, overlay=true },
+ }
+ }
+ }
+
+ local percentage = {
+ title = "%H: Battery charge on UPS \"%pi\"",
+ vlabel = "Percent",
+ y_min = "0",
+ y_max = "100",
+ number_format = "%5.1lf%%",
+ data = {
+ sources = {
+ percent = { "percent" }
+ },
+ instances = {
+ percent = "charge"
+ },
+ options = {
+ percent_charge = { color = "00ff00", title = "Charge level" }
+ }
+ }
+ }
+
+ -- Note: This is in ISO8859-1 for rrdtool. Welcome to the 20th century.
+ local temperature = {
+ title = "%H: Battery temperature on UPS \"%pi\"",
+ vlabel = "\176C",
+ number_format = "%5.1lf\176C",
+ data = {
+ instances = {
+ temperature = "battery"
+ },
+
+ options = {
+ temperature_battery = { color = "ffb000", title = "Battery temperature" }
+ }
+ }
+ }
+
+ local timeleft = {
+ title = "%H: Time left on UPS \"%pi\"",
+ vlabel = "Minutes",
+ number_format = "%.1lfm",
+ data = {
+ sources = {
+ timeleft = { "timeleft" }
+ },
+ instances = {
+ timeleft = { "battery" }
+ },
+ options = {
+ timeleft_battery = { color = "0000ff", title = "Time left", transform_rpn = "60,/" }
+ }
+ }
+ }
+
+ return { voltages, currents, percentage, temperature, timeleft }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/olsrd.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/olsrd.lua
new file mode 100644
index 0000000000..3ca2f03ec8
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/olsrd.lua
@@ -0,0 +1,146 @@
+--[[
+
+Luci statistics - olsrd plugin diagram definition
+
+Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+]]--
+
+module("luci.statistics.rrdtool.definitions.olsrd", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+ local g = { }
+
+ if plugin_instance == "routes" then
+
+ g[#g+1] = {
+ -- diagram data description
+ title = "%H: Total amount of OLSR routes", vlabel = "n",
+ number_format = "%5.0lf", data = {
+ types = { "routes" },
+ options = {
+ routes = {
+ color = "ff0000",
+ title = "Total number of routes"
+ }
+ }
+ }
+ }
+
+ g[#g+1] = {
+ title = "%H: Average route ETX", vlabel = "ETX", detail = true,
+ number_format = "%5.1lf",data = {
+ instances = { "average" }, -- falls es irgendwann mal welche pro ip gibt, wie bei links, dann werden die hier excludiert
+ types = { "route_etx" },
+ options = {
+ route_etx = {
+ title = "Average route ETX"
+ }
+ }
+ }
+ }
+
+ g[#g+1] = {
+ title = "%H: Average route metric", vlabel = "metric", detail = true,
+ number_format = "%5.1lf", data = {
+ instances = { "average" }, -- falls es irgendwann mal welche pro ip gibt, wie bei links, dann werden die hier excludiert
+ types = { "route_metric" },
+ options = {
+ route_metric = {
+ title = "Average route metric"
+ }
+ }
+ }
+ }
+
+ elseif plugin_instance == "links" then
+
+ g[#g+1] = {
+ -- diagram data description
+ title = "%H: Total amount of OLSR neighbours", vlabel = "n",
+ number_format = "%5.0lf", data = {
+ instances = { "" },
+ types = { "links" },
+ options = {
+ links = {
+ color = "00ff00",
+ title = "Number of neighbours"
+ }
+ }
+ }
+ }
+
+ local instances = graph.tree:data_instances(plugin, plugin_instance, "signal_quality")
+ table.sort(instances)
+
+ -- define one diagram per host, containing the rx and lq values
+ local i
+ for i = 1, #instances, 2 do
+ local dsn1 = "signal_quality_%s_value" % instances[i]:gsub("[^%w]+", "_")
+ local dsn2 = "signal_quality_%s_value" % instances[i+1]:gsub("[^%w]+", "_")
+ local host = instances[i]:match("^[^%-]+%-([^%-]+)%-.+")
+
+ g[#g+1] = {
+ title = "%H: Signal Quality" .. " (" .. (host or "avg") ..")", vlabel = "ETX",
+ number_format = "%5.2lf", detail = true,
+ data = {
+ types = { "signal_quality" },
+
+ instances = {
+ signal_quality = { instances[i], instances[i+1] },
+ },
+
+ options = {
+ [dsn1] = {
+ color = "00ff00",
+ title = "LQ (%s)" % (host or "avg"),
+ },
+ [dsn2] = {
+ color = "0000ff",
+ title = "NLQ (%s)" % (host or "avg"),
+ flip = true
+ }
+ }
+ }
+ }
+ end
+
+ elseif plugin_instance == "topology" then
+
+ g[#g+1] = {
+ title= "%H: Total amount of OLSR links", vlabel = "n",
+ number_format = "%5.0lf", data = {
+ instances = { "" },
+ types = { "links" },
+ options = {
+ links = {
+ color = "0000ff",
+ title = "Total number of links"
+ }
+ }
+ }
+ }
+
+ g[#g+1] = {
+ title= "%H: Average signal quality", vlabel = "n",
+ number_format = "%5.2lf", detail = true,
+ data = {
+ instances = { "average" }, -- exclude possible per-ip stuff
+ types = { "signal_quality" },
+ options = {
+ signal_quality = {
+ color = "0000ff",
+ title = "Average signal quality"
+ }
+ }
+ }
+ }
+ end
+
+ return g
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/ping.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/ping.lua
new file mode 100644
index 0000000000..bdffc85997
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/ping.lua
@@ -0,0 +1,41 @@
+--[[
+
+Luci statistics - ping plugin diagram definition
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id: ping.lua 6810 2011-01-29 03:33:48Z jow $
+
+]]--
+
+module("luci.statistics.rrdtool.definitions.ping", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+ return {
+ -- Ping roundtrip time
+ { title = "%H: ICMP Round Trip Time", vlabel = "ms",
+ number_format = "%5.1lf ms", data = {
+ sources = { ping = { "value" } },
+ options = { ping__ping = { noarea = true, title = "%di" } }
+ } },
+
+ -- Ping droprate
+ { title = "%H: ICMP Drop Rate", vlabel = "%",
+ number_format = "%5.2lf %%", data = {
+ types = { "ping_droprate" },
+ options = { ping_droprate = { title = "%di" } }
+ } },
+
+ -- Ping standard deviation
+ { title = "%H: ICMP Standard Deviation", vlabel = "ms",
+ number_format = "%5.2lf ms", data = {
+ types = { "ping_stddev" },
+ options = { ping_stddev = { title = "%di" } }
+ } },
+ }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/processes.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/processes.lua
new file mode 100644
index 0000000000..6f83c8e283
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/processes.lua
@@ -0,0 +1,110 @@
+--[[
+
+Luci statistics - processes plugin diagram definition
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+]]--
+
+module("luci.statistics.rrdtool.definitions.processes", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+
+ return {
+ {
+ title = "%H: Processes",
+ vlabel = "Processes/s",
+ 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" }
+ }
+ }
+ },
+
+ {
+ title = "%H: CPU time used by %pi",
+ vlabel = "Jiffies",
+ data = {
+ sources = {
+ ps_cputime = { "syst", "user" }
+ },
+
+ options = {
+ ps_cputime__user = {
+ color = "0000ff",
+ overlay = true
+ },
+
+ ps_cputime__syst = {
+ color = "ff0000",
+ overlay = true
+ }
+ }
+ }
+ },
+
+ {
+ title = "%H: Threads and processes belonging to %pi",
+ vlabel = "Count",
+ detail = true,
+ data = {
+ sources = {
+ ps_count = { "threads", "processes" }
+ },
+
+ options = {
+ ps_count__threads = { color = "00ff00" },
+ ps_count__processes = { color = "0000bb" }
+ }
+ }
+ },
+
+ {
+ title = "%H: Page faults in %pi",
+ vlabel = "Pagefaults",
+ detail = true,
+ data = {
+ sources = {
+ ps_pagefaults = { "minflt", "majflt" }
+ },
+
+ options = {
+ ps_pagefaults__minflt = { color = "ff0000" },
+ ps_pagefaults__majflt = { color = "ff5500" }
+ }
+ }
+ },
+
+ {
+ title = "%H: Virtual memory size of %pi",
+ vlabel = "Bytes",
+ detail = true,
+ number_format = "%5.1lf%sB",
+ data = {
+ types = { "ps_rss" },
+
+ options = {
+ ps_rss = { color = "0000ff" }
+ }
+ }
+ }
+ }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/splash_leases.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/splash_leases.lua
new file mode 100644
index 0000000000..69f3c113cd
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/splash_leases.lua
@@ -0,0 +1,37 @@
+--[[
+
+Luci statistics - splash_leases plugin diagram definition
+(c) 2013 Freifunk Augsburg / Michael Wendland <michael@michiwend.com>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+
+]]--
+
+module("luci.statistics.rrdtool.definitions.splash_leases", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+
+ return {
+ title = "%H: Splash Leases",
+ vlabel = "Active Clients",
+ y_min = "0",
+ number_format = "%5.1lf",
+ data = {
+ sources = {
+ splash_leases = { "leased", "whitelisted", "blacklisted" }
+ },
+
+ options = {
+ splash_leases__leased = { color = "00CC00", title = "Leased", overlay = false },
+ splash_leases__whitelisted = { color = "0000FF", title = "Whitelisted", overlay = false },
+ splash_leases__blacklisted = { color = "FF0000", title = "Blacklisted", overlay = false }
+ }
+ }
+ }
+
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/tcpconns.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/tcpconns.lua
new file mode 100644
index 0000000000..4f1c221f9b
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/tcpconns.lua
@@ -0,0 +1,37 @@
+--[[
+
+Luci statistics - tcpconns plugin diagram definition
+(c) 2008 Freifunk Leipzig / Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id: tcp_connections.lua 2274 2008-06-03 23:15:16Z jow $
+
+]]--
+
+module("luci.statistics.rrdtool.definitions.tcpconns", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+ return {
+ title = "%H: TCP connections to port %pi",
+ vlabel = "Connections/s",
+ number_format = "%5.0lf",
+ data = {
+ types = { "tcp_connections" },
+ instances = {
+ tcp_connections = {
+ "SYN_SENT", "SYN_RECV", "LISTEN", "ESTABLISHED",
+ "LAST_ACK", "TIME_WAIT", "CLOSING", "CLOSE_WAIT",
+ "CLOSED", "FIN_WAIT1", "FIN_WAIT2"
+ },
+ options = {
+ load__ESTABLISHED = { title = "%di", noarea = true }
+ }
+ }
+ }
+ }
+end
diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/uptime.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/uptime.lua
new file mode 100644
index 0000000000..077ec57e83
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/uptime.lua
@@ -0,0 +1,27 @@
+--[[
+
+Copyright 2013 Thomas Endt <tmo26@gmx.de>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+]]--
+
+module("luci.statistics.rrdtool.definitions.uptime", package.seeall)
+
+function rrdargs( graph, plugin, plugin_instance, dtype )
+
+ return {
+ title = "%H: Uptime", vlabel = "seconds",
+ number_format = "%5.0lf%s", data = {
+ types = { "uptime" },
+ options = {
+ uptime = { title = "Uptime %di", noarea = true }
+ }
+ }
+ }
+
+end
+
diff --git a/applications/luci-app-statistics/luasrc/view/admin_statistics/index.htm b/applications/luci-app-statistics/luasrc/view/admin_statistics/index.htm
new file mode 100644
index 0000000000..25157da40a
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/view/admin_statistics/index.htm
@@ -0,0 +1,22 @@
+<%#
+LuCI - Lua Configuration Interface
+Copyright 2008 Steven Barth <steven@midlink.org>
+Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+-%>
+<%+header%>
+
+<h2><a id="content" name="content"><%:Statistics%></a></h2>
+
+<p><%_The statistics package is based on <a href="http://collectd.org/index.shtml">Collectd</a>
+and uses <a href="http://oss.oetiker.ch/rrdtool/">RRD Tool</a> to render diagram images from collected data.%></p>
+
+<%+footer%>
diff --git a/applications/luci-app-statistics/luasrc/view/public_statistics/graph.htm b/applications/luci-app-statistics/luasrc/view/public_statistics/graph.htm
new file mode 100644
index 0000000000..8a8256bbbf
--- /dev/null
+++ b/applications/luci-app-statistics/luasrc/view/public_statistics/graph.htm
@@ -0,0 +1,48 @@
+<%#
+LuCI - Lua Configuration Interface
+Copyright 2008 Steven Barth <steven@midlink.org>
+Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+$Id$
+
+-%>
+<%+header%>
+
+<h2><a id="content" name="content"><%:Statistics%></a></h2>
+
+<form action="" method="get">
+ <select name="host">
+ <% for i, host in ipairs(hosts) do %>
+ <option<% if host == current_host then %> selected="selected"<% end %>><%=pcdata(host)%></option>
+ <% end %>
+ </select>
+ <input class="cbi-button cbi-button-apply" type="submit" name="submit" value="<%:Display Host »%>" />
+ <select name="timespan">
+ <% for i, span in ipairs(timespans) do %>
+ <option<% if span == current_timespan then %> selected="selected"<% end %>><%=span%></option>
+ <% end %>
+ </select>
+ <input class="cbi-button cbi-button-apply" type="submit" name="submit" value="<%:Display timespan »%>" />
+</form>
+
+<br />
+<hr />
+<br />
+
+<div style="text-align: center">
+ <% for i, img in ipairs(images) do %>
+ <% if is_index then %><a href="<%=pcdata(images[img])%>"><% end %>
+ <img src="<%=REQUEST_URI%>?img=<%=img%>&#38;host=<%=current_host%>" />
+ <% if is_index then %></a><% end %>
+ <br />
+ <% end %>
+</div>
+
+<%+footer%>
+