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
70 function read_file(path
)
71 local fd
= io
.open(path
, "r")
76 local text
= fd
:read("*a")
79 if type(text
) == 'string' then
80 text
= text
:match('(%w+)')
86 local function create_string(cpu
)
87 local govfile
= cpu
.. '/cpufreq/scaling_governor'
88 local gov
= read_file(govfile
) or ""
90 local frqfile
= cpu
.. '/cpufreq/scaling_cur_freq'
91 local frq
= read_file(frqfile
) or ""
93 if type(frq
) == 'string' then
94 local mhz
= frq
:match('(.*)000')
104 return gov
.. " " .. frq
107 function update ( new_vol
)
110 local list
= cpu_list()
111 for _
,cpu
in pairs(list
) do
112 txt
= txt
.. create_string(cpu
) .. " "
118 local function cpu_timer(timer
)
123 timer
= wmii
.timer
:new (cpu_timer
, 1)