-- 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",
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 = {
--- /dev/null
+------- 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()
+
+
+