From aa7ea7938f4b39fef4b8a0a3f9ab14c1119be515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Treffer?= Date: Mon, 3 Jun 2024 22:16:11 +0200 Subject: [PATCH] prometheus-node-exporter-lua: fix netclass duplicate TYPE lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes a315c40b7232bbc83582685c98e41466d84d7a35 [initial fix] Signed-off-by: René Treffer [fixup René version] Signed-off-by: PichetGoulu [actual commit] Signed-off-by: Etienne Champetier --- utils/prometheus-node-exporter-lua/Makefile | 4 +- .../lua/prometheus-collectors/netclass.lua | 82 +++++++++++-------- 2 files changed, 50 insertions(+), 36 deletions(-) diff --git a/utils/prometheus-node-exporter-lua/Makefile b/utils/prometheus-node-exporter-lua/Makefile index 6c0d1a949e..f40ae7a0d7 100644 --- a/utils/prometheus-node-exporter-lua/Makefile +++ b/utils/prometheus-node-exporter-lua/Makefile @@ -4,8 +4,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=prometheus-node-exporter-lua -PKG_VERSION:=2024.06.02 -PKG_RELEASE:=2 +PKG_VERSION:=2024.06.03 +PKG_RELEASE:=1 PKG_MAINTAINER:=Etienne CHAMPETIER PKG_LICENSE:=Apache-2.0 diff --git a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/netclass.lua b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/netclass.lua index f1bcf577ec..11666ecde7 100644 --- a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/netclass.lua +++ b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/netclass.lua @@ -25,52 +25,66 @@ local function load(device, file) -- load a single sysfs file, trim trailing new end end -local function file_gauge(name, device, file) - local value = load(device, file) - if value ~= nil then - metric("node_network_" .. name, "gauge", {device = device}, tonumber(value)) - end -end - -local function file_counter(name, device, file) - local value = load(device, file) - if value ~= nil then - metric("node_network_" .. name, "counter", {device = device}, tonumber(value)) - end -end - -local function get_metric(device) +local function get_metric(device, metric_node_network) local address = load(device, "address") local broadcast = load(device, "broadcast") local duplex = load(device, "duplex") local operstate = load(device, "operstate") local ifalias = load(device, "ifalias") - metric("node_network_info", "gauge", {device = device, address = address, broadcast = broadcast, duplex = duplex, operstate = operstate, ifalias = ifalias}, 1) - file_gauge("address_assign_type", device, "addr_assign_type") - file_gauge("carrier", device, "carrier") - file_counter("carrier_changes_total", device, "carrier_changes") - file_counter("carrier_up_changes_total", device, "carrier_up_count") - file_counter("carrier_down_changes_total", device, "carrier_down_count") - file_gauge("device_id", device, "dev_id") - file_gauge("dormant", device, "dormant") - file_gauge("flags", device, "flags") - file_gauge("iface_id", device, "ifindex") - file_gauge("iface_link", device, "iflink") - file_gauge("iface_link_mode", device, "link_mode") - file_gauge("mtu_bytes", device, "mtu") - file_gauge("name_assign_type", device, "name_assign_type") - file_gauge("net_dev_group", device, "netdev_group") - file_gauge("transmit_queue_length", device, "tx_queue_len") - file_gauge("protocol_type", device, "type") + metric_node_network.info({device = device, address = address, broadcast = broadcast, duplex = duplex, operstate = operstate, ifalias = ifalias}, 1) local speed = load(device, "speed") if speed ~= nil and tonumber(speed) >= 0 then - metric("node_network_speed_bytes", "gauge", {device = device}, tonumber(speed)*1000*1000/8) + metric_node_network.speed_bytes({device = device}, tonumber(speed)*1000*1000/8) + end + local file_to_metric = { + addr_assign_type = "address_assign_type", + carrier = "carrier", + carrier_changes = "carrier_changes_total", + carrier_up_count = "carrier_up_changes_total", + carrier_down_count = "carrier_down_changes_total", + dev_id = "device_id", + dormant = "dormant", + flags = "flags", + ifindex = "iface_id", + iflink = "iface_link", + link_mode = "iface_link_mode", + mtu = "mtu_bytes", + name_assign_type = "name_assign_type", + netdev_group = "net_dev_group", + tx_queue_len = "transmit_queue_length", + type = "protocol_type", + } + for file, metric in pairs(file_to_metric) do + local value = load(device, file) + if value ~= nil then + metric_node_network[metric]({device = device}, tonumber(value)) + end end end local function scrape() + local metric_node_network = { + info = metric("node_network_info", "gauge"), + address_assign_type = metric("node_network_address_assign_type", "gauge"), + carrier = metric("node_network_carrier", "gauge"), + carrier_changes_total = metric("node_network_carrier_changes_total", "counter"), + carrier_up_changes_total = metric("node_network_carrier_up_changes_total", "counter"), + carrier_down_changes_total = metric("node_network_carrier_down_changes_total", "counter"), + device_id = metric("node_network_device_id", "gauge"), + dormant = metric("node_network_dormant", "gauge"), + flags = metric("node_network_flags", "gauge"), + iface_id = metric("node_network_iface_id", "gauge"), + iface_link = metric("node_network_iface_link", "gauge"), + iface_link_mode = metric("node_network_iface_link_mode", "gauge"), + mtu_bytes = metric("node_network_mtu_bytes", "gauge"), + name_assign_type = metric("node_network_name_assign_type", "gauge"), + net_dev_group = metric("node_network_net_dev_group", "gauge"), + transmit_queue_length = metric("node_network_transmit_queue_length", "gauge"), + protocol_type = metric("node_network_protocol_type", "gauge"), + speed_bytes = metric("node_network_speed_bytes", "gauge"), + } for _, devicename in ipairs(get_devices()) do - get_metric(devicename) + get_metric(devicename, metric_node_network) end end