Software /
code /
prosody-modules
Comparison
mod_measure_cpu/mod_measure_cpu.lua @ 3431:8357cabc31f6
mod_measure_cpu: Also report the raw clock value, whatever that is
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 05 Jan 2019 18:44:50 +0100 |
parent | 1677:2a4c632a24cb |
child | 3444:e0fb97f47212 |
comparison
equal
deleted
inserted
replaced
3430:6e70d354b7d8 | 3431:8357cabc31f6 |
---|---|
4 local mt = require"util.multitable"; | 4 local mt = require"util.multitable"; |
5 local get_time = require "socket".gettime; | 5 local get_time = require "socket".gettime; |
6 local get_clock = os.clock; | 6 local get_clock = os.clock; |
7 | 7 |
8 local measure_cpu_now = measure("amount", "cpu.percent"); -- Current percentage | 8 local measure_cpu_now = measure("amount", "cpu.percent"); -- Current percentage |
9 local measure_cpu_now = measure("counter", "cpu.clock"); | |
9 | 10 |
10 local last_cpu_wall, last_cpu_clock; | 11 local last_cpu_wall, last_cpu_clock; |
11 module:hook("stats-update", function () | 12 module:hook("stats-update", function () |
12 local new_wall, new_clock = get_time(), get_clock(); | 13 local new_wall, new_clock = get_time(), get_clock(); |
13 local pc = 0; | 14 local pc = 0; |
15 pc = 100/((new_wall-last_cpu_wall)/(new_clock-last_cpu_clock)); | 16 pc = 100/((new_wall-last_cpu_wall)/(new_clock-last_cpu_clock)); |
16 end | 17 end |
17 last_cpu_wall, last_cpu_clock = new_wall, new_clock; | 18 last_cpu_wall, last_cpu_clock = new_wall, new_clock; |
18 | 19 |
19 measure_cpu_now(pc); | 20 measure_cpu_now(pc); |
21 measure_cpu_now(new_clock); | |
20 end); | 22 end); |
21 | 23 |
22 -- Some metadata for mod_munin | 24 -- Some metadata for mod_munin |
23 local munin_meta = mt.new(); munin_meta.data = module:shared"munin/meta"; | 25 local munin_meta = mt.new(); munin_meta.data = module:shared"munin/meta"; |
24 local key = "global_cpu_amount"; | 26 local key = "global_cpu_amount"; |