# HG changeset patch # User Matthew Wild # Date 1451924637 0 # Node ID 67858d7315180271835e9a324b783e8815a551b2 # Parent 1d28dfcd9c94d56a27eea49cff77c99a6609503f clients.lua: Add /watcher_info endpoint to get a more detailed list of streams diff -r 1d28dfcd9c94 -r 67858d731518 clients.lua --- a/clients.lua Mon Jan 04 14:52:06 2016 +0000 +++ b/clients.lua Mon Jan 04 16:23:57 2016 +0000 @@ -82,6 +82,8 @@ update_have_clients(); + events.fire_event("new-client", { conn = conn, cookie = cookie }); + if last_chunk then conn:write(last_chunk); end @@ -123,6 +125,21 @@ return tostring(total); end +function handle_watcher_info(event) + local watchers = {}; + for client in pairs(clients) do + local bytes_rx, bytes_tx, age_sec = client:socket():getstats(); + table.insert(watchers, json.encode{ + location = client.location or "(Unknown location)"; + active = not not active_clients[client]; + age = math.floor(age_sec); + sent = math.floor(bytes_tx/1024); + }); + end + mark_active(event.request); + return "[\n "..table.concat(watchers, ",\n ").."\n]"; +end + -- Called when a HTTP stream client closes local function client_closed(request) local stream = request._watching; @@ -183,6 +200,7 @@ http_server.add_handler("GET localhost/*", handle_request); http_server.add_handler("GET localhost/active", handle_active); http_server.add_handler("GET localhost/watchers", handle_watchers); +http_server.add_handler("GET localhost/watcher_info", handle_watcher_info); http_server.add_handler("GET localhost/notifications", handle_notifications); http_server.add_handler("GET localhost/push/*", handle_push); http_server.listen_on(8006);