Mercurial > prosody-modules
changeset 3839:a4b05f34a790
mod_stats39: Provides statsmanager stats via XEP-0039
The @name attrs are just Prosodys internal names for stats.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 08 Jan 2020 20:53:57 +0100 |
parents | 9f0c10bd4633 |
children | 054898e84a04 |
files | mod_stats39/mod_stats39.lua |
diffstat | 1 files changed, 15 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_stats39/mod_stats39.lua Wed Jan 08 20:53:57 2020 +0100 @@ -0,0 +1,15 @@ +local statsman = require "core.statsmanager"; +local st = require "util.stanza"; + +module:hook("iq/host/http://jabber.org/protocol/stats:query", function (event) + local origin, stanza = event.origin, event.stanza; + local stats, _, extra = statsman.get_stats(); + local reply = st.reply(event.stanza); + reply:tag("query", { xmlns = "http://jabber.org/protocol/stats" }); + for stat, value in pairs(stats) do + local unit = extra[stat] and extra[stat].units; + reply:tag("stat", { name = stat, unit = unit, value = tostring(value) }):up(); + end + origin.send(reply); + return true; +end)