From 2be8aefe7f7a7e368d82d332b1aeb5494aefa9b5 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 13 Sep 2019 11:55:36 +0200 Subject: luci-app-statistics: add new cpu plugin options Signed-off-by: Florian Eckert --- .../luasrc/model/cbi/luci_statistics/cpu.lua | 21 +++ .../luasrc/statistics/plugins/cpu.lua | 2 +- .../luasrc/statistics/rrdtool/definitions/cpu.lua | 176 ++++++++++++++++++--- 3 files changed, 177 insertions(+), 22 deletions(-) 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 index ee3fd254fb..56af1cc96a 100644 --- a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/cpu.lua +++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/cpu.lua @@ -12,4 +12,25 @@ s = m:section( NamedSection, "collectd_cpu", "luci_statistics" ) enable = s:option( Flag, "enable", translate("Enable this plugin") ) enable.default = 0 +-- collectd_cpu.reportbycpu (ReportByCpu) +reportbycpu = s:option( Flag, "ReportByCpu", + translate("Report by CPU"), + translate("By setting this, CPU is not aggregate of all processors on the system")) +reportbycpu.default = 1 +reportbycpu:depends( "enable", 1 ) + +-- collectd_cpu.reportbystate (ReportByState) +reportbystate = s:option( Flag, "ReportByState", + translate("Report by state"), + translate("When set to true, reports per-state metric (system, user, idle)")) +reportbystate.default = 1 +reportbystate:depends( "enable", 1 ) + +-- collectd_cpu.valuespercentage (ValuesPercentage) +valuespercentage = s:option( Flag, "ValuesPercentage", + translate("Report in percent"), + translate("When set to true, we request percentage values")) +valuespercentage.default = 0 +valuespercentage:depends({ enable = 1, ReportByCpu = 1, ReportByState = 1 }) + return m diff --git a/applications/luci-app-statistics/luasrc/statistics/plugins/cpu.lua b/applications/luci-app-statistics/luasrc/statistics/plugins/cpu.lua index 004a450eec..bae325990e 100644 --- a/applications/luci-app-statistics/luasrc/statistics/plugins/cpu.lua +++ b/applications/luci-app-statistics/luasrc/statistics/plugins/cpu.lua @@ -1,7 +1,7 @@ return { legend = { { }, - { }, + { "ValuesPercentage" , "ReportByCpu", "ReportByState" }, { } }, label = _("Processor"), diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua index 226c84ee96..3f8910722a 100644 --- a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua +++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/cpu.lua @@ -3,33 +3,167 @@ module("luci.statistics.rrdtool.definitions.cpu",package.seeall) +local uci = require("luci.model.uci").cursor() +local reportbystate = uci:get("luci_statistics", "collectd_cpu", "ReportByState") or "0" + function item() return luci.i18n.translate("Processor") end function rrdargs( graph, plugin, plugin_instance, dtype ) + local p = {} + + local title = "%H: Processor usage" + if #plugin_instance > 0 then + title = "%H: Processor usage on core #%pi" + end + + if reportbystate == "1" then + local cpu = { + title = title, + y_min = "0", + alt_autoscale_max = true, + vlabel = "Jiffies", + number_format = "%5.1lf", + data = { + instances = { + cpu = { + "idle", + "interrupt", + "nice", + "softirq", + "steal", + "system", + "user", + "wait" + } + }, + options = { + cpu_idle = { + color = "ffffff", + title = "Idle" + }, + cpu_interrupt = { + color = "a000a0", + title = "Interrupt" + }, + cpu_nice = { + color = "00e000", + title = "Nice" + }, + cpu_softirq = { + color = "ff00ff", + title = "Softirq" + }, + cpu_steal = { + color = "000000", + title = "Steal" + }, + cpu_system = { + color = "ff0000", + title = "System" + }, + cpu_user = { + color = "0000ff", + title = "User" + }, + cpu_wait = { + color = "ffb000", + title = "Wait" + } + } + } + } - return { - title = "%H: Processor usage on core #%pi", - y_min = "0", - alt_autoscale_max = true, - vlabel = "Percent", - number_format = "%5.1lf%%", - data = { - instances = { - cpu = { "user", "nice", "system", "softirq", "interrupt" } - }, - - options = { - cpu_idle = { color = "ffffff", title = "Idle" }, - cpu_nice = { color = "00e000", title = "Nice" }, - cpu_user = { color = "0000ff", title = "User" }, - cpu_wait = { color = "ffb000", title = "Wait" }, - cpu_system = { color = "ff0000", title = "System" }, - cpu_softirq = { color = "ff00ff", title = "Softirq" }, - cpu_interrupt = { color = "a000a0", title = "Interrupt" }, - cpu_steal = { color = "000000", title = "Steal" } + local percent = { + title = title, + y_min = "0", + alt_autoscale_max = true, + vlabel = "Percent", + number_format = "%5.1lf%%", + data = { + instances = { + percent = { + "idle", + "interrupt", + "nice", + "softirq", + "steal", + "system", + "user", + "wait" + } + }, + options = { + percent_idle = { + color = "ffffff", + title = "Idle" + }, + percent_interrupt = { + color = "a000a0", + title = "Interrupt" + }, + percent_nice = { + color = "00e000", + title = "Nice" + }, + percent_softirq = { + color = "ff00ff", + title = "Softirq" + }, + percent_steal = { + color = "000000", + title = "Steal" + }, + percent_system = { + color = "ff0000", + title = "System" + }, + percent_user = { + color = "0000ff", + title = "User" + }, + percent_wait = { + color = "ffb000", + title = "Wait" + } + } } } - } + + local types = graph.tree:data_types( plugin, plugin_instance ) + + for _, t in ipairs(types) do + if t == "cpu" then + p[#p+1] = cpu + end + + if t == "percent" then + p[#p+1] = percent + end + end + else + p = { + title = title, + y_min = "0", + alt_autoscale_max = true, + vlabel = "Percent", + number_format = "%5.1lf%%", + data = { + instances = { + percent = { + "active", + } + }, + options = { + percent_active = { + color = "00e000", + title = "Active" + } + } + } + } + end + + return p end -- cgit v1.2.3 From d064cbcf982cde30c4827207af74721c425b9bb0 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 13 Sep 2019 12:51:13 +0200 Subject: luci-app-statistics: add new memory plugin option Signed-off-by: Florian Eckert --- .../luasrc/model/cbi/luci_statistics/memory.lua | 14 ++++ .../luasrc/statistics/plugins/memory.lua | 4 +- .../statistics/rrdtool/definitions/memory.lua | 82 ++++++++++++++++++++-- 3 files changed, 91 insertions(+), 9 deletions(-) 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 index fa677b8d12..e5f3360c05 100644 --- a/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/memory.lua +++ b/applications/luci-app-statistics/luasrc/model/cbi/luci_statistics/memory.lua @@ -10,4 +10,18 @@ s = m:section( NamedSection, "collectd_memory", "luci_statistics" ) enable = s:option( Flag, "enable", translate("Enable this plugin") ) enable.default = 0 +-- collectd_memory.valuesabsolute (ValuesAbsolute) +valuespercentage = s:option( Flag, "ValuesAbsolute", + translate("Absolute values"), + translate("When set to true, we request absolute values")) +valuespercentage.default = 1 +valuespercentage:depends( "enable", 1 ) + +-- collectd_memory.valuespercentage (ValuesPercentage) +valuespercentage = s:option( Flag, "ValuesPercentage", + translate("Percent values"), + translate("When set to true, we request percentage values")) +valuespercentage.default = 0 +valuespercentage:depends( "enable", 1 ) + return m diff --git a/applications/luci-app-statistics/luasrc/statistics/plugins/memory.lua b/applications/luci-app-statistics/luasrc/statistics/plugins/memory.lua index 8dee2dafcd..9ad1b3f88d 100644 --- a/applications/luci-app-statistics/luasrc/statistics/plugins/memory.lua +++ b/applications/luci-app-statistics/luasrc/statistics/plugins/memory.lua @@ -1,7 +1,7 @@ return { - legend = { - { }, + legend = { { }, + { "ValuesPercentage", "ValuesAbsolute" }, { } }, label = _("Memory"), diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/memory.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/memory.lua index b05d31dc02..53cfc8f553 100644 --- a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/memory.lua +++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/memory.lua @@ -16,24 +16,92 @@ function item() end function rrdargs( graph, plugin, plugin_instance, dtype ) + local p = {} - return { + local memory = { title = "%H: Memory usage", vlabel = "MB", number_format = "%5.1lf%s", y_min = "0", alt_autoscale_max = true, data = { - instances = { - memory = { "free", "buffered", "cached", "used" } + 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" } + memory_buffered = { + color = "0000ff", + title = "Buffered" + }, + memory_cached = { + color = "ff00ff", + title = "Cached" + }, + memory_used = { + color = "ff0000", + title = "Used" + }, + memory_free = { + color = "00ff00", + title = "Free" + } } } } + + local percent = { + title = "%H: Memory usage", + vlabel = "Percent", + number_format = "%5.1lf%%", + y_min = "0", + alt_autoscale_max = true, + data = { + instances = { + percent = { + "free", + "buffered", + "cached", + "used" + } + }, + options = { + percent_buffered = { + color = "0000ff", + title = "Buffered" + }, + percent_cached = { + color = "ff00ff", + title = "Cached" + }, + percent_used = { + color = "ff0000", + title = "Used" + }, + percent_free = { + color = "00ff00", + title = "Free" + } + } + } + } + + local types = graph.tree:data_types( plugin, plugin_instance ) + + for _, t in ipairs(types) do + if t == "percent" then + p[#p+1] = percent + end + + if t == "memory" then + p[#p+1] = memory + end + end + + return p end -- cgit v1.2.3 From 00fc5548ffb35184e5915c130889ed8ad9912fa6 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 13 Sep 2019 12:56:39 +0200 Subject: luci-app-statistics: update license header in memory definition Signed-off-by: Florian Eckert --- .../luasrc/statistics/rrdtool/definitions/memory.lua | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/memory.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/memory.lua index 53cfc8f553..749c3e352c 100644 --- a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/memory.lua +++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/memory.lua @@ -1,13 +1,5 @@ ---[[ - -(c) 2011 Manuel Munz - -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 -]]-- +-- Copyright 2011 Manuel Munz +-- Licensed to the public under the Apache License 2.0. module("luci.statistics.rrdtool.definitions.memory",package.seeall) -- cgit v1.2.3 From cb252b2c03189446fb8a8413e1371c84bcb044dd Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 13 Sep 2019 14:01:36 +0200 Subject: luci-app-statistics: cleanup ping definitions Signed-off-by: Florian Eckert --- .../luasrc/statistics/rrdtool/definitions/ping.lua | 57 ++++++++++++++-------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/ping.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/ping.lua index e290af549a..6ad11985ec 100644 --- a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/ping.lua +++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/ping.lua @@ -9,25 +9,44 @@ end 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__value = { - noarea = true, overlay = true, title = "%di" } } - } }, + local ping = { + title = "%H: ICMP Round Trip Time", + vlabel = "ms", + number_format = "%5.1lf ms", + data = { + sources = { + ping = { + "value" + } + }, + options = { + ping__value = { + noarea = true, + overlay = true, + title = "%di" + } + } + } + } - -- Ping droprate - { title = "%H: ICMP Drop Rate", - vlabel = "%", - number_format = "%5.2lf %%", - data = { - types = { "ping_droprate" }, - options = { ping_droprate = { - noarea = true, overlay = true, title = "%di", transform_rpn = "100,*" } } - } } + local droprate = { + title = "%H: ICMP Drop Rate", + vlabel = "%", + number_format = "%5.2lf %%", + data = { + types = { + "ping_droprate" + }, + options = { + ping_droprate = { + noarea = true, + overlay = true, + title = "%di", + transform_rpn = "100,*" + } + } + } } + + return { ping, droprate } end -- cgit v1.2.3 From b80ccb990b5a9256207a44bfdef359bd4d5c19c9 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 13 Sep 2019 14:10:01 +0200 Subject: luci-app-statistics: add ping stddev definition Signed-off-by: Florian Eckert --- .../luasrc/statistics/rrdtool/definitions/ping.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/ping.lua b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/ping.lua index 6ad11985ec..b8d11c0759 100644 --- a/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/ping.lua +++ b/applications/luci-app-statistics/luasrc/statistics/rrdtool/definitions/ping.lua @@ -48,5 +48,23 @@ function rrdargs( graph, plugin, plugin_instance, dtype ) } } - return { ping, droprate } + local stddev = { + title = "%H: ICMP Standard Deviation", + vlabel = "ms", + number_format = "%5.1lf ms", + data = { + types = { + "ping_stddev" + }, + options = { + ping_stddev = { + noarea = true, + overlay = true, + title = "%di" + } + } + } + } + + return { ping, droprate, stddev } end -- cgit v1.2.3