Software /
code /
prosody
Comparison
plugins/mod_csi_simple.lua @ 11573:cb5748f94840
mod_csi_simple: convert to use new metric interface for flush reasons
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Thu, 20 May 2021 14:00:54 +0200 |
parent | 11425:fc7706fe115d |
child | 11834:f54d9abc4e14 |
comparison
equal
deleted
inserted
replaced
11572:e06dba5e99b9 | 11573:cb5748f94840 |
---|---|
105 return stanza; | 105 return stanza; |
106 end | 106 end |
107 | 107 |
108 local measure_buffer_hold = module:measure("buffer_hold", "times"); | 108 local measure_buffer_hold = module:measure("buffer_hold", "times"); |
109 | 109 |
110 local flush_reasons = setmetatable({}, { | 110 local flush_reasons = module:metric( |
111 __index = function (t, reason) | 111 "counter", "flushes", "", |
112 local m = module:measure("flush_reason."..reason:gsub("%W", "_"), "rate"); | 112 "CSI queue flushes", |
113 t[reason] = m; | 113 { "reason" } |
114 return m; | 114 ); |
115 end; | |
116 }); | |
117 | |
118 | 115 |
119 local function manage_buffer(stanza, session) | 116 local function manage_buffer(stanza, session) |
120 local ctr = session.csi_counter or 0; | 117 local ctr = session.csi_counter or 0; |
121 local flush, why = should_flush(stanza, session, ctr); | 118 local flush, why = should_flush(stanza, session, ctr); |
122 if flush then | 119 if flush then |
123 if session.csi_measure_buffer_hold then | 120 if session.csi_measure_buffer_hold then |
124 session.csi_measure_buffer_hold(); | 121 session.csi_measure_buffer_hold(); |
125 session.csi_measure_buffer_hold = nil; | 122 session.csi_measure_buffer_hold = nil; |
126 end | 123 end |
127 flush_reasons[why or "important"](); | 124 flush_reasons:with_labels(why or "important"):add(1); |
128 session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter); | 125 session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter); |
129 session.conn:resume_writes(); | 126 session.conn:resume_writes(); |
130 session.state = "flushing"; | 127 session.state = "flushing"; |
131 module:fire_event("csi-flushing", { session = session }); | 128 module:fire_event("csi-flushing", { session = session }); |
132 else | 129 else |
137 return stanza; | 134 return stanza; |
138 end | 135 end |
139 | 136 |
140 local function flush_buffer(data, session) | 137 local function flush_buffer(data, session) |
141 session.log("debug", "Flushing buffer (%s; queue size is %d)", "client activity", session.csi_counter); | 138 session.log("debug", "Flushing buffer (%s; queue size is %d)", "client activity", session.csi_counter); |
142 flush_reasons["client activity"](); | 139 flush_reasons:with_labels("client activity"):add(1); |
143 if session.csi_measure_buffer_hold then | 140 if session.csi_measure_buffer_hold then |
144 session.csi_measure_buffer_hold(); | 141 session.csi_measure_buffer_hold(); |
145 session.csi_measure_buffer_hold = nil; | 142 session.csi_measure_buffer_hold = nil; |
146 end | 143 end |
147 session.conn:resume_writes(); | 144 session.conn:resume_writes(); |