-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prometheus-node-exporter-lua: Add ethtool-stats
Based on ethtool-lua library, add interface statistics to the prometheus-node-exporter. Signed-off-by: Kevin Jilissen <info@kevinjilissen.nl>
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/ethtool-stats.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |