aboutsummaryrefslogtreecommitdiff
path: root/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/thermal.lua
blob: 3996ea581b54ad3da9ebbeac836526258abfa69a (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
-- thermal collector
local function scrape()
  local i = 0
  local temp_metric = metric("node_thermal_zone_temp", "gauge")

  while true do
    local zonePath = "/sys/class/thermal/thermal_zone" .. i

    -- required attributes

    local typ = string.match(get_contents(zonePath .. "/type"), "^%s*(.-)%s*$")
    if not typ then
      break
    end

    local policy = string.match(get_contents(zonePath .. "/policy"), "^%s*(.-)%s*$")
    if not policy then
      break
    end

    local temp = string.match(get_contents(zonePath .. "/temp"), "(%d+)")
    if not temp then
      break
    end

    local labels = {zone = i, type = typ, policy = policy}

    -- optional attributes

    local mode = string.match(get_contents(zonePath .. "/mode"), "^%s*(.-)%s*$")
    if mode then
      labels.mode = mode
    end

    local passive = string.match(get_contents(zonePath .. "/passive"), "(%d+)")
    if passive then
      labels.passive = passive
    end

    temp_metric(labels, temp / 1000)

    i = i + 1
  end
end

return { scrape = scrape }