Mercurial > prosody-modules
annotate mod_measure_stanza_counts/mod_measure_stanza_counts.lua @ 4579:b305814bd930
mod_muc_dicebot: A thing to roll dice
Do you see what happens, Jitsi? Do you see what happens when you
make it hard for me to use a proper bot? This is what happens,
Jitsi. This is what happens when you meet a stranger in the alps!
Ahem. In all seriousness, this is more of a quick hack than
anything else. It will look for `.r` in MUC messages and if it
finds it, it'll interpret it as an instruction to roll a few
dice. Injects the results in the body of the message. Eats the
message alive if it is malformed.
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Sat, 29 May 2021 15:17:05 +0200 |
parents | 33b1b6ff23d8 |
children |
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 |
4559
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
5 local stanzas_in = module:metric( |
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
6 "counter", "received", "", |
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
7 "Stanzas received by Prosody", |
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
8 { "session_type", "stanza_kind" } |
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
9 ) |
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
10 local stanzas_out = module:metric( |
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
11 "counter", "sent", "", |
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
12 "Stanzas sent by prosody", |
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
13 { "session_type", "stanza_kind" } |
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
14 ) |
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
15 |
2787
750572f6f59d
mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 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
|
17 |
4559
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
18 local function rate(metric_family) |
2787
750572f6f59d
mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 return function (stanza, session) |
2788
512405077709
mod_measure_stanza_counts: Fix a crash in mod_bosh.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
2787
diff
changeset
|
20 if stanza.attr and not stanza.attr.xmlns and stanza_kinds[stanza.name] then |
4559
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
21 metric_family:with_labels(session.type, stanza.name):add(1); |
2787
750572f6f59d
mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 end |
750572f6f59d
mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 return stanza; |
750572f6f59d
mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 end |
750572f6f59d
mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 end |
750572f6f59d
mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 |
750572f6f59d
mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 local function measure_stanza_counts(session) |
4559
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
28 filters.add_filter(session, "stanzas/in", rate(stanzas_in)); |
33b1b6ff23d8
mod_measure_stanza_counts: port to new metrics API
Jonas Schäfer <jonas@wielicki.name>
parents:
2788
diff
changeset
|
29 filters.add_filter(session, "stanzas/out", rate(stanzas_out)); |
2787
750572f6f59d
mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 end |
750572f6f59d
mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 |
750572f6f59d
mod_measure_stanza_counts: Counts stanzas and reports using 0.10+ statistics API
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 filters.add_filter_hook(measure_stanza_counts); |