Last active
December 1, 2023 13:31
-
-
Save 95gabor/dd88e6c3abff9369f7e34266d1cddd21 to your computer and use it in GitHub Desktop.
prometheus-node-exporter-lua-wan
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
#!/usr/bin/lua | |
# /usr/lib/lua/prometheus-collectors/upstream.lua | |
local ubus = require "ubus" | |
local function scrape() | |
local metric_wan_interface = metric("wan_interface_uptime", "gauge", "WAN interface uptime") | |
local u = ubus.connect() | |
local network_data = u:call("network.interface", "dump", {}) | |
for _, interface in ipairs(network_data.interface) do | |
local is_wan = false | |
local ipv4 = interface["ipv4-address"][1] | |
local ipv6 = interface["ipv6-address"][1] | |
for _, route in pairs(interface.route or {}) do | |
if route.target == "0.0.0.0" and route.mask == 0 then | |
is_wan = true | |
break | |
end | |
if route.target == "::" and route.mask == 0 then | |
is_wan = true | |
break | |
end | |
end | |
if is_wan then | |
metric_wan_interface( | |
{ | |
name = interface.interface, | |
proto = interface.proto or "unknown", | |
device = interface.l3_device or interface.device, | |
ipv4 = ipv4 and ipv4.address, | |
ipv4_mask = ipv4 and ipv4.mask, | |
ipv6 = ipv6 and ipv6.address, | |
ipv6_mask = ipv6 and ipv6.mask, | |
}, | |
interface.uptime | |
) | |
end | |
end | |
end | |
return { scrape = scrape } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
omg