Software /
code /
prosody-modules
Changeset
6059:25b091cbb471
mod_pubsub_serverinfo: Allow including the count of active users in the published info
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 22 Nov 2024 19:09:10 +0000 |
parents | 6058:e905ef16efb7 |
children | 6060:c7c17fac41b3 |
files | mod_pubsub_serverinfo/README.md mod_pubsub_serverinfo/mod_pubsub_serverinfo.lua |
diffstat | 2 files changed, 28 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_pubsub_serverinfo/README.md Fri Nov 22 19:05:49 2024 +0000 +++ b/mod_pubsub_serverinfo/README.md Fri Nov 22 19:09:10 2024 +0000 @@ -50,6 +50,12 @@ pubsub_serverinfo_cache_ttl = 1800 -- or any other number of seconds +To include the count of active (within the past 30 days) users: + + pubsub_serverinfo_publish_user_count = true + +Enabling this option will automatically load mod_measure_active_users. + Compatibility =============
--- a/mod_pubsub_serverinfo/mod_pubsub_serverinfo.lua Fri Nov 22 19:05:49 2024 +0000 +++ b/mod_pubsub_serverinfo/mod_pubsub_serverinfo.lua Fri Nov 22 19:09:10 2024 +0000 @@ -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)