Released version 3-2015061300
[notion.git] / contrib / statusd / statusd_cpufreq.lua
blob138057238719f3627e4258c3c7c8a5fd4690a1f1
1 -- Authors: Unknown
2 -- License: Public domain
3 -- Last Changed: Unknown
4 --
5 -- statusd_cpufreq.lua
6 --
7 -- Public domain
8 --
9 -- Use the key "cpufreq_[KMG]" to get the current CPU frequency in
10 -- K/M/GHz, according to /sys/devices/system/cpu/cpuX/cpufreq/. (This
11 -- has the advantage of being a much "rounder" number than the one in
12 -- /proc/cpuinfo, as provided by statusd_cpuspeed.lua.)
13 --
14 -- The "cpu" option to the statusd settings for cpufreq modifies which
15 -- cpu we look at.
17 local defaults={ update_interval=2*1000, cpu=0 }
18 local settings=table.join(statusd.get_config("cpufreq"), defaults)
20 function get_cpufreq()
21 local f=io.open('/sys/devices/system/cpu/cpu'.. settings.cpu ..'/cpufreq/scaling_cur_freq')
22 local cpufreq_K = f:read('*a')
23 f:close()
25 local cpufreq_M = cpufreq_K / 1000
26 local cpufreq_G = cpufreq_M / 1000
28 return tostring(cpufreq_K), tostring(cpufreq_M), tostring(cpufreq_G)
29 end
31 function update_cpufreq()
32 local cpufreq_K, cpufreq_M, cpufreq_G = get_cpufreq()
33 statusd.inform("cpufreq_K", cpufreq_K)
34 statusd.inform("cpufreq_M", cpufreq_M)
35 statusd.inform("cpufreq_G", cpufreq_G)
36 cpufreq_timer:set(settings.update_interval, update_cpufreq)
37 end
39 cpufreq_timer = statusd.create_timer()
40 update_cpufreq()