6 cpu.lua - wmiirc-lua plugin for monitoring acpi stuff
10 -- in your wmiirc.lua:
11 wmii.load_plugin("cpu")
22 Jan-David Quesel <jdq@gmx.net>
24 =head1 LICENCE AND COPYRIGHT
26 Copyright (c) 2008, Jan-David Quesel <jdq@gmx.net>
28 This is free software. You may redistribute copies of it under the terms of
29 the GNU General Public License L<http://www.gnu.org/licenses/gpl.html>. There
30 is NO WARRANTY, to the extent permitted by law.
35 local wmii
= require("wmii")
36 local os
= require("os")
37 local posix
= require("posix")
38 local io
= require("io")
42 local tostring = tostring
47 -- ------------------------------------------------------------
52 widget
= wmii
.widget
:new ("400_cpu")
54 local function cpu_list()
55 local dir
= "/sys/devices/system/cpu/"
58 for _
,cpu
in pairs(posix
.glob(dir
.. 'cpu[0-9]*')) do
61 stat
= posix
.stat(cpu
)
62 if stat
and stat
.type == 'directory' then
71 function read_file(path
)
72 local fd
= io
.open(path
, "r")
77 local text
= fd
:read("*a")
80 if type(text
) == 'string' then
81 text
= text
:match('(%w+)')
88 local function create_string(cpu
)
89 local govfile
= cpu
.. '/cpufreq/scaling_governor'
90 local gov
= read_file(govfile
) or ""
92 local frqfile
= cpu
.. '/cpufreq/scaling_cur_freq'
93 local frq
= read_file(frqfile
) or ""
95 if type(frq
) == 'string' then
96 local mhz
= frq
:match('(.*)000')
106 return frq
.. "(" .. gov
.. ")"
110 function update ( new_vol
)
113 local list
= cpu_list()
115 for _
,cpu
in pairs(list
) do
116 local str
= create_string(cpu
)
120 txt
= txt
.. create_string(cpu
) .. space
128 local function cpu_timer ( timer
)
133 timer
= wmii
.timer
:new (cpu_timer
, 1)