Mercurial > prosody-modules
annotate mod_measure_client_presence/mod_measure_client_presence.lua @ 4989:b74d592df9e2
mod_http_muc_log: Remove dead code
This might be something left over since a different variant where the
loop went like `for n = i-1, i-100, -1 do ... end` i.e. it went trough a
fixed number of items instead of all the page until the current message.
Then it would have needed something to stop going over the end, but
since the checks are simple it shouldn't be much of a problem looping
over even a very busy day.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 16 Aug 2022 01:27:59 +0200 |
parents | 37ae0801f925 |
children |
rev | line source |
---|---|
2789
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 module:set_global(); |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 local measure = require"core.statsmanager".measure; |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 local valid_shows = { |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 available = true, |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 chat = true, |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 away = true, |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 dnd = true, |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 xa = true, |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 unavailable = true, |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 } |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 local counters = { |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 available = measure("amount", "client_presence.available"), |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 chat = measure("amount", "client_presence.chat"), |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 away = measure("amount", "client_presence.away"), |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 dnd = measure("amount", "client_presence.dnd"), |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 xa = measure("amount", "client_presence.xa"), |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 unavailable = measure("amount", "client_presence.unavailable"), |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 invalid = measure("amount", "client_presence.invalid"); |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 }; |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 module:hook("stats-update", function () |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 local buckets = { |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 available = 0, |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 chat = 0, |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 away = 0, |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 dnd = 0, |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 xa = 0, |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 unavailable = 0, |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 invalid = 0, |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 }; |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 for _, session in pairs(full_sessions) do |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 local status = "unavailable"; |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 if session.presence then |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 status = session.presence:get_child_text("show") or "available"; |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 end |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 if valid_shows[status] ~= nil then |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 buckets[status] = buckets[status] + 1; |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 else |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 buckets.invalid = buckets.invalid + 1; |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 end |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 end |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 for bucket, count in pairs(buckets) do |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 counters[bucket](count) |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 end |
37ae0801f925
mod_measure_client_presence: Counts presence show and reports using 0.10+ statistics API.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 end) |