]> git.llucax.com Git - personal/ion3-config.git/commitdiff
Add lm-sensors statusd monitor. master
authorLeandro Lucarella <llucax@gmail.com>
Thu, 10 Jan 2008 23:38:01 +0000 (21:38 -0200)
committerLeandro Lucarella <llucax@gmail.com>
Thu, 10 Jan 2008 23:38:01 +0000 (21:38 -0200)
default/cfg_statusbar.lua
statusd_sensors.lua [new file with mode: 0644]

index 71ac8995af3ddce892e376f14d2268f1ddb0cc61..46652dd1b912626c1d07de65719b9190b66340ed 100644 (file)
@@ -42,7 +42,8 @@ mod_statusbar.create{
     -- windows and icons.
     --
     template = "%mpd %filler [mails: %exec_maildir | im: %exec_psi] " ..
-        "[mem: %mem_hused/%mem_cached/%mem_total | " ..
+        "[fan: %sensors_fan RPM | temp: %sensors_mb/%sensors_cpu C | " ..
+        "mem: %mem_hused/%mem_cached/%mem_total | " ..
        "swap: %mem_sw_used/%mem_sw_total | load: %load] %date %systray",
     --template="[ %date || load: %05load_1min || mail: %02mail_new/%02mail_total ] %filler%systray",
     --template="[ %date || load:% %>load ] %filler %systray_dock",
@@ -129,6 +130,16 @@ mod_statusbar.launch_statusd{
        used_sw_alarm = 75,
         units         = "m", -- "g" , "m" or "k"
     },
+    -- Sensors monitor
+    sensors = {
+        update_interval = 5 * 1000, -- 5 segs
+        fan_alarm = 4000,
+        mb_alarm = 45,
+        cpu_alarm = 55,
+        fan_file = '/sys/class/i2c-adapter/i2c-0/0-002d/fan1_input',
+        mb_file = '/sys/class/i2c-adapter/i2c-0/0-002d/temp1_input',
+        cpu_file = '/sys/class/i2c-adapter/i2c-0/0-002d/temp2_input',
+    },
 
     -- Scripts
     exec = {
diff --git a/statusd_sensors.lua b/statusd_sensors.lua
new file mode 100644 (file)
index 0000000..5860b41
--- /dev/null
@@ -0,0 +1,59 @@
+------- DEFAULT SETTINGS :------------------------------------------------------
+
+local sensors_timer
+local defaults = {
+       update_interval = 5*1000,
+       fan_alarm = 4000,
+       mb_alarm = 45,
+       cpu_alarm = 55,
+       fan_file = '/sys/class/i2c-adapter/i2c-0/0-002d/fan1_input',
+       mb_file = '/sys/class/i2c-adapter/i2c-0/0-002d/temp1_input',
+       cpu_file = '/sys/class/i2c-adapter/i2c-0/0-002d/temp2_input',
+}
+local settings = table.join(statusd.get_config("sensors"), defaults)
+
+------- SENSORS MONITOR :-------------------------------------------------------
+
+local function inform_fan(name, file, alarm)
+       file = io.open(file, 'r')
+       if file then
+               local level = 'normal'
+               local var = file:read('*n')
+               file:close()
+               if var <= alarm then level = 'critical' end
+               statusd.inform("sensors_" .. name, string.format('%d', var))
+               statusd.inform('sensors_' .. name .. '_hint', level)
+       end
+end
+
+local function inform_temp(name, file, alarm)
+       file = io.open(file, 'r')
+       if file then
+               local level = 'normal'
+               local var = file:read('*n') / 1000
+               file:close()
+               if var >= alarm then level = 'critical' end
+               statusd.inform("sensors_" .. name, string.format('%0.1f', var))
+               statusd.inform('sensors_' .. name .. '_hint', level)
+       end
+end
+
+local function inform_sensors()
+       inform_fan('fan', settings.fan_file, settings.fan_alarm + 0)
+       inform_temp('mb', settings.mb_file, settings.mb_alarm + 0)
+       inform_temp('cpu', settings.cpu_file, settings.cpu_alarm + 0)
+end
+
+local sensors_timer
+
+local function update_sensors()
+       inform_sensors()
+       sensors_timer:set(settings.update_interval, update_sensors)
+end
+
+-- Init
+sensors_timer=statusd.create_timer()
+update_sensors()
+
+
+