http: implement stats for http servers.

bzr revid: p_christ@hol.gr-20100726093335-syhvyodg1ec0467f
This commit is contained in:
P. Christeas
2010-07-26 12:33:35 +03:00
parent 9613c0c864
commit 132ffb246e
2 changed files with 25 additions and 0 deletions
+14
View File
@@ -72,6 +72,8 @@ class ThreadedHTTPServer(ConnThreadingMixIn, SimpleXMLRPCDispatcher, HTTPServer)
SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding)
HTTPServer.__init__(self, addr, requestHandler)
self.numThreads = 0
# [Bug #1222790] If possible, set close-on-exec flag; if a
# method spawns a subprocess, the subprocess shouldn't have
@@ -87,6 +89,12 @@ class ThreadedHTTPServer(ConnThreadingMixIn, SimpleXMLRPCDispatcher, HTTPServer)
logging.getLogger("init").exception("Server error in request from %s:" % (client_address,))
def _mark_start(self, thread):
self.numThreads += 1
def _mark_end(self, thread):
self.numThreads -= 1
class HttpLogHandler:
""" helper class for uniform log handling
Please define self._logger at each class that is derived from this
@@ -158,6 +166,12 @@ class BaseHttpDaemon(threading.Thread, netsvc.Server):
raise
return True
def stats(self):
res = "%sd: " % self._RealProto + ((self.running and "running") or "stopped")
if self.server:
res += ", %d threads" % (self.server.numThreads,)
return res
def append_svc(self, service):
if not isinstance(service, HTTPDir):
raise Exception("Wrong class for http service")
+11
View File
@@ -405,6 +405,14 @@ class ConnThreadingMixIn:
if self.daemon_threads:
t.setDaemon (1)
t.start()
def _mark_start(self, thread):
""" Mark the start of a request thread """
pass
def _mark_end(self, thread):
""" Mark the end of a request thread """
pass
def _handle_request2(self):
"""Handle one request, without blocking.
@@ -414,8 +422,10 @@ class ConnThreadingMixIn:
no risk of blocking in get_request().
"""
try:
self._mark_start(threading.currentThread())
request, client_address = self.get_request()
except socket.error:
self._mark_end(threading.currentThread())
return
if self.verify_request(request, client_address):
try:
@@ -423,5 +433,6 @@ class ConnThreadingMixIn:
except Exception:
self.handle_error(request, client_address)
self.close_request(request)
self._mark_end(threading.currentThread())
#eof