diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2009-05-14 02:59:27 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2009-05-14 02:59:27 +0000 |
commit | 65f9f83a1fe481c60d24ef187c424e991208008a (patch) | |
tree | 89382806a994d2ebb5056f16fb87feaf1ea26d97 /src | |
parent | 88f446708cf429818ed17b2460163e622d3ca91c (diff) | |
download | bcfg2-65f9f83a1fe481c60d24ef187c424e991208008a.tar.gz bcfg2-65f9f83a1fe481c60d24ef187c424e991208008a.tar.bz2 bcfg2-65f9f83a1fe481c60d24ef187c424e991208008a.zip |
Integrate server-side performance statistics infrastructure
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5225 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Component.py | 14 | ||||
-rw-r--r-- | src/lib/SSLServer.py | 1 | ||||
-rw-r--r-- | src/lib/Statistics.py | 33 | ||||
-rw-r--r-- | src/lib/__init__.py | 2 |
4 files changed, 49 insertions, 1 deletions
diff --git a/src/lib/Component.py b/src/lib/Component.py index ee4e5a0c2..6ea788ba5 100644 --- a/src/lib/Component.py +++ b/src/lib/Component.py @@ -15,6 +15,7 @@ import urlparse import xmlrpclib import Bcfg2.Logger +from Bcfg2.Statistics import Statistics from Bcfg2.SSLServer import XMLRPCServer class NoExposedMethod (Exception): @@ -132,6 +133,7 @@ class Component (object): self.statefile = kwargs.get("statefile", None) self.logger = logging.getLogger("%s %s" % (self.implementation, self.name)) self.lock = threading.Lock() + self.instance_statistics = Statistics() def do_tasks (self): """Perform automatic tasks for the component. @@ -145,7 +147,10 @@ class Component (object): if (time.time() - func.automatic_ts) > \ func.automatic_period: if need_to_lock: + t1 = time.time() self.lock.acquire() + t2 = time.time() + self.instance_statistics.add_value('component_lock', t2-t1) try: mt1 = time.time() func() @@ -157,6 +162,7 @@ class Component (object): if need_to_lock: self.lock.release() + self.instance_statistics.add_value(name, mt2-mt1) func.__dict__['automatic_ts'] = time.time() def _resolve_exposed_method (self, method_name): @@ -207,6 +213,9 @@ class Component (object): finally: if need_to_lock: self.lock.release() + self.instance_statistics.add_value('component_lock', + lock_done - lock_start) + self.instance_statistics.add_value(method, method_done - method_start) return result @exposed @@ -239,3 +248,8 @@ class Component (object): """The implementation of the component.""" return self.implementation get_implementation = exposed(get_implementation) + + def get_statistics (self): + """Get current statistics about component execution""" + return self.instance_statistics.display() + get_statistics = exposed(get_statistics) diff --git a/src/lib/SSLServer.py b/src/lib/SSLServer.py index a3840f71f..850fb28d7 100644 --- a/src/lib/SSLServer.py +++ b/src/lib/SSLServer.py @@ -46,6 +46,7 @@ class XMLRPCDispatcher (SimpleXMLRPCServer.SimpleXMLRPCDispatcher): allow_none=self.allow_none, encoding=self.encoding) except: + self.logger.error("Unexpected handler error", exc_info=1) # report exception back to server raw_response = xmlrpclib.dumps( xmlrpclib.Fault(1, "%s:%s" % (sys.exc_type, sys.exc_value)), diff --git a/src/lib/Statistics.py b/src/lib/Statistics.py new file mode 100644 index 000000000..a7ae85c67 --- /dev/null +++ b/src/lib/Statistics.py @@ -0,0 +1,33 @@ + +class Statistic(object): + def __init__(self, name, initial_value): + self.name = name + self.min = float(initial_value) + self.max = float(initial_value) + self.ave = float(initial_value) + self.count = 1 + + def add_value(self, value): + if value < self.min: + self.min = value + if value > self.max: + self.max = value + self.count += 1 + self.ave = (((self.ave * (self.count - 1)) + value) / self.count ) + + def get_value(self): + return (self.name, (self.min, self.max, self.ave)) + +class Statistics(object): + def __init__(self): + self.data = dict() + + def add_value(self, name, value): + if name not in self.data: + self.data[name] = Statistic(name, value) + else: + self.data[name].add_value(value) + + def display(self): + return dict([value.get_value() for value in self.data.values()]) + diff --git a/src/lib/__init__.py b/src/lib/__init__.py index a6300af89..b9056f25f 100644 --- a/src/lib/__init__.py +++ b/src/lib/__init__.py @@ -1,4 +1,4 @@ '''base modules definition''' __revision__ = '$Revision$' -__all__ = ['Server', 'Client', 'Component', 'Logger', 'Options', 'Proxy'] +__all__ = ['Server', 'Client', 'Component', 'Logger', 'Options', 'Proxy', 'Statistics'] |