Comparison

plugins/mod_s2s/mod_s2s.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 6608:b6e558febb7a
child 6633:832987170da8
child 6658:65563530375b
comparison
equal deleted inserted replaced
6629:42aeb882b3e1 6630:6735e2d735d6
34 local opt_keepalives = module:get_option_boolean("s2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); 34 local opt_keepalives = module:get_option_boolean("s2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true));
35 local secure_auth = module:get_option_boolean("s2s_secure_auth", false); -- One day... 35 local secure_auth = module:get_option_boolean("s2s_secure_auth", false); -- One day...
36 local secure_domains, insecure_domains = 36 local secure_domains, insecure_domains =
37 module:get_option_set("s2s_secure_domains", {})._items, module:get_option_set("s2s_insecure_domains", {})._items; 37 module:get_option_set("s2s_secure_domains", {})._items, module:get_option_set("s2s_insecure_domains", {})._items;
38 local require_encryption = module:get_option_boolean("s2s_require_encryption", false); 38 local require_encryption = module:get_option_boolean("s2s_require_encryption", false);
39
40 local measure_connections = module:measure("connections", "counter");
39 41
40 local sessions = module:shared("sessions"); 42 local sessions = module:shared("sessions");
41 43
42 local log = module._log; 44 local log = module._log;
43 45
572 session:close("connection-timeout"); 574 session:close("connection-timeout");
573 end); 575 end);
574 end 576 end
575 577
576 function listener.onconnect(conn) 578 function listener.onconnect(conn)
579 measure_connections(1);
577 conn:setoption("keepalive", opt_keepalives); 580 conn:setoption("keepalive", opt_keepalives);
578 local session = sessions[conn]; 581 local session = sessions[conn];
579 if not session then -- New incoming connection 582 if not session then -- New incoming connection
580 session = s2s_new_incoming(conn); 583 session = s2s_new_incoming(conn);
581 sessions[conn] = session; 584 sessions[conn] = session;
603 end 606 end
604 end 607 end
605 end 608 end
606 609
607 function listener.ondisconnect(conn, err) 610 function listener.ondisconnect(conn, err)
611 measure_connections(-1);
608 local session = sessions[conn]; 612 local session = sessions[conn];
609 if session then 613 if session then
610 sessions[conn] = nil; 614 sessions[conn] = nil;
611 if err and session.direction == "outgoing" and session.notopen then 615 if err and session.direction == "outgoing" and session.notopen then
612 (session.log or log)("debug", "s2s connection attempt failed: %s", err); 616 (session.log or log)("debug", "s2s connection attempt failed: %s", err);