[LNT] r255968 - Add a health endpoint

Chris Matthews via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 17 18:10:05 PST 2015


Author: cmatthews
Date: Thu Dec 17 20:10:05 2015
New Revision: 255968

URL: http://llvm.org/viewvc/llvm-project?rev=255968&view=rev
Log:
Add a health endpoint

When deployed to the cloud, some clouds monitor app/__health to see if the app needs to be restarted.  Add __heath, and request a restart if we are using too much memory OR our queue length has gotten too long.

Modified:
    lnt/trunk/lnt/server/ui/views.py

Modified: lnt/trunk/lnt/server/ui/views.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/views.py?rev=255968&r1=255967&r2=255968&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/views.py (original)
+++ lnt/trunk/lnt/server/ui/views.py Thu Dec 17 20:10:05 2015
@@ -1180,3 +1180,25 @@ def log():
 @frontend.route('/debug')
 def debug():
     assert current_app.debug == False
+
+
+ at frontend.route('/__health')
+def health():
+    """Our instnace health. If queue is too long or we use too much mem,
+    return 500.  Monitor might reboot us for this."""
+    explode = False
+    msg = "Ok"
+    queue_length = async_ops.check_workers()
+    if queue_length > 10:
+        explode = True
+        msg = "Queue too long."
+    
+    import resource
+    stats = resource.getrusage(resource.RUSAGE_SELF)
+    mem = stats.ru_maxrss
+    if mem > 1024**3:
+        explode = True
+        msg = "Over memory " + str(mem) + ">" + str(1024**3)
+    if explode:
+        return msg, 500
+    return msg, 200




More information about the llvm-commits mailing list