1 -- Authors: Relu Patrascu
2 -- License: LGPL, version 2.1 or later
3 -- Last Changed: 2004-11-05
5 -- statusd_cpuspeed.lua
7 -- Copyright (c) Relu Patrascu 2004.
9 -- Ion is free software; you can redistribute it and/or modify it under
10 -- the terms of the GNU Lesser General Public License as published by
11 -- the Free Software Foundation; either version 2.1 of the License, or
12 -- (at your option) any later version.
16 -- Neither am I a lua expert nor do I have the time to invest in writing
17 -- better code here. I simply needed this utility and it works OK for me.
18 -- I give no guarantees of any kind for this code. Suggestions for
19 -- improvement are welcome.
20 -- ikoflexer at gmail dot com
22 if not statusd_cpuspeed
then
23 statusd_cpuspeed
={ interval
=10*1000 }
27 local function get_cpuspeed_proc()
29 local f
=io
.open('/proc/cpuinfo', 'r')
35 st
, en
, cpuspeed
= string.find(s
, 'cpu MHz[%s]*:[%s]*(%d+%.%d+)')
36 return tostring(cpuspeed
)
39 local function get_cpuspeed_fn()
40 return get_cpuspeed_proc
43 local get_cpuspeed
, cpuspeed_timer
45 local function update_cpuspeed()
46 statusd
.inform("cpuspeed", get_cpuspeed())
47 cpuspeed_timer
:set(statusd_cpuspeed
.interval
, update_cpuspeed
)
51 get_cpuspeed
=get_cpuspeed_fn()
52 cpuspeed_timer
=statusd
.create_timer()