Software /
code /
prosody
Comparison
plugins/mod_c2s.lua @ 7662:946871f6e3c8
mod_c2s, mod_s2s: Switch connection counting to 'amount' type and enumerate once per statistics interval
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 12 Sep 2016 15:01:16 +0200 |
parent | 7540:e69df8093387 |
child | 7666:03aa330562ed |
child | 7862:f5cbbf69cac8 |
comparison
equal
deleted
inserted
replaced
7659:449de852cf38 | 7662:946871f6e3c8 |
---|---|
25 | 25 |
26 local c2s_timeout = module:get_option_number("c2s_timeout"); | 26 local c2s_timeout = module:get_option_number("c2s_timeout"); |
27 local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5); | 27 local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5); |
28 local opt_keepalives = module:get_option_boolean("c2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); | 28 local opt_keepalives = module:get_option_boolean("c2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); |
29 | 29 |
30 local measure_connections = module:measure("connections", "counter"); | 30 local measure_connections = module:measure("connections", "amount"); |
31 | 31 |
32 local sessions = module:shared("sessions"); | 32 local sessions = module:shared("sessions"); |
33 local core_process_stanza = prosody.core_process_stanza; | 33 local core_process_stanza = prosody.core_process_stanza; |
34 local hosts = prosody.hosts; | 34 local hosts = prosody.hosts; |
35 | 35 |
36 local stream_callbacks = { default_ns = "jabber:client" }; | 36 local stream_callbacks = { default_ns = "jabber:client" }; |
37 local listener = {}; | 37 local listener = {}; |
38 | 38 |
39 do | 39 module:hook("stats-update", function () |
40 -- Connection counter resets to 0 on load and reload | 40 -- Connection counter resets to 0 on load and reload |
41 -- Bump it up to current value | 41 -- Bump it up to current value |
42 local count = 0; | 42 local count = 0; |
43 for _ in pairs(sessions) do | 43 for _ in pairs(sessions) do |
44 count = count + 1; | 44 count = count + 1; |
45 end | 45 end |
46 measure_connections(count); | 46 measure_connections(count); |
47 end | 47 end); |
48 | 48 |
49 --- Stream events handlers | 49 --- Stream events handlers |
50 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; | 50 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; |
51 | 51 |
52 function stream_callbacks.streamopened(session, attr) | 52 function stream_callbacks.streamopened(session, attr) |
205 end | 205 end |
206 end, 200); | 206 end, 200); |
207 | 207 |
208 --- Port listener | 208 --- Port listener |
209 function listener.onconnect(conn) | 209 function listener.onconnect(conn) |
210 measure_connections(1); | |
211 local session = sm_new_session(conn); | 210 local session = sm_new_session(conn); |
212 sessions[conn] = session; | 211 sessions[conn] = session; |
213 | 212 |
214 session.log("info", "Client connected"); | 213 session.log("info", "Client connected"); |
215 | 214 |
274 session.data(data); | 273 session.data(data); |
275 end | 274 end |
276 end | 275 end |
277 | 276 |
278 function listener.ondisconnect(conn, err) | 277 function listener.ondisconnect(conn, err) |
279 measure_connections(-1); | |
280 local session = sessions[conn]; | 278 local session = sessions[conn]; |
281 if session then | 279 if session then |
282 (session.log or log)("info", "Client disconnected: %s", err or "connection closed"); | 280 (session.log or log)("info", "Client disconnected: %s", err or "connection closed"); |
283 sm_destroy_session(session, err); | 281 sm_destroy_session(session, err); |
284 session.conn = nil; | 282 session.conn = nil; |