Software /
code /
prosody-modules
Comparison
mod_pubsub_serverinfo/mod_pubsub_serverinfo.lua @ 6138:9db1529c06c2
Merge upstream
author | tmolitor <thilo@eightysoft.de> |
---|---|
date | Sun, 05 Jan 2025 17:50:02 +0100 |
parent | 6059:25b091cbb471 |
comparison
equal
deleted
inserted
replaced
6137:4cb1cad2badd | 6138:9db1529c06c2 |
---|---|
10 local publication_interval = module:get_option_number(module.name .. "_publication_interval", 300); | 10 local publication_interval = module:get_option_number(module.name .. "_publication_interval", 300); |
11 local cache_ttl = module:get_option_number(module.name .. "_cache_ttl", 3600); | 11 local cache_ttl = module:get_option_number(module.name .. "_cache_ttl", 3600); |
12 local public_providers_url = module:get_option_string(module.name.."_public_providers_url", "https://data.xmpp.net/providers/v2/providers-Ds.json"); | 12 local public_providers_url = module:get_option_string(module.name.."_public_providers_url", "https://data.xmpp.net/providers/v2/providers-Ds.json"); |
13 local delete_node_on_unload = module:get_option_boolean(module.name.."_delete_node_on_unload", false); | 13 local delete_node_on_unload = module:get_option_boolean(module.name.."_delete_node_on_unload", false); |
14 local persist_items = module:get_option_boolean(module.name.."_persist_items", true); | 14 local persist_items = module:get_option_boolean(module.name.."_persist_items", true); |
15 local include_user_count = module:get_option_boolean(module.name.."_publish_user_count", false); | |
15 | 16 |
16 if not service and prosody.hosts["pubsub."..module.host] then | 17 if not service and prosody.hosts["pubsub."..module.host] then |
17 service = "pubsub."..module.host; | 18 service = "pubsub."..module.host; |
18 end | 19 end |
19 if not service then | 20 if not service then |
20 module:log_status("warn", "No pubsub service specified - module not activated"); | 21 module:log_status("warn", "No pubsub service specified - module not activated"); |
21 return; | 22 return; |
23 end | |
24 | |
25 local metric_registry = require "core.statsmanager".get_metric_registry(); | |
26 if include_user_count then | |
27 module:depends("measure_active_users"); | |
22 end | 28 end |
23 | 29 |
24 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; | 30 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; |
25 | 31 |
26 -- Needed to publish server-info-fields | 32 -- Needed to publish server-info-fields |
182 end | 188 end |
183 | 189 |
184 return domains_by_host | 190 return domains_by_host |
185 end | 191 end |
186 | 192 |
193 local function get_gauge_metric(name) | |
194 return (metric_registry.families[name].data:get(module.host) or {}).value; | |
195 end | |
196 | |
187 function publish_serverinfo() | 197 function publish_serverinfo() |
188 module:log("debug", "Publishing server info..."); | 198 module:log("debug", "Publishing server info..."); |
189 local domains_by_host = get_remote_domain_names() | 199 local domains_by_host = get_remote_domain_names() |
190 | 200 |
191 -- Build the publication stanza. | 201 -- Build the publication stanza. |
209 request:tag("remote-domain"):up() | 219 request:tag("remote-domain"):up() |
210 end | 220 end |
211 end | 221 end |
212 end | 222 end |
213 | 223 |
214 request:up():up() | 224 request:up(); |
225 | |
226 if include_user_count then | |
227 local mau = get_gauge_metric("prosody_mod_measure_active_users/active_users_30d"); | |
228 request:tag("users", { xmlns = "xmpp:prosody.im/protocol/serverinfo" }); | |
229 if mau then | |
230 request:text_tag("active", ("%d"):format(mau)); | |
231 end | |
232 request:up(); | |
233 end | |
234 | |
235 request:up() | |
215 | 236 |
216 module:send_iq(request):next( | 237 module:send_iq(request):next( |
217 function(response) | 238 function(response) |
218 if response.stanza == nil or response.stanza.attr.type ~= "result" then | 239 if response.stanza == nil or response.stanza.attr.type ~= "result" then |
219 module:log("warn", "Unexpected response to item publication at pub/sub node '%s' on %s: %s", node, service, response.stanza) | 240 module:log("warn", "Unexpected response to item publication at pub/sub node '%s' on %s: %s", node, service, response.stanza) |