summaryrefslogtreecommitdiff
path: root/files/common/openwrt/sensors_promethues-node-exporter.lua
blob: 9c814659392ee6283e160dd9f4b7328694cf597d (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
local sensors = require "sensors"

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

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

    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 }