Comparison

plugins/mod_c2s.lua @ 6630:6735e2d735d6

mod_c2s, mod_s2s: Collect statistics on number of connections
author Kim Alvefur <zash@zash.se>
date Sun, 26 Apr 2015 00:06:11 +0200
parent 6382:57d23c26039b
child 6846:7eb166fa1f26
comparison
equal deleted inserted replaced
6629:42aeb882b3e1 6630:6735e2d735d6
25 local log = module._log; 25 local log = module._log;
26 26
27 local c2s_timeout = module:get_option_number("c2s_timeout"); 27 local c2s_timeout = module:get_option_number("c2s_timeout");
28 local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5); 28 local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5);
29 local opt_keepalives = module:get_option_boolean("c2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); 29 local opt_keepalives = module:get_option_boolean("c2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true));
30
31 local measure_connections = module:measure("connections", "counter");
30 32
31 local sessions = module:shared("sessions"); 33 local sessions = module:shared("sessions");
32 local core_process_stanza = prosody.core_process_stanza; 34 local core_process_stanza = prosody.core_process_stanza;
33 local hosts = prosody.hosts; 35 local hosts = prosody.hosts;
34 36
196 (self.data.log or log)("error", "Traceback[c2s]: %s", err); 198 (self.data.log or log)("error", "Traceback[c2s]: %s", err);
197 end 199 end
198 200
199 --- Port listener 201 --- Port listener
200 function listener.onconnect(conn) 202 function listener.onconnect(conn)
203 measure_connections(1);
201 local session = sm_new_session(conn); 204 local session = sm_new_session(conn);
202 sessions[conn] = session; 205 sessions[conn] = session;
203 206
204 session.log("info", "Client connected"); 207 session.log("info", "Client connected");
205 208
268 session.data(data); 271 session.data(data);
269 end 272 end
270 end 273 end
271 274
272 function listener.ondisconnect(conn, err) 275 function listener.ondisconnect(conn, err)
276 measure_connections(-1);
273 local session = sessions[conn]; 277 local session = sessions[conn];
274 if session then 278 if session then
275 (session.log or log)("info", "Client disconnected: %s", err or "connection closed"); 279 (session.log or log)("info", "Client disconnected: %s", err or "connection closed");
276 sm_destroy_session(session, err); 280 sm_destroy_session(session, err);
277 sessions[conn] = nil; 281 sessions[conn] = nil;