summaryrefslogtreecommitdiff
path: root/files/common/openwrt/sensors_promethues-node-exporter.lua
blob: 776f15b57daa1d4bd1f62128224bab5afc5b648d (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 = "pascal",
}

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 }