Software /
code /
prosody
Comparison
plugins/mod_csi_simple.lua @ 10830:8889d5037aca
mod_csi_simple: Collect stats on flush reasons
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 09 May 2020 17:47:03 +0200 |
parent | 10829:67a09706e56e |
child | 10831:7dd7cdb43181 |
comparison
equal
deleted
inserted
replaced
10829:67a09706e56e | 10830:8889d5037aca |
---|---|
100 end | 100 end |
101 return stanza; | 101 return stanza; |
102 end | 102 end |
103 | 103 |
104 local measure_buffer_hold = module:measure("buffer_hold", "times"); | 104 local measure_buffer_hold = module:measure("buffer_hold", "times"); |
105 | |
106 local flush_reasons = setmetatable({}, { | |
107 __index = function (t, reason) | |
108 local m = module:measure("flush_reason."..reason:gsub("%W", "_"), "rate"); | |
109 t[reason] = m; | |
110 return m; | |
111 end; | |
112 }); | |
113 | |
105 | 114 |
106 local function manage_buffer(stanza, session) | 115 local function manage_buffer(stanza, session) |
107 local ctr = session.csi_counter or 0; | 116 local ctr = session.csi_counter or 0; |
108 local flush, why = should_flush(stanza, session, ctr); | 117 local flush, why = should_flush(stanza, session, ctr); |
109 if flush then | 118 if flush then |
110 if session.csi_measure_buffer_hold then | 119 if session.csi_measure_buffer_hold then |
111 session.csi_measure_buffer_hold(); | 120 session.csi_measure_buffer_hold(); |
112 session.csi_measure_buffer_hold = nil; | 121 session.csi_measure_buffer_hold = nil; |
113 end | 122 end |
123 flush_reasons[why or "important"](); | |
114 session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter); | 124 session.log("debug", "Flushing buffer (%s; queue size is %d)", why or "important", session.csi_counter); |
115 session.conn:resume_writes(); | 125 session.conn:resume_writes(); |
116 else | 126 else |
117 session.log("debug", "Holding buffer (%s; queue size is %d)", why or "unimportant", session.csi_counter); | 127 session.log("debug", "Holding buffer (%s; queue size is %d)", why or "unimportant", session.csi_counter); |
118 stanza = with_timestamp(stanza, jid.join(session.username, session.host)) | 128 stanza = with_timestamp(stanza, jid.join(session.username, session.host)) |
121 return stanza; | 131 return stanza; |
122 end | 132 end |
123 | 133 |
124 local function flush_buffer(data, session) | 134 local function flush_buffer(data, session) |
125 session.log("debug", "Flushing buffer (%s; queue size is %d)", "client activity", session.csi_counter); | 135 session.log("debug", "Flushing buffer (%s; queue size is %d)", "client activity", session.csi_counter); |
136 flush_reasons["client activity"](); | |
126 if session.csi_measure_buffer_hold then | 137 if session.csi_measure_buffer_hold then |
127 session.csi_measure_buffer_hold(); | 138 session.csi_measure_buffer_hold(); |
128 session.csi_measure_buffer_hold = nil; | 139 session.csi_measure_buffer_hold = nil; |
129 end | 140 end |
130 session.conn:resume_writes(); | 141 session.conn:resume_writes(); |