From: Jo-Philipp Wich Date: Thu, 22 May 2008 13:09:45 +0000 (+0000) Subject: * ffluci/statistics: add cbi model for rrdtool, fix stat-genconfig to allow correctly... X-Git-Tag: 0.8.0~1014 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0e3371976118cc1cd36cb5d5cf5c379fe19e0020;p=oweals%2Fluci.git * ffluci/statistics: add cbi model for rrdtool, fix stat-genconfig to allow correctly spelled list value parameters, updated default config --- diff --git a/applications/luci-statistics/files/etc/config/luci_statistics b/applications/luci-statistics/files/etc/config/luci_statistics index 64beddb91..1bb183f36 100644 --- a/applications/luci-statistics/files/etc/config/luci_statistics +++ b/applications/luci-statistics/files/etc/config/luci_statistics @@ -1,12 +1,12 @@ config 'statistics' 'general' option 'BaseDir' '/var/run/collectd' - option 'Include' '/etc/collectd/conf.d/*.conf' + option 'Include' '/etc/collectd/conf.d' option 'PIDFile' '/var/run/collectd.pid' option 'PluginDir' '/usr/lib/collectd' option 'TypesDB' '/etc/collectd/types.db' option 'Interval' '30' - option 'ReadThreads' '5' + option 'ReadThreads' '2' config 'statistics' 'collectd_ping' option 'enable' '1' @@ -14,7 +14,7 @@ config 'statistics' 'collectd_ping' option 'Hosts' '127.0.0.1' config 'statistics' 'collectd_csv' - option 'enable' '1' + option 'enable' '0' option 'StoreRates' '0' option 'DataDir' '/tmp' @@ -32,12 +32,13 @@ config 'statistics' 'collectd_disk' config 'statistics' 'collectd_dns' option 'enable' '1' - option 'Interfaces' 'ffdhcp ff lan wan' + option 'Interfaces' 'ffdhcp ff br-lan' option 'IgnoreSources' '127.0.0.1' config 'statistics' 'collectd_email' option 'enable' '1' - option 'SocketFile' '/var/run/collectd-email.socket' + option 'SocketFile' '/var/run/collectd/email.sock' + option 'SocketGroup' 'nogroup' config 'statistics' 'collectd_exec' option 'enable' '1' @@ -50,7 +51,7 @@ config 'collectd_exec_notify' config 'statistics' 'collectd_interface' option 'enable' '1' - option 'Interfaces' 'ffdhcp ff lan wan' + option 'Interfaces' 'br-lan br-ff' option 'IgnoreSelected' '0' config 'statistics' 'collectd_iptables' @@ -77,7 +78,7 @@ config 'statistics' 'collectd_irq' option 'Irqs' '2 3 4 7' config 'statistics' 'collectd_logfile' - option 'enable' '1' + option 'enable' '0' option 'LogLevel' 'notice' option 'File' '/var/log/collectd.log' option 'Timestamp' '1' @@ -89,7 +90,7 @@ config 'statistics' 'collectd_netlink' option 'QDiscs' 'br-lan br-ff' config 'statistics' 'collectd_network' - option 'enable' '1' + option 'enable' '0' config 'collectd_network_listen' option 'host' '0.0.0.0' @@ -99,7 +100,6 @@ config 'collectd_network_server' config 'statistics' 'collectd_processes' option 'enable' '1' - option 'Processs' 'olsrd tincd bmxd' config 'statistics' 'collectd_tcpconns' option 'enable' '1' @@ -107,6 +107,15 @@ config 'statistics' 'collectd_tcpconns' option 'LocalPorts' '22 80 443' config 'statistics' 'collectd_unixsock' + option 'enable' '0' + option 'SocketFile' '/var/run/collectd/query.sock' + option 'SocketGroup' 'nogroup' + +config 'statistics' 'collectd_wireless' option 'enable' '1' - option 'SocketFile' '/var/run/collectd-query.sock' +config 'statistics' 'collectd_rrdtool' + option 'enable' '1' + option 'DataDir' '/tmp' + option 'RRARows' '100' + option 'RRASingle' '1' diff --git a/applications/luci-statistics/files/usr/bin/stat-genconfig b/applications/luci-statistics/files/usr/bin/stat-genconfig index 2b2e19dca..cd707c6b2 100755 --- a/applications/luci-statistics/files/usr/bin/stat-genconfig +++ b/applications/luci-statistics/files/usr/bin/stat-genconfig @@ -31,64 +31,75 @@ function section( plugin ) if type(config) == "table" and ( plugin == "general" or config.enable == "1" ) then - if plugin ~= "general" then print( "" ) end + local params = "" if type( plugins[plugin] ) == "function" then - plugins[plugin]( config ) + params = plugins[plugin]( config ) else - config_generic( config, plugins[plugin][1], plugins[plugin][2], plugins[plugin][3], plugin == "general" ) + params = config_generic( config, plugins[plugin][1], plugins[plugin][2], plugins[plugin][3], plugin == "general" ) end + if plugin ~= "general" then - print( "\n" ) + print( "LoadPlugin " .. plugin ) + + if params:len() > 0 then + print( "\n" .. params .. "\n" ) + else + print( "" ) + end else - print( "\n" ) + 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 - _string( c[key], key, nopad ) + str = str .. _string( c[key], key, nopad ) end end if type(bools) == "table" then for i, key in ipairs( bools ) do - _bool( c[key], key, nopad ) + str = str .. _bool( c[key], key, nopad ) end end if type(lists) == "table" then - _list_expand( c, lists, nopad ) + 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 - user = sections[s].cmduser or "root" - group = sections[s].cmdgroup or "root" + user = sections[s].cmduser or "nobody" + group = sections[s].cmdgroup or "nogroup" - print( "\t" .. key .. " " .. user .. ":" .. group .. ' "' .. cmd .. '"' ) + str = str .. "\t" .. key .. " " .. user .. ":" .. group .. ' "' .. cmd .. "\"\n" 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 @@ -109,86 +120,110 @@ function config_iptables( c ) for i, rule in ipairs( ipt:find( search ) ) do - name = sections[s].name - if i > 1 then name = name .. " (" .. i .. ")" end - - print( "\tChain " .. rule.table .. " " .. rule.chain .. " " .. rule.index .. ' "' .. name .. '"' ) + 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 + 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 + host = sections[s].host + port = sections[s].port if host then if port then - print( "\t" .. key .. " " .. host .. " " .. port ) + str = str .. "\t" .. key .. " " .. host .. " " .. port .. "\n" else - print( "\t" .. key .. " " .. host ) + str = str .. "\t" .. key .. " " .. host .. "\n" end end end end end - _string( c["TimeToLive"], "TimeToLive" ) - _string( c["CacheFlush"], "CacheFlush" ) - _bool( c["Forward"], "Forward" ) + 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 - _expand( c[n], n:gsub( "(%w+)s", "%1" ), nopad ) + 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 ) if type(s) == "string" then + local str = "" + for i, v in ipairs( ffluci.util.split( s, "%s+", nil, true ) ) do - _string( v, n, nopad ) + str = str .. _string( v, n, nopad ) end + + return str end end function _bool( s, n, nopad ) + local str = "" local pad = "" if not nopad then pad = "\t" end if s and s == "1" then - print( pad .. n .. " true" ) + str = pad .. n .. " true" else - print( pad .. n .. " false" ) + 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 not s:find("%d") then - if not s:find("%s") then - print( pad .. n .. " " .. s ) + if s:find("[^%d]") then + if not s:find("[^%w]") then + str = pad .. n .. " " .. s else - print( pad .. n .. ' "' .. s '"' ) + str = pad .. n .. ' "' .. s .. '"' end else - print( pad .. n .. " " .. s ) + str = pad .. n .. " " .. s end + + str = str .. "\n" end + + return str end @@ -224,7 +259,7 @@ plugins = { }, email = { - { "SocketFile", "SocketUser", "SocketPerms", "MaxConns" }, + { "SocketFile", "SocketGroup", "SocketPerms", "MaxConns" }, { }, { } }, @@ -254,7 +289,7 @@ plugins = { netlink = { { }, { "IgnoreSelected" }, - { "Interfaces", "VerboseInterfaces", "QDiscs", "Classs", "Filters" } + { "Interfaces", "VerboseInterfaces", "QDiscs", "Classes", "Filters" } }, network = config_network, @@ -262,7 +297,13 @@ plugins = { processes = { { }, { }, - { "Processs" } + { "Processes" } + }, + + rrdtool = { + { "DataDir", "StepSize", "HeartBeat", "RRARows", "XFF", "CacheFlush", "CacheTimeout" }, + { "RRASingle" }, + { "RRATimespans" } }, tcpconns = { @@ -272,7 +313,13 @@ plugins = { }, unixsock = { - { "SocketFile", "SocketUser", "SocketPerms" }, + { "SocketFile", "SocketGroup", "SocketPerms" }, + { }, + { } + }, + + wireless = { + { }, { }, { } }, diff --git a/applications/luci-statistics/src/model/cbi/admin_statistics/netlink.lua b/applications/luci-statistics/src/model/cbi/admin_statistics/netlink.lua index f027f3778..9e1b86d4d 100644 --- a/applications/luci-statistics/src/model/cbi/admin_statistics/netlink.lua +++ b/applications/luci-statistics/src/model/cbi/admin_statistics/netlink.lua @@ -56,8 +56,8 @@ for i, v in ipairs(ffluci.sys.net.devices()) do qdiscs:value(v) end --- collectd_netlink.classs (Class) -classs = s:option( MultiValue, "Classs", "Shapingklassen auf Schnittstellen Überwachen", "mehrere Einträge mit Strg selektieren" ) +-- collectd_netlink.classes (Class) +classs = s:option( MultiValue, "Classes", "Shapingklassen auf Schnittstellen Überwachen", "mehrere Einträge mit Strg selektieren" ) classs.widget = "select" classs.optional = true classs:depends( "enable", 1 ) diff --git a/applications/luci-statistics/src/model/cbi/admin_statistics/processes.lua b/applications/luci-statistics/src/model/cbi/admin_statistics/processes.lua index 9af3cdc95..5e9735385 100644 --- a/applications/luci-statistics/src/model/cbi/admin_statistics/processes.lua +++ b/applications/luci-statistics/src/model/cbi/admin_statistics/processes.lua @@ -24,7 +24,7 @@ enable = s:option( Flag, "enable", "Plugin aktivieren" ) enable.default = 0 -- collectd_processes.processs (Process) -processes = s:option( Value, "Processs", "Überwachte Prozesse", "mehrere mit Leerzeichen trennen" ) +processes = s:option( Value, "Processes", "Überwachte Prozesse", "mehrere mit Leerzeichen trennen" ) processes.default = "olsrd bmxd httpd dnsmasq dropbear tinc" processes:depends( "enable", 1 ) diff --git a/applications/luci-statistics/src/model/cbi/admin_statistics/rrdtool.lua b/applications/luci-statistics/src/model/cbi/admin_statistics/rrdtool.lua new file mode 100644 index 000000000..89adf52a7 --- /dev/null +++ b/applications/luci-statistics/src/model/cbi/admin_statistics/rrdtool.lua @@ -0,0 +1,99 @@ +--[[ + +Luci configuration model for statistics - collectd rrdtool plugin configuration +(c) 2008 Freifunk Leipzig / Jo-Philipp Wich + +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", "RRDTool Plugin", +[[Das RRDTool-Plugin schreibt die gesammelten Werte in sogenannte RRD Datenbanken, welche die +Grundlage für die Statistik-Diagramme bilden.

+Die Einstellungen auf dieser Seite sollten nur in Ausnahmefällen geändert werden, +falsche Einstellungen führen zu einem sehr hohem Platzverbrauch im Temp-Verzeichnis und das +Gerät kann nur noch im Failsafe-Modus repariert werden!]]) + +-- collectd_rrdtool config section +s = m:section( NamedSection, "collectd_rrdtool", "luci_statistics", "Pluginkonfiguration" ) + +-- collectd_rrdtool.enable +enable = s:option( Flag, "enable", "Plugin aktivieren" ) +enable.default = 1 + +-- collectd_rrdtool.datadir (DataDir) +datadir = s:option( Value, "DataDir", "Speicherort für die RRD Datenbanken" ) +datadir.default = "/tmp" +datadir.rmempty = true +datadir.optional = true +datadir:depends( "enable", 1 ) + +-- collectd_rrdtool.stepsize (StepSize) +stepsize = s:option( Value, "StepSize", "Schritt-Interval", "in Sekunden" ) +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", "Heart-Beat-Interval", "in Sekunden" ) +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", 'Jeweils nur ein RRA anlegen', "reduziert die Größe der RRDs" ) +rrasingle.default = true +rrasingle.rmempty = true +rrasingle.optional = true +rrasingle:depends( "enable", 1 ) + +-- collectd_rrdtool.rratimespans (RRATimespan) +rratimespans = s:option( Value, "RRATimespans", "Gespeicherte Zeitspannen", "in Sekunden; mehrere mit Leerzeichen trennen" ) +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", "Anzahl der Datenpunkte pro Zeitspanne" ) +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", "RRD XFiles Faktor" ) +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", "Daten für Zeitspanne cachen", "in Sekunden" ) +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", "Cache nach Zeitspanne leeren", "in Sekunden" ) +cacheflush.isinteger = true +cacheflush.default = 100 +cacheflush.rmempty = true +cacheflush.optional = true +cacheflush:depends( "enable", 1 ) + +return m diff --git a/applications/luci-statistics/src/model/menu/70luci-statistics.lua b/applications/luci-statistics/src/model/menu/70luci-statistics.lua index bc36d7122..e53a0a0d4 100644 --- a/applications/luci-statistics/src/model/menu/70luci-statistics.lua +++ b/applications/luci-statistics/src/model/menu/70luci-statistics.lua @@ -20,7 +20,7 @@ act( "network", "Netzwerk" ) act( "ping", "Ping" ) --act( "powerdns", "Powerdns Server" ) act( "processes", "Prozesse" ) ---act( "rrdtool", "RRD Tool" ) +act( "rrdtool", "RRDTool" ) --act( "sensors", "Sensoren" ) --act( "snmp", "SNMP Datenquellen" ) --act( "syslog", "Systemlog" )