From e5da3bbf0bdfb7f1a893804c0e8ced28ab46ce31 Mon Sep 17 00:00:00 2001 From: Jan-David Quesel Date: Tue, 19 Feb 2008 09:16:46 +0100 Subject: [PATCH] Added plugin to monitor current CPU state using ACPI --- plugins/cpu.lua | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 plugins/cpu.lua diff --git a/plugins/cpu.lua b/plugins/cpu.lua new file mode 100644 index 0000000..79273a4 --- /dev/null +++ b/plugins/cpu.lua @@ -0,0 +1,90 @@ +--[[ +=pod + +=head1 NAME + +cpu.lua - wmiirc-lua plugin for monitoring acpi stuff + +=head1 SYNOPSIS + + -- in your wmiirc.lua: + wmii.load_plugin("cpu") + + +=head1 DESCRIPTION + +=head1 SEE ALSO + +L, L + +=head1 AUTHOR + +Jan-David Quesel + +=head1 LICENCE AND COPYRIGHT + +Copyright (c) 2008, Jan-David Quesel + +This is free software. You may redistribute copies of it under the terms of +the GNU General Public License L. There +is NO WARRANTY, to the extent permitted by law. + +=cut +--]] + +local wmii = require("wmii") +local os = require("os") +local io = require("io") +local type = type +local error = error + +module("cpu") +api_version = 0.1 + +-- ------------------------------------------------------------ +-- MODULE VARIABLES +local widget = nil +local timer = nil + +widget = wmii.widget:new ("400_cpu") + +local function _command ( cmd ) + + if (cmd) then + wmii.log( "about to run " .. cmd) + local file = io.popen( cmd) + local status = file:read("*a") + file:close() + + return status:match("[^\n]*") + else + return "" + end +end + +local function create_string ( ) + wmii.log( "create string") + local cmd = "cpufreq-info |grep 'current CPU fre'|uniq | awk '{print $5 $6}'" + local cmd2 = "cpufreq-info | grep \'The gove\'|awk '{print $3}' | uniq" + local cmd3 = "echo `awk '/remaining/ {print $3}' /proc/acpi/battery/BAT0/state`\*100/`awk '/last/ {print $4}' /proc/acpi/battery/BAT0/info` | bc" + local str2 = _command(cmd2) + str2 = str2.sub(str2, 2, str2.len(str2)-1) + local str = _command(cmd) + str = str.sub(str, 1, str.len(str)-1) + return str .. "(" .. str2 .. ") BAT0: " .. _command(cmd3) .. "%" +end + +function update ( new_vol ) + local str = create_string() + + widget:show(str) +end + +local function cpu_timer ( timer ) + + wmii.log("cpu_timer()") + update(0) + return 10 +end + +timer = wmii.timer:new (cpu_timer, 1) -- 2.11.4.GIT