Mercurial > prosody-modules
annotate mod_statistics/stats.lib.lua @ 1072:4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 15 Jun 2013 19:08:34 +0100 |
parents | |
children | 164ed759b1d2 |
rev | line source |
---|---|
1072
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local it = require "util.iterators"; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local log = require "util.logger".init("stats"); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local last_cpu_wall, last_cpu_clock; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local get_time = require "socket".gettime; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local active_sessions, active_jids = {}, {}; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local stats = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 total_users = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 get = function () return it.count(it.keys(bare_sessions)); end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 total_c2s = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 get = function () return it.count(it.keys(full_sessions)); end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 total_s2sin = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 get = function () return it.count(it.keys(prosody.incoming_s2s)); end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 total_s2sout = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 get = function () |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 local count = 0; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 for host, host_session in pairs(hosts) do |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 count = count + it.count(it.keys(host_session.s2sout)); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 return count; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 total_component = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 get = function () |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 local count = 0; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 for host, host_session in pairs(hosts) do |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 if host_session.type == "component" then |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 local c = host_session.modules.component; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 if c and c.connected then -- 0.9 only |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 count = count + 1; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 return count; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 up_since = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 get = function () return prosody.start_time; end; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 tostring = function (up_since) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 return tostring(os.time()-up_since).."s"; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 end; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 memory_used = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 get = function () return collectgarbage("count")/1024; end; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 tostring = "%0.2fMB"; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 memory_process = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 get = function () return pposix.meminfo().allocated/1048576; end; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 tostring = "%0.2fMB"; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 time = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 tostring = function () return os.date("%T"); end; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 cpu = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 get = function () |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 local new_wall, new_clock = get_time(), os.clock(); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 local pc = 0; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 if last_cpu_wall then |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 pc = 100/((new_wall-last_cpu_wall)/(new_clock-last_cpu_clock)); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 last_cpu_wall, last_cpu_clock = new_wall, new_clock; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 return math.ceil(pc); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 end; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 tostring = "%s%%"; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 local add_statistics_filter; -- forward decl |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 if prosody and prosody.full_sessions then -- start_time ensures we aren't in prosodyctl |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 setmetatable(active_sessions, { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 __index = function ( t, k ) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 local v = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 bytes_in = 0, bytes_out = 0; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 stanzas_in = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 message = 0, presence = 0, iq = 0; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 stanzas_out = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 message = 0, presence = 0, iq = 0; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 } |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 rawset(t, k, v); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 return v; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 }); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 local filters = require "util.filters"; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 local function handle_stanza_in(stanza, session) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 local s = active_sessions[session].stanzas_in; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 local n = s[stanza.name]; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 if n then |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 s[stanza.name] = n + 1; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 return stanza; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 local function handle_stanza_out(stanza, session) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 local s = active_sessions[session].stanzas_out; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 local n = s[stanza.name]; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 if n then |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 s[stanza.name] = n + 1; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 return stanza; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 local function handle_bytes_in(bytes, session) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 local s = active_sessions[session]; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 s.bytes_in = s.bytes_in + #bytes; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 return bytes; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 local function handle_bytes_out(bytes, session) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 local s = active_sessions[session]; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 s.bytes_out = s.bytes_out + #bytes; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 return bytes; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 function add_statistics_filter(session) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 filters.add_filter(session, "stanzas/in", handle_stanza_in); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 filters.add_filter(session, "stanzas/out", handle_stanza_out); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 filters.add_filter(session, "bytes/in", handle_bytes_in); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 filters.add_filter(session, "bytes/out", handle_bytes_out); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 return { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 stats = stats; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 active_sessions = active_sessions; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 filter_hook = add_statistics_filter; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 }; |