annotate mod_measure_stanza_counts/mod_measure_stanza_counts.lua @ 4203:c4002aae4ad3

mod_s2s_keepalive: Use timestamp as iq @id RFC 6120 implies that the id attribute must be unique within a stream. This should fix problems with remote servers that enforce uniqueness and don't answer duplicated ids. If it doesn't do that, then at least you can get a guesstimate at round-trip time from the difference between the result iq stanza and the timestamp it was logged without having to go look for when it was sent, or needing to keep state.
author Kim Alvefur <zash@zash.se>
date Wed, 14 Oct 2020 18:02:10 +0200
parents 512405077709
children 33b1b6ff23d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2787
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 module:set_global()
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local filters = require"util.filters";
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local stanza_kinds = { message = true, presence = true, iq = true };
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local function rate(measures, dir)
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 return function (stanza, session)
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 measures[dir]();
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 measures[dir .. "_" .. session.type]();
2788
512405077709 mod_measure_stanza_counts: Fix a crash in mod_bosh.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2787
diff changeset
11 if stanza.attr and not stanza.attr.xmlns and stanza_kinds[stanza.name] then
2787
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 measures[dir .. "_" .. session.type .. "_" .. stanza.name]();
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 end
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 return stanza;
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 end
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 end
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 local measures = setmetatable({}, {
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 __index = function (t, name)
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 local m = module:measure(name, "rate");
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 t[name] = m;
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 return m;
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 end
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 });
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 local function measure_stanza_counts(session)
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 filters.add_filter(session, "stanzas/in", rate(measures, "incoming"));
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 filters.add_filter(session, "stanzas/out", rate(measures, "outgoing"));
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30
750572f6f59d mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 filters.add_filter_hook(measure_stanza_counts);