comparison mod_measure_cpu/mod_measure_cpu.lua @ 1677:2a4c632a24cb

mod_measure_cpu: Collect CPU usage statistic
author Kim Alvefur <zash@zash.se>
date Thu, 23 Apr 2015 17:00:59 +0200
parents
children 8357cabc31f6
comparison
equal deleted inserted replaced
1676:accbf0db0246 1677:2a4c632a24cb
1 module:set_global();
2
3 local measure = require"core.statsmanager".measure;
4 local mt = require"util.multitable";
5 local get_time = require "socket".gettime;
6 local get_clock = os.clock;
7
8 local measure_cpu_now = measure("amount", "cpu.percent"); -- Current percentage
9
10 local last_cpu_wall, last_cpu_clock;
11 module:hook("stats-update", function ()
12 local new_wall, new_clock = get_time(), get_clock();
13 local pc = 0;
14 if last_cpu_wall then
15 pc = 100/((new_wall-last_cpu_wall)/(new_clock-last_cpu_clock));
16 end
17 last_cpu_wall, last_cpu_clock = new_wall, new_clock;
18
19 measure_cpu_now(pc);
20 end);
21
22 -- Some metadata for mod_munin
23 local munin_meta = mt.new(); munin_meta.data = module:shared"munin/meta";
24 local key = "global_cpu_amount";
25
26 munin_meta:set(key, "", "graph_args", "--base 1000 -r --lower-limit 0 --upper-limit 100");
27 munin_meta:set(key, "", "graph_title", "Prosody CPU Usage");
28 munin_meta:set(key, "", "graph_vlabel", "%");
29 munin_meta:set(key, "", "graph_category", "cpu");
30
31 munin_meta:set(key, "percent", "label", "CPU Usage");
32 munin_meta:set(key, "percent", "min", "0");
33