Include notionflux in the main repo instead of its own submodule
[notion/jeffpc.git] / contrib / statusd / statusd_cpuspeed.lua
bloba2d88bd6f894bebdfd7f25e2caaf28d32357d7d0
1 -- Authors: Relu Patrascu
2 -- License: LGPL, version 2.1 or later
3 -- Last Changed: 2004-11-05
4 --
5 -- statusd_cpuspeed.lua
6 --
7 -- Copyright (c) Relu Patrascu 2004.
8 --
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.
14 -- Nov. 5, 2004
15 -- Disclaimer
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 }
24 end
26 local cpuspeed
27 local function get_cpuspeed_proc()
28 local st,en
29 local f=io.open('/proc/cpuinfo', 'r')
30 if not f then
31 return ""
32 end
33 local s=f:read('*a')
34 f:close()
35 st, en, cpuspeed = string.find(s, 'cpu MHz[%s]*:[%s]*(%d+%.%d+)')
36 return tostring(cpuspeed)
37 end
39 local function get_cpuspeed_fn()
40 return get_cpuspeed_proc
41 end
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)
48 end
50 -- Init
51 get_cpuspeed=get_cpuspeed_fn()
52 cpuspeed_timer=statusd.create_timer()
53 update_cpuspeed()