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

local config, _ = sensors.read_config('/etc/sensors.json')
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

    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 }