Mercurial > prosody-modules
comparison mod_pubsub_stats/mod_pubsub_stats.lua @ 3068:380f92276e57
mod_pubsub_stats: Make the node used configurable
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 29 May 2018 05:34:05 +0200 |
parents | b01ef74c9fc0 |
children | 8a870e0319db |
comparison
equal
deleted
inserted
replaced
3067:b01ef74c9fc0 | 3068:380f92276e57 |
---|---|
2 local dt = require "util.datetime"; | 2 local dt = require "util.datetime"; |
3 | 3 |
4 local pubsub = module:depends"pubsub"; | 4 local pubsub = module:depends"pubsub"; |
5 | 5 |
6 local actor = module.host .. "/modules/" .. module.name; | 6 local actor = module.host .. "/modules/" .. module.name; |
7 | |
8 local node = module:get_option_string(module.name .. "_node", "stats"); | |
7 | 9 |
8 local function publish_stats(stats, stats_extra) | 10 local function publish_stats(stats, stats_extra) |
9 local id = "current"; | 11 local id = "current"; |
10 local xitem = st.stanza("item", { id = id }) | 12 local xitem = st.stanza("item", { id = id }) |
11 :tag("query", { xmlns = "http://jabber.org/protocol/stats" }); | 13 :tag("query", { xmlns = "http://jabber.org/protocol/stats" }); |
14 local stat_extra = stats_extra[name]; | 16 local stat_extra = stats_extra[name]; |
15 local unit = stat_extra and stat_extra.units; | 17 local unit = stat_extra and stat_extra.units; |
16 xitem:tag("stat", { name = name, unit = unit, value = tostring(value) }):up(); | 18 xitem:tag("stat", { name = name, unit = unit, value = tostring(value) }):up(); |
17 end | 19 end |
18 | 20 |
19 local ok, err = pubsub.service:publish("stats", actor, id, xitem); | 21 local ok, err = pubsub.service:publish(node, actor, id, xitem); |
20 if not ok then | 22 if not ok then |
21 module:log("error", "Error publishing stats: %s", err); | 23 module:log("error", "Error publishing stats: %s", err); |
22 end | 24 end |
23 end | 25 end |
24 | 26 |
25 function module.load() | 27 function module.load() |
26 pubsub.service:create("stats", true); | 28 pubsub.service:create(node, true); |
27 pubsub.service:set_affiliation("stats", true, actor, "publisher"); | 29 pubsub.service:set_affiliation(node, true, actor, "publisher"); |
28 end | 30 end |
29 | 31 |
30 module:hook_global("stats-updated", function (event) | 32 module:hook_global("stats-updated", function (event) |
31 publish_stats(event.stats, event.stats_extra); | 33 publish_stats(event.stats, event.stats_extra); |
32 end); | 34 end); |
33 | 35 |
34 function module.unload() | 36 function module.unload() |
35 pubsub.service:delete("stats", true); | 37 pubsub.service:delete(node, true); |
36 end | 38 end |