Mercurial > prosody-hg
comparison plugins/mod_csi_simple.lua @ 13991:0ff11f2e87cd
mod_csi_simple: Collect stats on why stanzas are held
To mirror flush reasons.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 07 Nov 2025 00:29:44 +0100 |
| parents | 598359d9f580 |
| children |
comparison
equal
deleted
inserted
replaced
| 13990:cf21d285385b | 13991:0ff11f2e87cd |
|---|---|
| 120 "counter", "flushes", "", | 120 "counter", "flushes", "", |
| 121 "CSI queue flushes", | 121 "CSI queue flushes", |
| 122 { "reason" } | 122 { "reason" } |
| 123 ); | 123 ); |
| 124 | 124 |
| 125 local hold_reasons = module:metric( | |
| 126 "counter", "hold", "", | |
| 127 "CSI queue held", | |
| 128 { "reason" } | |
| 129 ); | |
| 130 | |
| 125 local flush_sizes = module:metric("histogram", "flush_stanza_count", "", "Number of stanzas flushed at once", {}, | 131 local flush_sizes = module:metric("histogram", "flush_stanza_count", "", "Number of stanzas flushed at once", {}, |
| 126 { buckets = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 256 } }):with_labels(); | 132 { buckets = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 256 } }):with_labels(); |
| 127 | 133 |
| 128 local function manage_buffer(stanza, session) | 134 local function manage_buffer(stanza, session) |
| 129 local ctr = session.csi_counter or 0; | 135 local ctr = session.csi_counter or 0; |
| 142 session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter); | 148 session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter); |
| 143 session.state = "flushing"; | 149 session.state = "flushing"; |
| 144 module:fire_event("csi-flushing", { session = session }); | 150 module:fire_event("csi-flushing", { session = session }); |
| 145 session.conn:resume_writes(); | 151 session.conn:resume_writes(); |
| 146 else | 152 else |
| 153 hold_reasons:with_labels(why or "unimportant"):add(1); | |
| 147 session.log("debug", "Holding buffer (%s; queue size is %d)", why or "unimportant", session.csi_counter); | 154 session.log("debug", "Holding buffer (%s; queue size is %d)", why or "unimportant", session.csi_counter); |
| 148 stanza = with_timestamp(stanza, jid.join(session.username, session.host)) | 155 stanza = with_timestamp(stanza, jid.join(session.username, session.host)) |
| 149 end | 156 end |
| 150 session.csi_counter = ctr + 1; | 157 session.csi_counter = ctr + 1; |
| 151 return stanza; | 158 return stanza; |
