]> git.llucax.com Git - personal/ion3-config.git/blob - statusd_sensors.lua
Add lm-sensors statusd monitor.
[personal/ion3-config.git] / statusd_sensors.lua
1 ------- DEFAULT SETTINGS :------------------------------------------------------
2
3 local sensors_timer
4 local defaults = {
5         update_interval = 5*1000,
6         fan_alarm = 4000,
7         mb_alarm = 45,
8         cpu_alarm = 55,
9         fan_file = '/sys/class/i2c-adapter/i2c-0/0-002d/fan1_input',
10         mb_file = '/sys/class/i2c-adapter/i2c-0/0-002d/temp1_input',
11         cpu_file = '/sys/class/i2c-adapter/i2c-0/0-002d/temp2_input',
12 }
13 local settings = table.join(statusd.get_config("sensors"), defaults)
14
15 ------- SENSORS MONITOR :-------------------------------------------------------
16
17 local function inform_fan(name, file, alarm)
18         file = io.open(file, 'r')
19         if file then
20                 local level = 'normal'
21                 local var = file:read('*n')
22                 file:close()
23                 if var <= alarm then level = 'critical' end
24                 statusd.inform("sensors_" .. name, string.format('%d', var))
25                 statusd.inform('sensors_' .. name .. '_hint', level)
26         end
27 end
28
29 local function inform_temp(name, file, alarm)
30         file = io.open(file, 'r')
31         if file then
32                 local level = 'normal'
33                 local var = file:read('*n') / 1000
34                 file:close()
35                 if var >= alarm then level = 'critical' end
36                 statusd.inform("sensors_" .. name, string.format('%0.1f', var))
37                 statusd.inform('sensors_' .. name .. '_hint', level)
38         end
39 end
40
41 local function inform_sensors()
42         inform_fan('fan', settings.fan_file, settings.fan_alarm + 0)
43         inform_temp('mb', settings.mb_file, settings.mb_alarm + 0)
44         inform_temp('cpu', settings.cpu_file, settings.cpu_alarm + 0)
45 end
46
47 local sensors_timer
48
49 local function update_sensors()
50         inform_sensors()
51         sensors_timer:set(settings.update_interval, update_sensors)
52 end
53
54 -- Init
55 sensors_timer=statusd.create_timer()
56 update_sensors()
57
58
59