From: Leandro Lucarella Date: Thu, 10 Jan 2008 23:38:01 +0000 (-0200) Subject: Add lm-sensors statusd monitor. X-Git-Url: https://git.llucax.com/personal/ion3-config.git/commitdiff_plain/b762abdf2d0934d02ad9434adf993a68243340d4?ds=sidebyside;hp=f78989ef08affaa64a00d940cd3a41b0445312b0 Add lm-sensors statusd monitor. --- diff --git a/default/cfg_statusbar.lua b/default/cfg_statusbar.lua index 71ac899..46652dd 100644 --- a/default/cfg_statusbar.lua +++ b/default/cfg_statusbar.lua @@ -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 index 0000000..5860b41 --- /dev/null +++ b/statusd_sensors.lua @@ -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() + + +