diff 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
line wrap: on
line diff
--- a/mod_stats39/mod_stats39.lua	Sun Jan 19 19:27:17 2020 +0100
+++ b/mod_stats39/mod_stats39.lua	Sun Jan 19 19:27:46 2020 +0100
@@ -1,5 +1,6 @@
 local statsman = require "core.statsmanager";
 local st = require "util.stanza";
+local s_format = string.format;
 
 module:hook("iq/host/http://jabber.org/protocol/stats:query", function (event)
 	local origin, stanza = event.origin, event.stanza;
@@ -8,7 +9,7 @@
 	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();
+		reply:tag("stat", { name = stat, unit = unit, value = s_format("%.12g", value) }):up();
 	end
 	origin.send(reply);
 	return true;