annotate mod_statistics/mod_statistics.lua @ 3480:5911030a1a66

mod_invite: Fire event that signals that an user has registered (thanks jeybe) This allows other modules to see this and do things, eg mod_watchregistrations
author Kim Alvefur <zash@zash.se>
date Thu, 07 Mar 2019 22:36:30 +0100
parents 66bda434d476
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 module:set_global();
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local stats = module:require("mod_statistics/stats");
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 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
5 local serialize = require "util.serialization".serialize;
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 cached_values = {};
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 sessions = {};
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local function push_stat(conn, name, value)
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local value_str = serialize(value);
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 return conn:write((("STAT %q (%s)\n"):format(name, value_str):gsub("\\\n", "\\n")));
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 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 local function push_stat_to_all(name, value)
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 for conn in pairs(sessions) do
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 push_stat(conn, name, value);
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 local session_stats_tpl = ([[{
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 message_in = %d, message_out = %d;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 presence_in = %d, presence_out = %d;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 iq_in = %d, iq_out = %d;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 bytes_in = %d, bytes_out = %d;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 }]]):gsub("%s", "");
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 local jid_fields = {
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 c2s = "full_jid";
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 s2sin = "from_host";
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 s2sout = "to_host";
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 component = "host";
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 };
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 local function push_session_to_all(session, stats)
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 local id = tostring(session):match("[a-f0-9]+$"); -- FIXME: Better id? :/
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 local stanzas_in, stanzas_out = stats.stanzas_in, stats.stanzas_out;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 local s = (session_stats_tpl):format(
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 stanzas_in.message, stanzas_out.message,
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 stanzas_in.presence, stanzas_out.presence,
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 stanzas_in.iq, stanzas_out.iq,
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 stats.bytes_in, stats.bytes_out);
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 local jid = session[jid_fields[session.type]] or "";
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 for conn in pairs(sessions) do
1584
4713f9d453ec mod_statistics: Remove 'return' so SESS lines are pushed to all sessions (thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents: 1343
diff changeset
47 conn:write(("SESS %q %q %s\n"):format(id, jid, s));
1072
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 local available_stats = stats.stats;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 local active_sessions = stats.active_sessions;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 -- Handle statistics provided by other modules
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 local function item_handlers(host)
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 host = host and (host.."/") or "";
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 1074
diff changeset
57
1072
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 return function (event) -- Added
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 local stats = event.item.statistics;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 local group = host..(stats.name and (stats.name.."::") or "");
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 for name, stat in pairs(stats) do
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 available_stats[group..name] = stat;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 end, function (event) -- Removed
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 local stats = event.item.statistics;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 local group = host..(stats.name and (stats.name.."::") or "");
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 for name, stat in pairs(stats) do
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 available_stats[group..name] = nil;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 end;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 end
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 module:handle_items("statistics-provider", item_handlers());
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 function module.add_host(module)
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 module:handle_items("statistics-provider", item_handlers(module.host));
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 -- Network listener
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 local listener = {};
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 function listener.onconnect(conn)
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 sessions[conn] = {};
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 push_stat(conn, "version", prosody.version);
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 for name, value in pairs(cached_values) do
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 push_stat(conn, name, value);
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 conn:write("\n"); -- Signal end of first batch (for non-streaming clients)
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 function listener.onincoming(conn, data)
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 function listener.ondisconnect(conn)
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 sessions[conn] = nil;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96
2301
d7c014f91189 mod_statistics: Add a read timeout handler that keeps the connection alive (fixes #742)
Kim Alvefur <zash@zash.se>
parents: 1584
diff changeset
97 function listener.onreadtimeout()
d7c014f91189 mod_statistics: Add a read timeout handler that keeps the connection alive (fixes #742)
Kim Alvefur <zash@zash.se>
parents: 1584
diff changeset
98 return true;
d7c014f91189 mod_statistics: Add a read timeout handler that keeps the connection alive (fixes #742)
Kim Alvefur <zash@zash.se>
parents: 1584
diff changeset
99 end
d7c014f91189 mod_statistics: Add a read timeout handler that keeps the connection alive (fixes #742)
Kim Alvefur <zash@zash.se>
parents: 1584
diff changeset
100
1072
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 function module.load()
1074
cccd9f6a628d mod_statistics: Better detection of when running under prosody vs prosodyctl
Kim Alvefur <zash@zash.se>
parents: 1072
diff changeset
102 if not(prosody and prosody.arg) then
cccd9f6a628d mod_statistics: Better detection of when running under prosody vs prosodyctl
Kim Alvefur <zash@zash.se>
parents: 1072
diff changeset
103 return;
cccd9f6a628d mod_statistics: Better detection of when running under prosody vs prosodyctl
Kim Alvefur <zash@zash.se>
parents: 1072
diff changeset
104 end
1072
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 filters.add_filter_hook(stats.filter_hook);
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 module:add_timer(1, function ()
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 for stat_name, stat in pairs(available_stats) do
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 if stat.get then
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 local cached = cached_values[stat_name];
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 local new_value = stat.get();
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 if new_value ~= cached then
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 push_stat_to_all(stat_name, new_value);
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 cached_values[stat_name] = new_value;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 end
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 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 for session, session_stats in pairs(active_sessions) do
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 active_sessions[session] = nil;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 push_session_to_all(session, session_stats);
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 return 1;
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 end);
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 1074
diff changeset
124
1072
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 function module.unload()
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 filters.remove_filter_hook(stats.filter_hook);
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 function module.command( args )
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 local command = args[1];
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 if command == "top" then
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 local dir = module:get_directory();
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 package.path = dir.."/?.lua;"..dir.."/?.lib.lua;"..package.path;
3414
66bda434d476 mod_statistics: Update 'top' to (hopefully) work with Prosody 0.11/Lua 5.2
Matthew Wild <mwild1@gmail.com>
parents: 2301
diff changeset
134 local prosodytop = module:require "prosodytop";
1072
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 prosodytop.run();
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 end
4dbdb1b465e8 mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 end
1074
cccd9f6a628d mod_statistics: Better detection of when running under prosody vs prosodyctl
Kim Alvefur <zash@zash.se>
parents: 1072
diff changeset
138
cccd9f6a628d mod_statistics: Better detection of when running under prosody vs prosodyctl
Kim Alvefur <zash@zash.se>
parents: 1072
diff changeset
139 if prosody and prosody.arg then
cccd9f6a628d mod_statistics: Better detection of when running under prosody vs prosodyctl
Kim Alvefur <zash@zash.se>
parents: 1072
diff changeset
140 module:provides("net", {
cccd9f6a628d mod_statistics: Better detection of when running under prosody vs prosodyctl
Kim Alvefur <zash@zash.se>
parents: 1072
diff changeset
141 default_port = 5782;
cccd9f6a628d mod_statistics: Better detection of when running under prosody vs prosodyctl
Kim Alvefur <zash@zash.se>
parents: 1072
diff changeset
142 listener = listener;
cccd9f6a628d mod_statistics: Better detection of when running under prosody vs prosodyctl
Kim Alvefur <zash@zash.se>
parents: 1072
diff changeset
143 private = true;
cccd9f6a628d mod_statistics: Better detection of when running under prosody vs prosodyctl
Kim Alvefur <zash@zash.se>
parents: 1072
diff changeset
144 });
cccd9f6a628d mod_statistics: Better detection of when running under prosody vs prosodyctl
Kim Alvefur <zash@zash.se>
parents: 1072
diff changeset
145 end