Mercurial > prosody-modules
annotate mod_statistics_statsd/mod_statistics_statsd.lua @ 3955:017f60608fc8
mod_smacks: also count outgoing MAM messages
mod_smacks doesn't count outgoing MAM messages, which causes warnings in Prosody such as:
> The client says it handled 41 new stanzas, but we only sent 2
It seems mod_smacks is in the wrong here and that it's too strict in trying to determine what is a valid stanza to count.
In RFC6120:
> Definition of XML Stanza: An XML stanza is the basic unit of meaning
> in XMPP. A stanza is a first-level element (at depth=1 of the stream)
> whose element name is "message", "presence", or "iq" and whose
> qualifying namespace is 'jabber:client' or 'jabber:server'.
author | JC Brand <jc@opkode.com> |
---|---|
date | Thu, 26 Mar 2020 11:57:02 +0100 |
parents | 98a186874806 |
children |
rev | line source |
---|---|
1622
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local statsmanager = require "core.statsmanager"; |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local udp = require "socket".udp(); |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local server = module:get_option_string("statsd_server_ip", "127.0.0.1"); |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local server_port = module:get_option_number("statsd_server_port", 8124); |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local max_datagram_size = module:get_option_number("statds_packet_size", 512); |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 function push_stats(stats, meta) |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local metric_strings, remaining_bytes = {}, max_datagram_size; |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 for name, value in pairs(stats) do |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local value_meta = meta[name]; |
1656
98a186874806
mod_statistics_statsd: Use module:log()
Kim Alvefur <zash@zash.se>
parents:
1622
diff
changeset
|
12 module:log("warn", "%s %s", name, tostring(value_meta)); |
1622
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 --if not value_meta then |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 -- Simple value (gauge) |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local metric_string = ("%s|%d|g"):format(name, value); |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 if #metric_string > remaining_bytes then |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 udp:sendto(table.concat(metric_strings, "\n"), server, server_port); |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 metric_strings, remaining_bytes = {}, max_datagram_size; |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 end |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 table.insert(metric_strings, metric_string); |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 remaining_bytes = remaining_bytes - (#metric_string + 1); -- +1 for newline |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 --end |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 end |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 if #metric_strings > 0 then |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 udp:sendto(table.concat(metric_strings, "\n"), server, server_port); |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 end |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 end |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 module:hook_global("stats-updated", function (event) |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 push_stats(event.changed_stats, event.stats_extra); |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 end); |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 function module.load() |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 local all, changed, extra = statsmanager.get_stats(); |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 push_stats(all, extra); |
b59812aaabad
mod_statistics_statsd: Module for pushing from util.statistics (0.10) to statsd
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 end |