Mercurial > prosody-modules
annotate mod_statistics/prosodytop.lua @ 1257:a02fbed74487
mod_component_roundrobin: Increase priority of stanza hooks above mod_component (thanks Julien)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 28 Dec 2013 14:12:02 +0100 |
parents | 56fc7a86eb20 |
children | 7dbde05b48a9 |
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 curses = require "curses"; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local server = require "net.server_select"; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local timer = require "util.timer"; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 assert(curses.timeout, "Incorrect version of curses library. Try 'sudo luarocks install luaposix'"); |
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 top = require "top"; |
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 function main() |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local stdscr = curses.stdscr() -- it's a userdatum |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 --stdscr:clear(); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local view = top.new({ |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 stdscr = stdscr; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 prosody = { up_since = os.time() }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 conn_list = {}; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 }); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 timer.add_task(0.01, function () |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 local ch = stdscr:getch(); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 if ch then |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 if stdscr:getch() == 410 then |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 view:resized(); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 else |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 curses.ungetch(ch); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 end |
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 return 0.2; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 end); |
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 timer.add_task(0, function () |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 view:draw(); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 return 1; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 |
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 posix.signal(28, function () |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 table.insert(view.conn_list, { jid = "WINCH" }); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 --view:draw(); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 end); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 ]] |
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 -- Fake socket object around stdin |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 local stdin = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 getfd = function () return 0; end; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 dirty = function (self) return false; end; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 settimeout = function () end; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 send = function (_, d) return #d, 0; end; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 close = function () end; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 receive = function (_, patt) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 local ch = stdscr:getch(); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 if ch >= 0 and ch <=255 then |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 return string.char(ch); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 elseif ch == 410 then |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 view:resized(); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 else |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 table.insert(view.conn_list, { jid = tostring(ch) }); --FIXME |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 return ""; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 }; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 local function on_incoming(stdin, text) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 -- TODO: Handle keypresses |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 if text:lower() == "q" then os.exit(); end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 stdin = server.wrapclient(stdin, "stdin", 0, { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 onincoming = on_incoming, ondisconnect = function () end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 }, "*a"); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 local function handle_line(line) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 local e = { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 STAT = function (name) return function (value) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 view:update_stat(name, value); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 end end; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 SESS = function (id) return function (jid) return function (stats) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 view:update_session(id, jid, stats); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 end end 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 local chunk = assert(loadstring(line)); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 setfenv(chunk, e); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 chunk(); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 local stats_listener = {}; |
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 function stats_listener.onconnect(conn) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 --stdscr:mvaddstr(6, 0, "CONNECTED"); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 local partial; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 function stats_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 --print("DATA", data) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 if partial then |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 partial, data = nil, partial..data; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 if not data:match("\n") then |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 partial = data; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 return; |
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 lastpos = 1; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 for line, pos in data:gmatch("([^\n]+)\n()") do |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 lastpos = pos; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 handle_line(line); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 if lastpos == #data then |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 partial = nil; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 else |
1085
56fc7a86eb20
mod_statistics: prosodytop: Fix off-by-one error (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
1072
diff
changeset
|
107 partial = data:sub(lastpos); |
1072
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 function stats_listener.ondisconnect(conn, err) |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 stdscr:mvaddstr(6, 0, "DISCONNECTED: "..(err or "unknown")); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 local conn = require "socket".tcp(); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 assert(conn:connect("localhost", 5782)); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 handler = server.wrapclient(conn, "localhost", 5279, stats_listener, "*a"); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 return { |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 run = function () |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 --os.setlocale("UTF-8", "all") |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 curses.initscr() |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 curses.cbreak() |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 curses.echo(false) -- not noecho ! |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 curses.nl(false) -- not nonl ! |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 curses.timeout(0); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 local ok, err = pcall(main); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 --while true do stdscr:getch() end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 --stdscr:endwin() |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 if ok then |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 ok, err = xpcall(server.loop, debug.traceback); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 curses.endwin(); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 --stdscr:refresh(); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 if not ok then |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 print(err); |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 end |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 print"DONE" |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 end; |
4dbdb1b465e8
mod_statistics: Initial version, and a rough 'prosodyctl mod_statistics top'
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 }; |