Hi, I'm trying to get nlbwmon data into grafana.
I need help creating a lua prometheus file for nlbwmon. Here is what I have so far:
I'm saving the nlbwmon output to a file, then I want prometheus to scrape it but I'm having no luck.
nlbw -c csv -g ip,mac -o ip | tr -d '"' | tail -n +2 > /tmp/nlbwmon.out
output looks like this:
11:44:54:00:00:00 10.0.0.1 5039 0 0 15227038 232789
22:22:33:00:00:00 10.0.0.2 151194 298574558 1794766 187757841 1951818
Here is my lua file.
local nlbwstat = {
"mac",
"ip",
"conns",
"rx_bytes",
"rx_pkts",
"tx_bytes",
"tx_pkts"
}
local pattern = "(%w+:%w+:%w+:%w+:%w+:%w+)%s+(%d+.%d+.%d+.%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)"
local function scrape()
local nlbw_table = {}
for line in io.lines("/tmp/nlbwmon.out") do
local t = {string.match(line, pattern)}
if #t == 7 then
nlbw_table[t[1]] = t
end
end
for i, nlbw in ipairs(nlbwstat) do
nlbw_metric = metric("node_network_" .. nlbw, "counter")
for mac, nlbw_table_entry in pairs(nlbw_table) do
nlbw_metric:set(nlbw_table_entry[i], {mac_address=mac})
end
end
end
-- Add some error handling to the io.lines call
local function read_file()
local file = io.open("/tmp/nlbwmon.out", "r")
if not file then
return nil, "Error opening file"
end
local contents = file:read("*all")
file:close()
return contents
end
return { scrape = scrape, read_file = read_file }
Prometheus output from http://10.0.0.2:9100/metrics
# TYPE node_network_mac counter
node_scrape_collector_duration_seconds{collector="nlbw_stat"} 0.00056004524230957
node_scrape_collector_success{collector="nlbw_stat"} 0