Appease pep8

This commit is contained in:
Paul "LeoNerd" Evans 2015-03-12 16:24:38 +00:00
parent b98b4c135d
commit 128cf2daf7
9 changed files with 46 additions and 27 deletions

View File

@ -57,7 +57,8 @@ class TransactionQueue(object):
# done # done
self.pending_transactions = {} self.pending_transactions = {}
metrics.register_callback("pending_destinations", metrics.register_callback(
"pending_destinations",
lambda: len(self.pending_transactions), lambda: len(self.pending_transactions),
) )
@ -67,10 +68,12 @@ class TransactionQueue(object):
# destination -> list of tuple(edu, deferred) # destination -> list of tuple(edu, deferred)
self.pending_edus_by_dest = edus = {} self.pending_edus_by_dest = edus = {}
metrics.register_callback("pending_pdus", metrics.register_callback(
"pending_pdus",
lambda: sum(map(len, pdus.values())), lambda: sum(map(len, pdus.values())),
) )
metrics.register_callback("pending_edus", metrics.register_callback(
"pending_edus",
lambda: sum(map(len, edus.values())), lambda: sum(map(len, edus.values())),
) )

View File

@ -136,8 +136,9 @@ class PresenceHandler(BaseHandler):
self._user_cachemap = {} self._user_cachemap = {}
self._user_cachemap_latest_serial = 0 self._user_cachemap_latest_serial = 0
metrics.register_callback("userCachemap:size", metrics.register_callback(
lambda: len(self._user_cachemap) "userCachemap:size",
lambda: len(self._user_cachemap),
) )
def _get_or_make_usercache(self, user): def _get_or_make_usercache(self, user):

View File

@ -34,11 +34,13 @@ logger = logging.getLogger(__name__)
metrics = synapse.metrics.get_metrics_for(__name__) metrics = synapse.metrics.get_metrics_for(__name__)
outgoing_requests_counter = metrics.register_counter("requests", outgoing_requests_counter = metrics.register_counter(
"requests",
labels=["method"], labels=["method"],
) )
incoming_responses_counter = metrics.register_counter("responses", incoming_responses_counter = metrics.register_counter(
labels=["method","code"], "responses",
labels=["method", "code"],
) )
@ -64,9 +66,11 @@ class SimpleHttpClient(object):
def _cb(response): def _cb(response):
incoming_responses_counter.inc(method, response.code) incoming_responses_counter.inc(method, response.code)
return response return response
def _eb(failure): def _eb(failure):
incoming_responses_counter.inc(method, "ERR") incoming_responses_counter.inc(method, "ERR")
return failure return failure
d.addCallbacks(_cb, _eb) d.addCallbacks(_cb, _eb)
return d return d

View File

@ -43,11 +43,13 @@ logger = logging.getLogger(__name__)
metrics = synapse.metrics.get_metrics_for(__name__) metrics = synapse.metrics.get_metrics_for(__name__)
outgoing_requests_counter = metrics.register_counter("requests", outgoing_requests_counter = metrics.register_counter(
"requests",
labels=["method"], labels=["method"],
) )
incoming_responses_counter = metrics.register_counter("responses", incoming_responses_counter = metrics.register_counter(
labels=["method","code"], "responses",
labels=["method", "code"],
) )
@ -78,9 +80,11 @@ class MatrixFederationHttpAgent(_AgentBase):
def _cb(response): def _cb(response):
incoming_responses_counter.inc(method, response.code) incoming_responses_counter.inc(method, response.code)
return response return response
def _eb(failure): def _eb(failure):
incoming_responses_counter.inc(method, "ERR") incoming_responses_counter.inc(method, "ERR")
return failure return failure
d.addCallbacks(_cb, _eb) d.addCallbacks(_cb, _eb)
return d return d

View File

@ -37,11 +37,13 @@ logger = logging.getLogger(__name__)
metrics = synapse.metrics.get_metrics_for(__name__) metrics = synapse.metrics.get_metrics_for(__name__)
incoming_requests_counter = metrics.register_counter("requests", incoming_requests_counter = metrics.register_counter(
"requests",
labels=["method", "servlet"], labels=["method", "servlet"],
) )
outgoing_responses_counter = metrics.register_counter("responses", outgoing_responses_counter = metrics.register_counter(
labels=["method","code"], "responses",
labels=["method", "code"],
) )

View File

@ -85,7 +85,7 @@ def render_all():
strs += ["# FAILED to render %s" % name] strs += ["# FAILED to render %s" % name]
logger.exception("Failed to render %s metric", name) logger.exception("Failed to render %s metric", name)
strs.append("") # to generate a final CRLF strs.append("") # to generate a final CRLF
return "\n".join(strs) return "\n".join(strs)
@ -96,6 +96,7 @@ def render_all():
rusage = None rusage = None
PAGE_SIZE = getpagesize() PAGE_SIZE = getpagesize()
def update_resource_metrics(): def update_resource_metrics():
global rusage global rusage
rusage = getrusage(RUSAGE_SELF) rusage = getrusage(RUSAGE_SELF)

View File

@ -27,7 +27,7 @@ class BaseMetric(object):
def __init__(self, name, labels=[]): def __init__(self, name, labels=[]):
self.name = name self.name = name
self.labels = labels # OK not to clone as we never write it self.labels = labels # OK not to clone as we never write it
def dimension(self): def dimension(self):
return len(self.labels) return len(self.labels)
@ -66,8 +66,8 @@ class CounterMetric(BaseMetric):
def inc_by(self, incr, *values): def inc_by(self, incr, *values):
if len(values) != self.dimension(): if len(values) != self.dimension():
raise ValueError("Expected as many values to inc() as labels (%d)" % raise ValueError(
(self.dimension()) "Expected as many values to inc() as labels (%d)" % (self.dimension())
) )
# TODO: should assert that the tag values are all strings # TODO: should assert that the tag values are all strings
@ -135,10 +135,11 @@ class CacheMetric(object):
def __init__(self, name, size_callback, labels=[]): def __init__(self, name, size_callback, labels=[]):
self.name = name self.name = name
self.hits = CounterMetric(name + ":hits", labels=labels) self.hits = CounterMetric(name + ":hits", labels=labels)
self.total = CounterMetric(name + ":total", labels=labels) self.total = CounterMetric(name + ":total", labels=labels)
self.size = CallbackMetric(name + ":size", self.size = CallbackMetric(
name + ":size",
callback=size_callback, callback=size_callback,
labels=labels, labels=labels,
) )

View File

@ -26,7 +26,7 @@ class MetricsResource(Resource):
isLeaf = True isLeaf = True
def __init__(self, hs): def __init__(self, hs):
Resource.__init__(self) # Resource is old-style, so no super() Resource.__init__(self) # Resource is old-style, so no super()
self.hs = hs self.hs = hs

View File

@ -127,14 +127,17 @@ class Notifier(object):
return len(all_listeners) return len(all_listeners)
metrics.register_callback("listeners", count_listeners) metrics.register_callback("listeners", count_listeners)
metrics.register_callback("rooms", metrics.register_callback(
lambda: count(bool, self.room_to_listeners.values()) "rooms",
lambda: count(bool, self.room_to_listeners.values()),
) )
metrics.register_callback("users", metrics.register_callback(
lambda: count(bool, self.user_to_listeners.values()) "users",
lambda: count(bool, self.user_to_listeners.values()),
) )
metrics.register_callback("appservices", metrics.register_callback(
lambda: count(bool, self.appservice_to_listeners.values()) "appservices",
lambda: count(bool, self.appservice_to_listeners.values()),
) )
@log_function @log_function