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 }
|