Mercurial > prosody-modules
comparison mod_stats39/mod_stats39.lua @ 3846:3941768916f1
mod_stats39: Format numbers with a bit more precision
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 19 Jan 2020 19:27:46 +0100 |
| parents | 054898e84a04 |
| children | ffc64d285a96 |
comparison
equal
deleted
inserted
replaced
| 3845:117f0fb8cb15 | 3846:3941768916f1 |
|---|---|
| 1 local statsman = require "core.statsmanager"; | 1 local statsman = require "core.statsmanager"; |
| 2 local st = require "util.stanza"; | 2 local st = require "util.stanza"; |
| 3 local s_format = string.format; | |
| 3 | 4 |
| 4 module:hook("iq/host/http://jabber.org/protocol/stats:query", function (event) | 5 module:hook("iq/host/http://jabber.org/protocol/stats:query", function (event) |
| 5 local origin, stanza = event.origin, event.stanza; | 6 local origin, stanza = event.origin, event.stanza; |
| 6 local stats, _, extra = statsman.get_stats(); | 7 local stats, _, extra = statsman.get_stats(); |
| 7 local reply = st.reply(stanza); | 8 local reply = st.reply(stanza); |
| 8 reply:tag("query", { xmlns = "http://jabber.org/protocol/stats" }); | 9 reply:tag("query", { xmlns = "http://jabber.org/protocol/stats" }); |
| 9 for stat, value in pairs(stats) do | 10 for stat, value in pairs(stats) do |
| 10 local unit = extra[stat] and extra[stat].units; | 11 local unit = extra[stat] and extra[stat].units; |
| 11 reply:tag("stat", { name = stat, unit = unit, value = tostring(value) }):up(); | 12 reply:tag("stat", { name = stat, unit = unit, value = s_format("%.12g", value) }):up(); |
| 12 end | 13 end |
| 13 origin.send(reply); | 14 origin.send(reply); |
| 14 return true; | 15 return true; |
| 15 end) | 16 end) |
