Comparison

mod_measure_client_presence/mod_measure_client_presence.lua @ 2789:37ae0801f925

mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 09 Oct 2017 19:28:17 +0100
comparison
equal deleted inserted replaced
2788:512405077709 2789:37ae0801f925
1 module:set_global();
2
3 local measure = require"core.statsmanager".measure;
4
5 local valid_shows = {
6 available = true,
7 chat = true,
8 away = true,
9 dnd = true,
10 xa = true,
11 unavailable = true,
12 }
13
14 local counters = {
15 available = measure("amount", "client_presence.available"),
16 chat = measure("amount", "client_presence.chat"),
17 away = measure("amount", "client_presence.away"),
18 dnd = measure("amount", "client_presence.dnd"),
19 xa = measure("amount", "client_presence.xa"),
20 unavailable = measure("amount", "client_presence.unavailable"),
21 invalid = measure("amount", "client_presence.invalid");
22 };
23
24 module:hook("stats-update", function ()
25 local buckets = {
26 available = 0,
27 chat = 0,
28 away = 0,
29 dnd = 0,
30 xa = 0,
31 unavailable = 0,
32 invalid = 0,
33 };
34 for _, session in pairs(full_sessions) do
35 local status = "unavailable";
36 if session.presence then
37 status = session.presence:get_child_text("show") or "available";
38 end
39 if valid_shows[status] ~= nil then
40 buckets[status] = buckets[status] + 1;
41 else
42 buckets.invalid = buckets.invalid + 1;
43 end
44 end
45 for bucket, count in pairs(buckets) do
46 counters[bucket](count)
47 end
48 end)