Mercurial > prosody-modules
comparison mod_measure_stanza_counts/mod_measure_stanza_counts.lua @ 2787:750572f6f59d
mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 09 Oct 2017 20:15:33 +0200 |
parents | |
children | 512405077709 |
comparison
equal
deleted
inserted
replaced
2786:127d5452e4bb | 2787:750572f6f59d |
---|---|
1 module:set_global() | |
2 | |
3 local filters = require"util.filters"; | |
4 | |
5 local stanza_kinds = { message = true, presence = true, iq = true }; | |
6 | |
7 local function rate(measures, dir) | |
8 return function (stanza, session) | |
9 measures[dir](); | |
10 measures[dir .. "_" .. session.type](); | |
11 if not stanza.attr.xmlns and stanza_kinds[stanza.name] then | |
12 measures[dir .. "_" .. session.type .. "_" .. stanza.name](); | |
13 end | |
14 return stanza; | |
15 end | |
16 end | |
17 | |
18 local measures = setmetatable({}, { | |
19 __index = function (t, name) | |
20 local m = module:measure(name, "rate"); | |
21 t[name] = m; | |
22 return m; | |
23 end | |
24 }); | |
25 | |
26 local function measure_stanza_counts(session) | |
27 filters.add_filter(session, "stanzas/in", rate(measures, "incoming")); | |
28 filters.add_filter(session, "stanzas/out", rate(measures, "outgoing")); | |
29 end | |
30 | |
31 filters.add_filter_hook(measure_stanza_counts); |