summaryrefslogtreecommitdiff
path: root/files/common/openwrt/sensors_prometheus-node-exporter.lua
blob: 9aa0af710185b3a52fb2b448c42de7980238b1e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
local sensors = require "sensors"

local config, _ = sensors.read_config('/etc/sensors.json')
local num_sensors, _ = sensors.setup(config)
local units = {
    temperature = "celsius",
    humidity = "percent",
    pressure = "pascals",
    gpio = "status",
}

local function scrape()
    local readings, err = sensors.read(config)
    if not readings then return end

    metric("sensors_count_total", "gauge", nil, num_sensors)
    for name, values in pairs(readings) do
        labels = { name = name, kind = values._kind_ }
        for t, v in pairs(values) do
            local unit = units[t]
            if unit ~= nil then
                metric("sensors_" .. t .. "_" .. unit, "gauge", labels, v)
            end
        end
    end
end

return { scrape = scrape }