Merge pull request #2473 from TDT-AG/pr/20190121-luci-app-statistics
luci-app-statistics: some code cleanup
This commit is contained in:
commit
29c343c5ea
25 changed files with 89 additions and 124 deletions
|
@ -1,7 +1,7 @@
|
||||||
-- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
|
-- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
|
||||||
-- Licensed to the public under the Apache License 2.0.
|
-- Licensed to the public under the Apache License 2.0.
|
||||||
|
|
||||||
require("luci.sys")
|
local sys = require("luci.sys")
|
||||||
|
|
||||||
|
|
||||||
m = Map("luci_statistics",
|
m = Map("luci_statistics",
|
||||||
|
@ -17,7 +17,7 @@ s = m:section( NamedSection, "collectd", "luci_statistics" )
|
||||||
|
|
||||||
-- general.hostname (Hostname)
|
-- general.hostname (Hostname)
|
||||||
hostname = s:option( Value, "Hostname", translate("Hostname") )
|
hostname = s:option( Value, "Hostname", translate("Hostname") )
|
||||||
hostname.default = luci.sys.hostname()
|
hostname.default = sys.hostname()
|
||||||
hostname.optional = true
|
hostname.optional = true
|
||||||
|
|
||||||
-- general.basedir (BaseDir)
|
-- general.basedir (BaseDir)
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
--[[
|
-- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
|
||||||
|
-- Licensed to the public under the Apache License 2.0.
|
||||||
Copyright 2011 Jo-Philipp Wich <jow@openwrt.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",
|
m = Map("luci_statistics",
|
||||||
translate("Conntrack Plugin Configuration"),
|
translate("Conntrack Plugin Configuration"),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
-- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
|
-- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
|
||||||
-- Licensed to the public under the Apache License 2.0.
|
-- Licensed to the public under the Apache License 2.0.
|
||||||
|
|
||||||
require("luci.sys")
|
local sys = require("luci.sys")
|
||||||
|
|
||||||
|
|
||||||
m = Map("luci_statistics",
|
m = Map("luci_statistics",
|
||||||
|
@ -24,7 +24,7 @@ interfaces.widget = "select"
|
||||||
interfaces.size = 5
|
interfaces.size = 5
|
||||||
interfaces:depends( "enable", 1 )
|
interfaces:depends( "enable", 1 )
|
||||||
interfaces:value("any")
|
interfaces:value("any")
|
||||||
for k, v in pairs(luci.sys.net.devices()) do
|
for k, v in pairs(sys.net.devices()) do
|
||||||
interfaces:value(v)
|
interfaces:value(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
-- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
|
-- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
|
||||||
-- Licensed to the public under the Apache License 2.0.
|
-- Licensed to the public under the Apache License 2.0.
|
||||||
|
|
||||||
require("luci.sys")
|
local sys = require("luci.sys")
|
||||||
|
|
||||||
|
|
||||||
m = Map("luci_statistics",
|
m = Map("luci_statistics",
|
||||||
|
@ -23,7 +23,7 @@ interfaces = s:option( MultiValue, "Interfaces", translate("Monitor interfaces")
|
||||||
interfaces.widget = "select"
|
interfaces.widget = "select"
|
||||||
interfaces.size = 5
|
interfaces.size = 5
|
||||||
interfaces:depends( "enable", 1 )
|
interfaces:depends( "enable", 1 )
|
||||||
for k, v in pairs(luci.sys.net.devices()) do
|
for k, v in pairs(sys.net.devices()) do
|
||||||
interfaces:value(v)
|
interfaces:value(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
-- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
|
-- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
|
||||||
-- Licensed to the public under the Apache License 2.0.
|
-- Licensed to the public under the Apache License 2.0.
|
||||||
|
|
||||||
require("luci.sys.iptparser")
|
local ip = require("luci.sys.iptparser").IptParser()
|
||||||
|
|
||||||
ip = luci.sys.iptparser.IptParser()
|
local chains = { }
|
||||||
chains = { }
|
local targets = { }
|
||||||
targets = { }
|
|
||||||
|
|
||||||
for i, rule in ipairs( ip:find() ) do
|
for i, rule in ipairs( ip:find() ) do
|
||||||
if rule.chain and rule.target then
|
if rule.chain and rule.target then
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
--[[
|
-- Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
|
||||||
|
-- Licensed to the public under the Apache License 2.0.
|
||||||
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",
|
m = Map("luci_statistics",
|
||||||
translate("Memory Plugin Configuration"),
|
translate("Memory Plugin Configuration"),
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
-- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
|
-- Copyright 2008 Freifunk Leipzig / Jo-Philipp Wich <jow@openwrt.org>
|
||||||
-- Licensed to the public under the Apache License 2.0.
|
-- Licensed to the public under the Apache License 2.0.
|
||||||
|
|
||||||
require("luci.sys")
|
local sys = require("luci.sys")
|
||||||
|
|
||||||
local devices = luci.sys.net.devices()
|
local devices = sys.net.devices()
|
||||||
|
|
||||||
|
|
||||||
m = Map("luci_statistics",
|
m = Map("luci_statistics",
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
-- Copyright 2015 Jo-Philipp Wich <jow@openwrt.org>
|
-- Copyright 2015 Jo-Philipp Wich <jow@openwrt.org>
|
||||||
-- Licensed to the public under the Apache License 2.0.
|
-- Licensed to the public under the Apache License 2.0.
|
||||||
|
|
||||||
require "luci.sys"
|
|
||||||
|
|
||||||
local m, s, o
|
local m, s, o
|
||||||
|
|
||||||
|
|
||||||
m = Map("luci_statistics",
|
m = Map("luci_statistics",
|
||||||
translate("OpenVPN Plugin Configuration"),
|
translate("OpenVPN Plugin Configuration"),
|
||||||
translate("The OpenVPN plugin gathers information about the current vpn connection status."))
|
translate("The OpenVPN plugin gathers information about the current vpn connection status."))
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
-- Copyright 2015 Jo-Philipp Wich <jow@openwrt.org>
|
-- Copyright 2015 Jo-Philipp Wich <jow@openwrt.org>
|
||||||
-- Licensed to the public under the Apache License 2.0.
|
-- Licensed to the public under the Apache License 2.0.
|
||||||
|
|
||||||
require "luci.sys"
|
|
||||||
|
|
||||||
local m, s, o
|
local m, s, o
|
||||||
local sensor_types = {
|
local sensor_types = {
|
||||||
["12v"] = "voltage",
|
["12v"] = "voltage",
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
--[[
|
-- Copyright 2013 Thomas Endt <tmo26@gmx.de>
|
||||||
|
-- Licensed to the public under the Apache License 2.0.
|
||||||
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",
|
m = Map("luci_statistics",
|
||||||
translate("Uptime Plugin Configuration"),
|
translate("Uptime Plugin Configuration"),
|
||||||
|
|
|
@ -3,15 +3,14 @@
|
||||||
|
|
||||||
module("luci.statistics.i18n", package.seeall)
|
module("luci.statistics.i18n", package.seeall)
|
||||||
|
|
||||||
require("luci.util")
|
local util = require("luci.util")
|
||||||
require("luci.i18n")
|
local i18n = require("luci.i18n")
|
||||||
|
|
||||||
|
|
||||||
Instance = luci.util.class()
|
Instance = util.class()
|
||||||
|
|
||||||
|
|
||||||
function Instance.__init__( self, graph )
|
function Instance.__init__( self, graph )
|
||||||
self.i18n = luci.i18n
|
self.i18n = i18n
|
||||||
self.graph = graph
|
self.graph = graph
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,30 +3,28 @@
|
||||||
|
|
||||||
module("luci.statistics.rrdtool", package.seeall)
|
module("luci.statistics.rrdtool", package.seeall)
|
||||||
|
|
||||||
require("luci.statistics.datatree")
|
local tree = require("luci.statistics.datatree")
|
||||||
require("luci.statistics.rrdtool.colors")
|
local colors = require("luci.statistics.rrdtool.colors")
|
||||||
require("luci.statistics.i18n")
|
local i18n = require("luci.statistics.i18n")
|
||||||
require("luci.model.uci")
|
local uci = require("luci.model.uci").cursor()
|
||||||
require("luci.util")
|
local util = require("luci.util")
|
||||||
require("luci.sys")
|
local sys = require("luci.sys")
|
||||||
|
local fs = require("nixio.fs")
|
||||||
local fs = require "nixio.fs"
|
|
||||||
|
|
||||||
|
|
||||||
Graph = luci.util.class()
|
Graph = util.class()
|
||||||
|
|
||||||
function Graph.__init__( self, timespan, opts )
|
function Graph.__init__( self, timespan, opts )
|
||||||
|
|
||||||
opts = opts or { }
|
opts = opts or { }
|
||||||
|
|
||||||
local uci = luci.model.uci.cursor()
|
|
||||||
local sections = uci:get_all( "luci_statistics" )
|
local sections = uci:get_all( "luci_statistics" )
|
||||||
|
|
||||||
-- options
|
-- options
|
||||||
opts.timespan = timespan or sections.rrdtool.default_timespan or 900
|
opts.timespan = timespan or sections.rrdtool.default_timespan or 900
|
||||||
opts.rrasingle = opts.rrasingle or ( sections.collectd_rrdtool.RRASingle == "1" )
|
opts.rrasingle = opts.rrasingle or ( sections.collectd_rrdtool.RRASingle == "1" )
|
||||||
opts.rramax = opts.rramax or ( sections.collectd_rrdtool.RRAMax == "1" )
|
opts.rramax = opts.rramax or ( sections.collectd_rrdtool.RRAMax == "1" )
|
||||||
opts.host = opts.host or sections.collectd.Hostname or luci.sys.hostname()
|
opts.host = opts.host or sections.collectd.Hostname or sys.hostname()
|
||||||
opts.width = opts.width or sections.rrdtool.image_width or 400
|
opts.width = opts.width or sections.rrdtool.image_width or 400
|
||||||
opts.rrdpath = opts.rrdpath or sections.collectd_rrdtool.DataDir or "/tmp/rrd"
|
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.imgpath = opts.imgpath or sections.rrdtool.image_path or "/tmp/rrdimg"
|
||||||
|
@ -34,9 +32,9 @@ function Graph.__init__( self, timespan, opts )
|
||||||
opts.imgpath = opts.imgpath:gsub("/$","")
|
opts.imgpath = opts.imgpath:gsub("/$","")
|
||||||
|
|
||||||
-- helper classes
|
-- helper classes
|
||||||
self.colors = luci.statistics.rrdtool.colors.Instance()
|
self.colors = colors.Instance()
|
||||||
self.tree = luci.statistics.datatree.Instance(opts.host)
|
self.tree = tree.Instance(opts.host)
|
||||||
self.i18n = luci.statistics.i18n.Instance( self )
|
self.i18n = i18n.Instance( self )
|
||||||
|
|
||||||
-- rrdtool default args
|
-- rrdtool default args
|
||||||
self.args = {
|
self.args = {
|
||||||
|
@ -102,7 +100,7 @@ function Graph._rrdtool( self, def, rrd )
|
||||||
opt = opt:gsub( "{file}", rrd )
|
opt = opt:gsub( "{file}", rrd )
|
||||||
end
|
end
|
||||||
|
|
||||||
cmdline[#cmdline+1] = luci.util.shellquote(opt)
|
cmdline[#cmdline+1] = util.shellquote(opt)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- execute rrdtool
|
-- execute rrdtool
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
|
|
||||||
module("luci.statistics.rrdtool.colors", package.seeall)
|
module("luci.statistics.rrdtool.colors", package.seeall)
|
||||||
|
|
||||||
require("luci.util")
|
local util = require("luci.util")
|
||||||
|
|
||||||
|
|
||||||
Instance = luci.util.class()
|
Instance = util.class()
|
||||||
|
|
||||||
function Instance.from_string( self, s )
|
function Instance.from_string( self, s )
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -19,7 +19,6 @@ function rrdargs( graph, plugin, plugin_instance )
|
||||||
ups_inst[t] = graph.tree:data_instances( plugin, plugin_instance, t )
|
ups_inst[t] = graph.tree:data_instances( plugin, plugin_instance, t )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Check if hash table or array is empty or nil-filled
|
-- Check if hash table or array is empty or nil-filled
|
||||||
|
|
||||||
local function empty( t )
|
local function empty( t )
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
module("luci.statistics.rrdtool.definitions.conntrack",package.seeall)
|
module("luci.statistics.rrdtool.definitions.conntrack",package.seeall)
|
||||||
|
|
||||||
function rrdargs( graph, plugin, plugin_instance, dtype )
|
function rrdargs( graph, plugin, plugin_instance, dtype )
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title = "%H: Conntrack entries",
|
title = "%H: Conntrack entries",
|
||||||
vlabel = "Count",
|
vlabel = "Count",
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
module("luci.statistics.rrdtool.definitions.curl", package.seeall)
|
module("luci.statistics.rrdtool.definitions.curl", package.seeall)
|
||||||
|
|
||||||
function rrdargs( graph, plugin, plugin_instance, dtype )
|
function rrdargs( graph, plugin, plugin_instance, dtype )
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title = "%H: cUrl Response Time for #%pi",
|
title = "%H: cUrl Response Time for #%pi",
|
||||||
y_min = "0",
|
y_min = "0",
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
module("luci.statistics.rrdtool.definitions.disk", package.seeall)
|
module("luci.statistics.rrdtool.definitions.disk", package.seeall)
|
||||||
|
|
||||||
function rrdargs( graph, plugin, plugin_instance, dtype )
|
function rrdargs( graph, plugin, plugin_instance, dtype )
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
title = "%H: Disk I/O operations on %pi",
|
title = "%H: Disk I/O operations on %pi",
|
||||||
|
|
|
@ -37,7 +37,6 @@ function rrdargs( graph, plugin, plugin_instance )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- packet diagram
|
-- packet diagram
|
||||||
--
|
--
|
||||||
|
@ -119,7 +118,6 @@ function rrdargs( graph, plugin, plugin_instance )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- multicast diagram
|
-- multicast diagram
|
||||||
--
|
--
|
||||||
|
@ -144,7 +142,6 @@ function rrdargs( graph, plugin, plugin_instance )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- collision diagram
|
-- collision diagram
|
||||||
--
|
--
|
||||||
|
@ -169,7 +166,6 @@ function rrdargs( graph, plugin, plugin_instance )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- error diagram
|
-- error diagram
|
||||||
--
|
--
|
||||||
|
@ -206,6 +202,5 @@ function rrdargs( graph, plugin, plugin_instance )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return { traffic, packets, multicast, collisions, errors }
|
return { traffic, packets, multicast, collisions, errors }
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
module("luci.statistics.rrdtool.definitions.ping", package.seeall)
|
module("luci.statistics.rrdtool.definitions.ping", package.seeall)
|
||||||
|
|
||||||
function rrdargs( graph, plugin, plugin_instance, dtype )
|
function rrdargs( graph, plugin, plugin_instance, dtype )
|
||||||
|
|
||||||
return {
|
return {
|
||||||
-- Ping roundtrip time
|
-- Ping roundtrip time
|
||||||
{ title = "%H: ICMP Round Trip Time",
|
{ title = "%H: ICMP Round Trip Time",
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
module("luci.statistics.rrdtool.definitions.sensors", package.seeall)
|
module("luci.statistics.rrdtool.definitions.sensors", package.seeall)
|
||||||
|
|
||||||
function rrdargs( graph, plugin, plugin_instance )
|
function rrdargs( graph, plugin, plugin_instance )
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
per_instance = true,
|
per_instance = true,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
-- Copyright 2013 Freifunk Augsburg / Michael Wendland <michael@michiwend.com>
|
-- Copyright 2013 Freifunk Augsburg / Michael Wendland <michael@michiwend.com>
|
||||||
-- Licensed to the public under the Apache License 2.0.
|
-- Licensed to the public under the Apache License 2.0.
|
||||||
|
|
||||||
|
|
||||||
module("luci.statistics.rrdtool.definitions.splash_leases", package.seeall)
|
module("luci.statistics.rrdtool.definitions.splash_leases", package.seeall)
|
||||||
|
|
||||||
function rrdargs( graph, plugin, plugin_instance, dtype )
|
function rrdargs( graph, plugin, plugin_instance, dtype )
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
module("luci.statistics.rrdtool.definitions.tcpconns", package.seeall)
|
module("luci.statistics.rrdtool.definitions.tcpconns", package.seeall)
|
||||||
|
|
||||||
function rrdargs( graph, plugin, plugin_instance, dtype )
|
function rrdargs( graph, plugin, plugin_instance, dtype )
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title = "%H: TCP connections to port %pi",
|
title = "%H: TCP connections to port %pi",
|
||||||
vlabel = "Connections/s",
|
vlabel = "Connections/s",
|
||||||
|
|
|
@ -22,6 +22,5 @@ function rrdargs( graph, plugin, plugin_instance, dtype )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue