http: implement stats for http servers.
bzr revid: p_christ@hol.gr-20100726093335-syhvyodg1ec0467f
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user