diff options
author | Erik Johnston <erik@matrix.org> | 2018-05-22 09:31:53 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2018-05-22 09:31:53 +0100 |
commit | fb2806b1868baaa24d0d6e21d10f2c1f6177717e (patch) | |
tree | 4072fa3e8cb5ff16e3ef84a2fb670a8b3e904247 /synapse | |
parent | Add in flight request metrics (diff) | |
download | synapse-fb2806b1868baaa24d0d6e21d10f2c1f6177717e.tar.xz |
Move in_flight_requests_count to be a callback metric
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/http/request_metrics.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/synapse/http/request_metrics.py b/synapse/http/request_metrics.py index f1e9b41fde..8cb23f4d64 100644 --- a/synapse/http/request_metrics.py +++ b/synapse/http/request_metrics.py @@ -124,12 +124,8 @@ in_flight_requests_db_sched_duration = metrics.register_counter( "in_flight_requests_db_sched_duration_seconds", labels=["method", "servlet"] ) -_in_flight_requests_count = metrics.register_gauge( - "in_flight_requests_count", labels=["method", "servlet"] -) - -# The set of all in flight requests. +# The set of all in flight requests, set[RequestMetrics] _in_flight_requests = set() @@ -138,20 +134,35 @@ def _collect_in_flight(): the in flight request metrics """ + for rm in _in_flight_requests: + rm.update_metrics() + + +metrics.register_collector(_collect_in_flight) + + +def _get_in_flight_counts(): + """Returns a count of all in flight requests by (method, server_name) + + Returns: + dict[tuple[str, str], int] + """ + # Map from (method, name) -> int, the number of in flight requests of that # type counts = {} - for rm in _in_flight_requests: - rm.update_metrics() key = (rm.method, rm.name,) counts[key] = counts.get(key, 0) + 1 - for (method, name), count in counts.iteritems(): - _in_flight_requests_count.set(count, method, name) + return counts -metrics.register_collector(_collect_in_flight) +metrics.register_callback( + "in_flight_requests_count", + _get_in_flight_counts, + labels=["method", "servlet"] +) class RequestMetrics(object): |