summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-statistics/root
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/root
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/root')
-rw-r--r--applications/luci-app-statistics/root/etc/config/luci_statistics143
-rwxr-xr-xapplications/luci-app-statistics/root/etc/init.d/luci_statistics33
-rwxr-xr-xapplications/luci-app-statistics/root/etc/uci-defaults/luci-statistics36
-rwxr-xr-xapplications/luci-app-statistics/root/usr/bin/stat-genconfig438
4 files changed, 650 insertions, 0 deletions
diff --git a/applications/luci-app-statistics/root/etc/config/luci_statistics b/applications/luci-app-statistics/root/etc/config/luci_statistics
new file mode 100644
index 000000000..e39db3513
--- /dev/null
+++ b/applications/luci-app-statistics/root/etc/config/luci_statistics
@@ -0,0 +1,143 @@
+config 'statistics' 'rrdtool'
+ option 'default_timespan' '1hour'
+ option 'image_width' '600'
+ option 'image_path' '/tmp/rrdimg'
+
+config 'statistics' 'collectd'
+ option 'BaseDir' '/var/run/collectd'
+ option 'Include' '/etc/collectd/conf.d'
+ option 'PIDFile' '/var/run/collectd.pid'
+ option 'PluginDir' '/usr/lib/collectd'
+ option 'TypesDB' '/usr/share/collectd/types.db'
+ option 'Interval' '30'
+ option 'ReadThreads' '2'
+
+config 'statistics' 'collectd_ping'
+ option 'enable' '0'
+ option 'TTL' '127'
+ option 'Interval' '30'
+ option 'Hosts' '127.0.0.1'
+
+config 'statistics' 'collectd_csv'
+ option 'enable' '0'
+ option 'StoreRates' '0'
+ option 'DataDir' '/tmp'
+
+config 'statistics' 'collectd_df'
+ option 'enable' '0'
+ option 'Devices' '/dev/mtdblock/4'
+ option 'MountPoints' '/jffs'
+ option 'FSTypes' 'tmpfs'
+ option 'IgnoreSelected' '0'
+
+config 'statistics' 'collectd_disk'
+ option 'enable' '0'
+ option 'Disks' 'hda1 hdb'
+ option 'IgnoreSelected' '0'
+
+config 'statistics' 'collectd_dns'
+ option 'enable' '0'
+ option 'Interfaces' 'ffdhcp ff br-lan'
+ option 'IgnoreSources' '127.0.0.1'
+
+config 'statistics' 'collectd_email'
+ option 'enable' '0'
+ option 'SocketFile' '/var/run/collectd/email.sock'
+ option 'SocketGroup' 'nogroup'
+
+config 'statistics' 'collectd_exec'
+ option 'enable' '0'
+
+config 'statistics' 'collectd_interface'
+ option 'enable' '1'
+ option 'Interfaces' 'br-lan br-ff'
+ option 'IgnoreSelected' '0'
+
+config 'statistics' 'collectd_iptables'
+ option 'enable' '1'
+
+config 'collectd_iptables_match'
+ option 'table' 'nat'
+ option 'chain' 'luci_fw_postrouting'
+ option 'target' 'MASQUERADE'
+ option 'source' '192.168.1.0/24'
+ option 'outputif' 'br-ff'
+ option 'name' 'Verkehr LAN-Clients'
+
+config 'collectd_iptables_match'
+ option 'chain' 'luci_fw_postrouting'
+ option 'table' 'nat'
+ option 'target' 'MASQUERADE'
+ option 'source' '10.61.230.0/24'
+ option 'outputif' 'br-ff'
+ option 'name' 'Verkehr WLAN-Clients'
+
+config 'statistics' 'collectd_irq'
+ option 'enable' '0'
+ option 'Irqs' '2 3 4 7'
+
+config 'statistics' 'collectd_load'
+ option 'enable' '1'
+
+config 'statistics' 'collectd_logfile'
+ option 'enable' '0'
+ option 'LogLevel' 'notice'
+ option 'File' '/var/log/collectd.log'
+ option 'Timestamp' '1'
+
+config 'statistics' 'collectd_netlink'
+ option 'enable' '0'
+ option 'IgnoreSelected' '0'
+ option 'VerboseInterfaces' 'br-lan br-ff'
+ option 'QDiscs' 'br-lan br-ff'
+
+config 'statistics' 'collectd_network'
+ option 'enable' '0'
+
+config 'statistics' 'collectd_processes'
+ option 'enable' '1'
+ option 'Processes' 'uhttpd dnsmasq dropbear'
+
+config statistics 'collectd_splash_leases'
+ option enable '1'
+
+config 'statistics' 'collectd_tcpconns'
+ option 'enable' '1'
+ option 'ListeningPorts' '0'
+ option 'LocalPorts' '22 80'
+
+config 'statistics' 'collectd_unixsock'
+ option 'enable' '0'
+ option 'SocketFile' '/var/run/collectd/query.sock'
+ option 'SocketGroup' 'nogroup'
+
+config 'statistics' 'collectd_cpu'
+ option 'enable' '1'
+
+config 'statistics' 'collectd_rrdtool'
+ option 'enable' '1'
+ option 'DataDir' '/tmp/rrd'
+ option 'RRARows' '100'
+ option 'RRASingle' '1'
+ option 'RRATimespans' '1hour 1day 1week 1month 1year'
+
+config 'statistics' 'collectd_memory'
+ option 'enable' '1'
+
+config 'statistics' 'collectd_conntrack'
+ option 'enable' '1'
+
+config 'statistics' 'collectd_olsrd'
+ option 'enable' '1'
+ option 'Port' '2006'
+ option 'Host' '127.0.0.1'
+
+config 'statistics' 'collectd_iwinfo'
+ option 'enable' '1'
+
+config 'statistics' 'collectd_nut'
+ option 'enable' '0'
+ option 'UPS' 'myupsname'
+
+config 'statistics' 'collectd_uptime'
+ option 'enable' '1'
diff --git a/applications/luci-app-statistics/root/etc/init.d/luci_statistics b/applications/luci-app-statistics/root/etc/init.d/luci_statistics
new file mode 100755
index 000000000..936f3a63c
--- /dev/null
+++ b/applications/luci-app-statistics/root/etc/init.d/luci_statistics
@@ -0,0 +1,33 @@
+#!/bin/sh /etc/rc.common
+START=79
+
+start() {
+ ### replace shipped config with symlink
+ if [ ! -L /etc/collectd.conf ]; then
+ test -f /etc/collectd.conf && mv /etc/collectd.conf /etc/collectd.conf.bak
+ ln -s /var/etc/collectd.conf /etc/collectd.conf
+ fi
+
+ ### create config
+ mkdir -p /var/etc
+ /usr/bin/stat-genconfig > /var/etc/collectd.conf
+
+ ### prepare rrdimg directory
+ if [ -f /etc/config/lucid ] && [ -x /etc/init.d/lucid ] && /etc/init.d/lucid enabled && \
+ [ "$(uci get luci_statistics.rrdtool.image_path 2>/dev/null)" != "$(uci get lucid.statistics.physical 2>/dev/null)" ]; then
+ uci set lucid.statistics.physical=$(uci get luci_statistics.rrdtool.image_path)
+ uci commit lucid
+ /etc/init.d/lucid restart
+ fi
+
+ ### workaround broken permissions on /tmp
+ chmod 1777 /tmp
+}
+
+restart() {
+ ### regenerate config / prepare environment
+ start
+
+ ### restart collectd
+ /etc/init.d/collectd restart
+}
diff --git a/applications/luci-app-statistics/root/etc/uci-defaults/luci-statistics b/applications/luci-app-statistics/root/etc/uci-defaults/luci-statistics
new file mode 100755
index 000000000..e94a8637c
--- /dev/null
+++ b/applications/luci-app-statistics/root/etc/uci-defaults/luci-statistics
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+# register commit handler
+uci -q batch <<-EOF >/dev/null
+ delete ucitrack.@luci_statistics[-1]
+ add ucitrack luci_statistics
+ set ucitrack.@luci_statistics[-1].init=luci_statistics
+ commit ucitrack
+EOF
+
+# register LuCId virtual path handler
+[ -f /etc/config/lucid ] && \
+uci -q batch <<-EOF >/dev/null
+ delete lucid.statistics
+
+ set lucid.statistics=DirectoryPublisher
+ set lucid.statistics.name='RRDTool Image Cache'
+ set lucid.statistics.physical=/tmp/rrdimg
+ set lucid.statistics.virtual=/rrdimg
+ set lucid.statistics.domain=''
+
+ add_list lucid.http.publisher=statistics
+ add_list lucid.https.publisher=statistics
+
+ commit lucid
+EOF
+
+# symlink for busybox httpd
+[ -x /usr/sbin/httpd ] && [ ! -h /www/rrdimg ] && \
+ ln -s /tmp/rrdimg /www/rrdimg
+
+# restart LuCId service
+[ -x /etc/init.d/lucid ] && /etc/init.d/lucid enabled && /etc/init.d/lucid restart
+
+rm -f /tmp/luci-indexcache
+exit 0
diff --git a/applications/luci-app-statistics/root/usr/bin/stat-genconfig b/applications/luci-app-statistics/root/usr/bin/stat-genconfig
new file mode 100755
index 000000000..86773b4e5
--- /dev/null
+++ b/applications/luci-app-statistics/root/usr/bin/stat-genconfig
@@ -0,0 +1,438 @@
+#!/usr/bin/lua
+
+--[[
+
+Luci statistics - collectd configuration generator
+(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.model.uci")
+require("luci.sys.iptparser")
+require("luci.util")
+
+local ipt = luci.sys.iptparser.IptParser()
+local uci = luci.model.uci.cursor()
+local sections = uci:get_all( "luci_statistics" )
+
+
+function print(...)
+ nixio.stdout:write(...)
+ nixio.stdout:write("\n")
+end
+
+function section( plugin )
+
+ local config = sections[ "collectd_" .. plugin ] or sections["collectd"]
+
+ if type(config) == "table" and ( plugin == "collectd" or config.enable == "1" ) then
+
+ local params = ""
+
+ if type( plugins[plugin] ) == "function" then
+ params = plugins[plugin]( config )
+ else
+ params = config_generic( config, plugins[plugin][1], plugins[plugin][2], plugins[plugin][3], plugin == "collectd" )
+ end
+
+
+ if plugin ~= "collectd" then
+ print( "LoadPlugin " .. plugin )
+
+ if params:len() > 0 then
+ print( "<Plugin " .. plugin .. ">\n" .. params .. "</Plugin>\n" )
+ else
+ print( "" )
+ end
+ else
+ print( params .. "\n" )
+ end
+ end
+end
+
+function config_generic( c, singles, bools, lists, nopad )
+ local str = ""
+
+ if type(c) == "table" then
+
+ if type(singles) == "table" then
+ for i, key in ipairs( singles ) do
+ if preprocess[key] then
+ c[key] = preprocess[key](c[key])
+ end
+
+ str = str .. _string( c[key], key, nopad )
+ end
+ end
+
+ if type(bools) == "table" then
+ for i, key in ipairs( bools ) do
+ if preprocess[key] then
+ c[key] = preprocess[key](c[key])
+ end
+
+ str = str .. _bool( c[key], key, nopad )
+ end
+ end
+
+ if type(lists) == "table" then
+ str = str .. _list_expand( c, lists, nopad )
+ end
+ end
+
+ return str
+end
+
+function config_exec( c )
+ local str = ""
+
+ for s in pairs(sections) do
+ for key, type in pairs({ Exec="collectd_exec_input", NotificationExec="collectd_exec_notify" }) do
+ if sections[s][".type"] == type then
+
+ cmd = sections[s].cmdline
+
+ if cmd then
+ cmd = cmd:gsub("^%s+", ""):gsub("%s+$", "")
+ user = sections[s].cmduser or "nobody"
+ group = sections[s].cmdgroup
+
+ str = str .. "\t" .. key .. ' "' ..
+ user .. ( group and ":" .. group or "" ) .. '" "' ..
+ cmd:gsub('%s+', '" "') .. '"\n'
+ end
+ end
+ end
+ end
+
+ return str
+end
+
+function config_iptables( c )
+ local str = ""
+
+ for s in pairs(sections) do
+ if sections[s][".type"] == "collectd_iptables_match" then
+
+ search = { }
+
+ for i, k in ipairs( {
+ "table", "chain", "target", "protocol", "source", "destination",
+ "inputif", "outputif", "options"
+ } ) do
+ v = sections[s][k]
+
+ if type(v) == "string" then
+ if k == "options" then v = luci.util.split( v, "%s+", nil, true ) end
+ search[k] = v
+ end
+ end
+
+ for i, rule in ipairs( ipt:find( search ) ) do
+
+ name = sections[s].name:gsub( "%s+", "_" )
+ if i > 1 then name = name .. "_(" .. i .. ")" end
+
+ str = str .. "\tChain " .. rule.table .. " " .. rule.chain .. " " .. rule.index .. ' "' .. name .. "\"\n"
+ end
+ end
+ end
+
+ return str
+end
+
+function config_network( c )
+ local str = ""
+
+ for s in pairs(sections) do
+ for key, type in pairs({ Listen="collectd_network_listen", Server="collectd_network_server" }) do
+ if sections[s][".type"] == type then
+
+ host = sections[s].host
+ port = sections[s].port
+
+ if host then
+ if port then
+ str = str .. "\t" .. key .. " \"" .. host .. "\" \"" .. port .. "\"\n"
+ else
+ str = str .. "\t" .. key .. " \"" .. host .. "\"\n"
+ end
+ end
+ end
+ end
+ end
+
+ return str .. _string( c["TimeToLive"], "TimeToLive" )
+ .. _string( c["CacheFlush"], "CacheFlush" )
+ .. _bool( c["Forward"], "Forward" )
+end
+
+
+function _list_expand( c, l, nopad )
+ local str = ""
+
+ for i, n in ipairs(l) do
+ if c[n] then
+ if preprocess[n] then
+ c[n] = preprocess[n](c[n])
+ end
+
+ if n:find("(%w+)ses") then
+ k = n:gsub("(%w+)ses", "%1s")
+ else
+ k = n:gsub("(%w+)s", "%1")
+ end
+
+ str = str .. _expand( c[n], k, nopad )
+ end
+ end
+
+ return str
+end
+
+function _expand( s, n, nopad )
+ local str = ""
+
+ if type(s) == "string" then
+ for i, v in ipairs( luci.util.split( s, "%s+", nil, true ) ) do
+ str = str .. _string( v, n, nopad )
+ end
+ elseif type(s) == "table" then
+ for i, v in ipairs(s) do
+ str = str .. _string( v, n, nopad )
+ end
+ end
+
+ return str
+end
+
+function _bool( s, n, nopad )
+
+ local str = ""
+ local pad = ""
+ if not nopad then pad = "\t" end
+
+ if s and s == "1" then
+ str = pad .. n .. " true"
+ else
+ str = pad .. n .. " false"
+ end
+
+ return str .. "\n"
+end
+
+function _string( s, n, nopad )
+
+ local str = ""
+ local pad = ""
+ if not nopad then pad = "\t" end
+
+ if s then
+ if s:find("[^%d]") or n == "Port" then
+ if not s:find("[^%w]") and n ~= "Port" then
+ str = pad .. n .. " " .. luci.util.trim(s)
+ else
+ str = pad .. n .. ' "' .. luci.util.trim(s) .. '"'
+ end
+ else
+ str = pad .. n .. " " .. luci.util.trim(s)
+ end
+
+ str = str .. "\n"
+ end
+
+ return str
+end
+
+
+plugins = {
+ collectd = {
+ { "BaseDir", "Include", "PIDFile", "PluginDir", "TypesDB", "Interval", "ReadThreads", "Hostname" },
+ { },
+ { }
+ },
+
+ conntrack = {
+ { },
+ { },
+ { }
+ },
+
+ cpu = {
+ { },
+ { },
+ { }
+ },
+
+ csv = {
+ { "DataDir" },
+ { "StoreRates" },
+ { }
+ },
+
+ df = {
+ { },
+ { "IgnoreSelected" },
+ { "Devices", "MountPoints", "FSTypes" }
+ },
+
+ disk = {
+ { },
+ { "IgnoreSelected" },
+ { "Disks" }
+ },
+
+ dns = {
+ { },
+ { },
+ { "Interfaces", "IgnoreSources" }
+ },
+
+ email = {
+ { "SocketFile", "SocketGroup", "SocketPerms", "MaxConns" },
+ { },
+ { }
+ },
+
+ exec = config_exec,
+
+ interface = {
+ { },
+ { "IgnoreSelected" },
+ { "Interfaces" }
+ },
+
+ iptables = config_iptables,
+
+ irq = {
+ { },
+ { "IgnoreSelected" },
+ { "Irqs" }
+ },
+
+ iwinfo = {
+ { },
+ { "IgnoreSelected" },
+ { "Interfaces" }
+ },
+
+ load = {
+ { },
+ { },
+ { }
+ },
+
+ logfile = {
+ { "LogLevel", "File" },
+ { "Timestamp" },
+ { }
+ },
+
+ madwifi = {
+ { "WatchSet" },
+ { },
+ { "Interfaces", "WatchAdds" }
+ },
+
+ memory = {
+ { },
+ { },
+ { }
+ },
+
+ netlink = {
+ { },
+ { "IgnoreSelected" },
+ { "Interfaces", "VerboseInterfaces", "QDiscs", "Classes", "Filters" }
+ },
+
+ network = config_network,
+
+ nut = {
+ { "UPS" },
+ { },
+ { }
+ },
+
+ olsrd = {
+ { "Host", "Port", "CollectLinks","CollectRoutes","CollectTopology"},
+ { },
+ { }
+ },
+
+ ping = {
+ { "TTL", "Interval" },
+ { },
+ { "Hosts" }
+ },
+
+ processes = {
+ { },
+ { },
+ { "Processes" }
+ },
+
+ rrdtool = {
+ { "DataDir", "StepSize", "HeartBeat", "RRARows", "XFF", "CacheFlush", "CacheTimeout" },
+ { "RRASingle" },
+ { "RRATimespans" }
+ },
+
+ splash_leases = {
+ { },
+ { },
+ { }
+ },
+
+ tcpconns = {
+ { },
+ { "ListeningPorts" },
+ { "LocalPorts", "RemotePorts" }
+ },
+
+ unixsock = {
+ { "SocketFile", "SocketGroup", "SocketPerms" },
+ { },
+ { }
+ },
+
+ uptime = {
+ { },
+ { },
+ { }
+ },
+
+ wireless = {
+ { },
+ { },
+ { }
+ },
+}
+
+preprocess = {
+ RRATimespans = function(val)
+ local rv = { }
+ for time in val:gmatch("[^%s]+") do
+ table.insert( rv, luci.util.parse_units(time) )
+ end
+ return table.concat(rv, " ")
+ end
+}
+
+
+section("collectd")
+
+for plugin in pairs(plugins) do
+ if plugin ~= "collectd" then
+ section( plugin )
+ end
+end