if not statusd_cpu_p then statusd_cpu_p={ interval=1*1000, last_idle = 0, } end local get_cpu_p, cpu_p_timer local function get_proc_cpu() local f=io.open('/proc/stat', 'r') if not f then return "" end local s=f:read('*l') local st, en, user, nice, system, idle, io_wait, irq, softirq = string.find(s, '(%d+) (%d+) (%d+) (%d+) (%d+) (%d+) (%d+)') local total=user+nice+system+idle+io_wait+irq+softirq f:close () local idle_diff=idle-statusd_cpu_p.last_idle statusd_cpu_p.last_idle=idle if idle_diff > 100 then idle_diff=100 end if idle_diff < 0 then idle_diff=0 end return 100-idle_diff end local function meter() local m = "" for i = 1, 10 do if i*10 > get_cpu_p then m = m .. "." else m = m .. "|" end end return m end local function p() return tostring(get_cpu_p) .. "%" end local function update_cpu_p() get_cpu_p=get_proc_cpu() statusd.inform("cpu_p", p()) statusd.inform("cpu_meter", meter()) cpu_p_timer:set(statusd_cpu_p.interval, update_cpu_p) end -- Init get_cpu_p=get_proc_cpu() cpu_p_timer=statusd.create_timer() update_cpu_p()