Browse Source

collectd: Add lua and exec collectors for lantiq dsl metrics

Signed-off-by: Jeroen Peelaerts <jeroen.peelaerts@gmail.com>
lilik-openwrt-22.03
Jeroen Peelaerts 5 years ago
committed by jekkos
parent
commit
533c072ee0
2 changed files with 198 additions and 1 deletions
  1. +28
    -1
      utils/collectd/Makefile
  2. +170
    -0
      utils/collectd/files/lua-scripts/dsl.lua

+ 28
- 1
utils/collectd/Makefile View File

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=collectd
PKG_VERSION:=5.12.0
PKG_RELEASE:=13
PKG_RELEASE:=15
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=https://collectd.org/files/ \
@ -397,6 +397,32 @@ define BuildPlugin
endef
define BuildScriptLuaPlugin
PKG_CONFIG_DEPENDS+= CONFIG_PACKAGE_collectd-mod-$(1)
define Package/collectd-mod-$(1)
$$(call Package/collectd/Default)
TITLE:=$(2) plugin
DEPENDS:= $(4)
endef
define Package/collectd-mod-$(1)/install
$(INSTALL_DIR) $$(1)/usr/lib/collectd-mod-lua
for m in $(3); do \
${INSTALL_DATA} \
./files/lua-scripts/$$$$$$$${m}.lua $$(1)/usr/lib/collectd-mod-lua/ ; \
done
if [ -f ./files/usr/share/collectd/plugin/$(1).json ]; then \
$(INSTALL_DIR) $$(1)/usr/share/collectd/plugin ; \
$(INSTALL_DATA) ./files/usr/share/collectd/plugin/$(1).json \
$$(1)/usr/share/collectd/plugin/$(1).json ; \
fi
endef
$$(eval $$(call BuildPackage,collectd-mod-$(1)))
endef
define BuildScriptPlugin
PKG_CONFIG_DEPENDS+= CONFIG_PACKAGE_collectd-mod-$(1)
@ -503,3 +529,4 @@ $(eval $(call BuildPlugin,write-graphite,Carbon/Graphite output,write_graphite,+
$(eval $(call BuildPlugin,write-http,HTTP POST output,write_http,+PACKAGE_collectd-mod-write-http:libcurl))
$(eval $(call BuildScriptPlugin,sqm,SQM/qdisc collection,sqm_collectd,+PACKAGE_collectd-mod-sqm:collectd-mod-exec))
$(eval $(call BuildScriptLuaPlugin,ltq-dsl,Lantiq DSL collection,dsl,@TARGET_lantiq_xrx200 +PACKAGE_collectd-mod-ltq-dsl:collectd-mod-lua +libubus-lua))

+ 170
- 0
utils/collectd/files/lua-scripts/dsl.lua View File

@ -0,0 +1,170 @@
-- Copyright 2019 Florian Eckert <fe@dev.tdt.de>
-- Copyright 2021 Jeroen Peelaerts <jeroen@steganos.dev>
-- Licensed to the public under the GNU General Public License v2.
local ubus = require("ubus")
local hostname_file = "/proc/sys/kernel/hostname"
local line_vars = {
{
name = "vector",
type = "bool"
},
{
name = "trellis",
type = "bool"
},
{
name = "bitswap",
type = "bool"
},
{
name = "retx",
type = "bool"
},
{
name = "satn",
type = "snr"
},
{
name = "latn",
type = "snr"
},
{
name = "attndr",
type = "bitrate"
},
{
name = "snr",
type = "snr"
},
{
name = "data_rate",
type = "bitrate"
},
{
name = "latn",
type = "latency"
}
}
local errors = {
{
name = "uas",
type = "gauge"
},
{
name = "rx_corrupted",
type = "gauge"
},
{
name = "rx_retransmitted",
type = "gauge"
},
{
name = "tx_retransmitted",
type = "gauge"
}
}
local erb_vars = {
{
name = "sent",
type = "gauge"
},
{
name = "discarded",
type = "gauge"
}
}
local general_vars = {
{
name = "profile",
type = "gauge"
},
{
name = "mode",
type = "gauge"
},
{
name = "state_num",
type = "gauge"
},
{
name = "power_state_num",
type = "gauge"
},
{
name = "uptime",
type = "uptime"
}
}
local function build_metric(name, direction)
if direction ~= '' then
return string.format("%s_%s", name, direction)
else
return name
end
end
local function get_values(hostname, variables, metrics, direction)
for _, information in pairs(variables) do
local name = information["name"]
if metrics and metrics[name] ~= nil then
local value = metrics[name]
local metric = build_metric(name, direction)
local t = {
host = host,
plugin = 'dsl',
type = information["type"],
type_instance = metric,
values = {value}
}
collectd.log_debug(string.format("%s: %s=%s", "collectd-mod-dsl(lua)", metric, tostring(value)))
collectd.dispatch_values(t)
else
collectd.log_info(string.format("%s: Unable to get %s", "collectd-mod-dsl(lua)", name))
end
end
end
local function read()
local lines = io.lines(hostname_file)
local hostname = lines()
local conn = ubus.connect()
if not conn then
collectd.log_error("collectd-mod-dsl(lua): Failed to connect to ubus")
return 0
end
local metrics = conn:call("dsl", "metrics", {})
if metrics then
if metrics["up"] then
local near_errors = metrics["errors"]["near"]
local far_errors = metrics["errors"]["far"]
local down_line = metrics["downstream"]
local up_line = metrics["upstream"]
local erb = metrics["erb"]
get_values(hostname, errors, near_errors, "near")
get_values(hostname, errors, far_errors, "far")
get_values(hostname, line_vars, down_line, "down")
get_values(hostname, line_vars, up_line, "up")
get_values(hostname, erb_vars, erb, "")
end
get_values(hostname, general_vars, metrics, "")
return 0
end
collectd.log_error("collectd-mod-dsl(lua): No ubus dsl object found")
return 0
end
collectd.register_read(read)

Loading…
Cancel
Save