Merge "Add a queue monitor for zuul."
diff --git a/setup.cfg b/setup.cfg
index e663278..6f6632c 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -31,6 +31,7 @@
     turbo-hipster = turbo_hipster.worker_server:main
     turbo-hipster-analyse = turbo_hipster.analyse_historical:main
     turbo-hipster-report = turbo_hipster.report_historical:main
+    turbo-hipster-queue-logger = turbo_hipster.queue_logger:main
 
 [build_sphinx]
 source-dir = doc/source
diff --git a/turbo_hipster/queue_logger.py b/turbo_hipster/queue_logger.py
new file mode 100644
index 0000000..3e35bcd
--- /dev/null
+++ b/turbo_hipster/queue_logger.py
@@ -0,0 +1,56 @@
+#!/usr/bin/python2
+#
+# Copyright 2013 Rackspace Australia
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+
+import os
+import socket
+import sys
+
+
+def main():
+    client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    client_socket.connect(('zuul.rcbops.com', 4730))
+    client_socket.send('status\n')
+
+    data = ''
+
+    d = client_socket.recv(1024)
+    while d:
+        data += d
+        if d.split('\n')[-2] == '.':
+            break
+        d = client_socket.recv(1024)
+
+    queued_count = 0
+    queued_detail = {}
+    for line in data.split('\n')[:-2]:
+        func, total, running, available_workers = line.split('\t')
+        queued = int(total) - int(running)
+        if queued > 0:
+            queued_detail[func] = ('%d (%s workers)'
+                                   % (queued, available_workers))
+        queued_count += queued
+
+    print 'There are %d turbo-hipster jobs queued' % queued_count
+    for job in queued_detail:
+        print '    %s: %s' % (job, queued_detail[job])
+
+    client_socket.close()
+
+if __name__ == '__main__':
+    sys.path.insert(0, os.path.abspath(
+                    os.path.join(os.path.dirname(__file__), '../')))
+    main()