Skip to content

Commit

Permalink
prometheus-node-exporter-lua: Add ethtool-stats
Browse files Browse the repository at this point in the history
Based on ethtool-lua library, add interface statistics to the
prometheus-node-exporter.

Signed-off-by: Kevin Jilissen <info@kevinjilissen.nl>
  • Loading branch information
Kevinjil committed May 8, 2024
1 parent 233e3d0 commit 17884fb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
11 changes: 11 additions & 0 deletions utils/prometheus-node-exporter-lua/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@ define Package/prometheus-node-exporter-lua-realtek-poe/install
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/realtek-poe.lua $(1)/usr/lib/lua/prometheus-collectors/
endef

define Package/prometheus-node-exporter-lua-ethtool-stats
$(call Package/prometheus-node-exporter-lua/Default)
TITLE+= (ethtool-stats collector)
DEPENDS:=prometheus-node-exporter-lua +ethtool-lua
endef

define Package/prometheus-node-exporter-lua-ethtool-stats/install
$(INSTALL_DIR) $(1)/usr/lib/lua/prometheus-collectors
$(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/ethtool-stats.lua $(1)/usr/lib/lua/prometheus-collectors/
endef

$(eval $(call BuildPackage,prometheus-node-exporter-lua))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-bmx7))
$(eval $(call BuildPackage,prometheus-node-exporter-lua-dawn))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
local ethtool = require "ethtool"

local pattern_device = "^%s*([^%s:]+):"
local pattern_metric = "^([a-zA-Z0-9:_]+)$"

local function get_devices()
local devices = {}
for line in io.lines("/proc/net/dev") do
local dev = string.match(line, pattern_device)
if dev then
table.insert(devices, dev)
end
end
return devices
end

local function scrape()
local eth = ethtool.open()
local metrics = {}
for _, dev in ipairs(get_devices()) do
local stats = eth:statistics(dev)
if stats then
for m_name, m_value in pairs(stats) do
if string.match(m_name, pattern_metric) then
local m = metrics[m_name]
if m == nil then
m = metric("ethtool_" .. m_name, "counter")
metrics[m_name] = m
end
m({device=dev}, m_value)
end
end
end
end
eth:close()
end

return { scrape = scrape }

0 comments on commit 17884fb

Please sign in to comment.