Annotate

plugins/mod_csi.lua @ 13026:a97f4b277221

mod_csi: Drop summary stats, doesn't work in normal module This method ends up going up for each collection and the :clear() method is only available to global modules (see e.g. mod_c2s), while regular per-host modules get scoped stats
author Kim Alvefur <zash@zash.se>
date Thu, 06 Apr 2023 08:36:39 +0200
parent 13025:b7d0c1d75a37
child 13070:be9ac41f1619
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12977
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 10429
diff changeset
1 local st = require "prosody.util.stanza";
9073
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local xmlns_csi = "urn:xmpp:csi:0";
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local csi_feature = st.stanza("csi", { xmlns = xmlns_csi });
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
13025
b7d0c1d75a37 mod_csi: Add metrics, covering changes and totals
Kim Alvefur <zash@zash.se>
parents: 12977
diff changeset
5 local change = module:metric("counter", "changes", "events", "CSI state changes", {"csi_state"});
b7d0c1d75a37 mod_csi: Add metrics, covering changes and totals
Kim Alvefur <zash@zash.se>
parents: 12977
diff changeset
6
10429
0b04d25c4ffb mod_csi: Cache CSI module availability to improve readabilty
Kim Alvefur <zash@zash.se>
parents: 10428
diff changeset
7 local csi_handler_available = nil;
9073
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 module:hook("stream-features", function (event)
10429
0b04d25c4ffb mod_csi: Cache CSI module availability to improve readabilty
Kim Alvefur <zash@zash.se>
parents: 10428
diff changeset
9 if event.origin.username and csi_handler_available then
9073
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 event.features:add_child(csi_feature);
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 end
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 end);
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 function refire_event(name)
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 return function (event)
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 if event.origin.username then
9653
91856829f18b mod_csi: Fix copypaste mistake [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9651
diff changeset
17 event.origin.state = event.stanza.name;
13025
b7d0c1d75a37 mod_csi: Add metrics, covering changes and totals
Kim Alvefur <zash@zash.se>
parents: 12977
diff changeset
18 change:with_labels(event.stanza.name):add(1);
9073
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 module:fire_event(name, event);
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 return true;
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 end
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end;
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 end
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 module:hook("stanza/"..xmlns_csi..":active", refire_event("csi-client-active"));
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 module:hook("stanza/"..xmlns_csi..":inactive", refire_event("csi-client-inactive"));
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27
10428
12a10208d86a mod_csi: Set module status based on whether a CSI handler module appears to be loaded
Kim Alvefur <zash@zash.se>
parents: 10427
diff changeset
28 function module.load()
12a10208d86a mod_csi: Set module status based on whether a CSI handler module appears to be loaded
Kim Alvefur <zash@zash.se>
parents: 10427
diff changeset
29 if prosody.hosts[module.host].events._handlers["csi-client-active"] then
10429
0b04d25c4ffb mod_csi: Cache CSI module availability to improve readabilty
Kim Alvefur <zash@zash.se>
parents: 10428
diff changeset
30 csi_handler_available = true;
10428
12a10208d86a mod_csi: Set module status based on whether a CSI handler module appears to be loaded
Kim Alvefur <zash@zash.se>
parents: 10427
diff changeset
31 module:set_status("core", "CSI handler module loaded");
12a10208d86a mod_csi: Set module status based on whether a CSI handler module appears to be loaded
Kim Alvefur <zash@zash.se>
parents: 10427
diff changeset
32 else
10429
0b04d25c4ffb mod_csi: Cache CSI module availability to improve readabilty
Kim Alvefur <zash@zash.se>
parents: 10428
diff changeset
33 csi_handler_available = false;
10428
12a10208d86a mod_csi: Set module status based on whether a CSI handler module appears to be loaded
Kim Alvefur <zash@zash.se>
parents: 10427
diff changeset
34 module:set_status("warn", "No CSI handler module loaded");
12a10208d86a mod_csi: Set module status based on whether a CSI handler module appears to be loaded
Kim Alvefur <zash@zash.se>
parents: 10427
diff changeset
35 end
12a10208d86a mod_csi: Set module status based on whether a CSI handler module appears to be loaded
Kim Alvefur <zash@zash.se>
parents: 10427
diff changeset
36 end
12a10208d86a mod_csi: Set module status based on whether a CSI handler module appears to be loaded
Kim Alvefur <zash@zash.se>
parents: 10427
diff changeset
37 module:hook("module-loaded", module.load);
12a10208d86a mod_csi: Set module status based on whether a CSI handler module appears to be loaded
Kim Alvefur <zash@zash.se>
parents: 10427
diff changeset
38 module:hook("module-unloaded", module.load);