Skip to content

Instantly share code, notes, and snippets.

@duxet
Last active November 9, 2024 19:02
Show Gist options
  • Save duxet/80d76d58f7d1f2bd82bf2f10d3ac237f to your computer and use it in GitHub Desktop.
Save duxet/80d76d58f7d1f2bd82bf2f10d3ac237f to your computer and use it in GitHub Desktop.
--
-- opkg install prometheus-node-exporter-lua
-- and then add this file to /usr/lib/lua/prometheus-collectors/ directory
--
local function scrape()
local status = get_page("Status")
local hw_version = status["PON IP HW version"]
local fw_version = status["PON IP FW version"]
local sw_version = status["PON IP SW version"]
local ploam_status = status["PON PLOAM Status"]:match("(.+), (.+)")
metric("pon_stick_info", "gauge", { hw_version=hw_version, fw_version=fw_version, sw_version=sw_version, ploam_status=ploam_status }, 1)
local optical = get_page("Optical Interface Status")
local temperature = optical["Optical transceiver temperature"]:match("([0-9]+) deg C")
local tx_bias = optical["Transmit bias current"]:match("(.+) mA")
local tx_power = optical["Transmit power"]:match("(.+) dBm")
local rx_power = optical["Receive power"]:match("(.+) dBm")
local voltage = opptical["Transceiver supply voltage"]:match("(.+) V")
metric("optical_transceiver_temperature", "gauge", nil, tonumber(temperature))
metric("optical_transmit_bias_current", "gauge", nil, tonumber(tx_bias))
metric("optical_transmit_power", "gauge", nil, tonumber(tx_power))
metric("optical_receive_power", "gauge", nil, tonumber(rx_power))
metric("optical_transceiver_supply_voltage", "gauge", nil, tonumber(voltage))
end
local function get_page(page)
local handle = io.popen("/usr/bin/pontop -b -g '" .. page .. "'")
local result = handle:read("*a")
handle:close()
return parse_page(result)
end
local function parse_page(text)
local parameters = {}
for line in string.gmatch(text, "[^\r\n]+") do
-- (.+?)\\s+: (.+) doesn't work in Lua, maybe it's different regex flavour
local key, value = string.match(line, "^(.+): (.+)$")
if key and value then
local trimmed_key = key:gsub('^%s*(.-)%s*$', '%1')
parameters[trimmed_key] = value
end
end
return parameters
end
return { scrape = scrape }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment