Software /
code /
prosody-modules
Diff
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 |
line wrap: on
line diff
--- a/mod_pubsub_serverinfo/mod_pubsub_serverinfo.lua Wed Nov 20 05:07:11 2024 +0100 +++ b/mod_pubsub_serverinfo/mod_pubsub_serverinfo.lua Sun Jan 05 17:50:02 2025 +0100 @@ -12,6 +12,7 @@ local public_providers_url = module:get_option_string(module.name.."_public_providers_url", "https://data.xmpp.net/providers/v2/providers-Ds.json"); local delete_node_on_unload = module:get_option_boolean(module.name.."_delete_node_on_unload", false); local persist_items = module:get_option_boolean(module.name.."_persist_items", true); +local include_user_count = module:get_option_boolean(module.name.."_publish_user_count", false); if not service and prosody.hosts["pubsub."..module.host] then service = "pubsub."..module.host; @@ -21,6 +22,11 @@ return; end +local metric_registry = require "core.statsmanager".get_metric_registry(); +if include_user_count then + module:depends("measure_active_users"); +end + local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; -- Needed to publish server-info-fields @@ -184,6 +190,10 @@ return domains_by_host end +local function get_gauge_metric(name) + return (metric_registry.families[name].data:get(module.host) or {}).value; +end + function publish_serverinfo() module:log("debug", "Publishing server info..."); local domains_by_host = get_remote_domain_names() @@ -211,7 +221,18 @@ end end - request:up():up() + request:up(); + + if include_user_count then + local mau = get_gauge_metric("prosody_mod_measure_active_users/active_users_30d"); + request:tag("users", { xmlns = "xmpp:prosody.im/protocol/serverinfo" }); + if mau then + request:text_tag("active", ("%d"):format(mau)); + end + request:up(); + end + + request:up() module:send_iq(request):next( function(response)