cpustat.fnl (700B)
1 (fn parse-cpu-stat-line [line] 2 (let [labels [:user :nice :system :idle :iowait 3 :irq :softirq :steal :guest :guest_nice] 4 vals (icollect [field (line:gmatch "([%d.]+)")] 5 (tonumber field))] 6 (collect [i label (ipairs labels)] 7 label (. vals i)))) 8 9 (fn cpustat [proc-stat-handle] 10 (let [f proc-stat-handle] 11 (f:seek :set 0) 12 (accumulate [ret nil 13 line #(f:read "*l") 14 :until ret] 15 (if (= (string.sub line 1 (# "cpu ")) "cpu ") 16 (parse-cpu-stat-line line) 17 ret)))) 18 { 19 :new 20 #(let [handle (io.open "/proc/stat" :r)] 21 { 22 :read #(cpustat handle) 23 }) 24 }