forked from MirrorHub/synapse
Move in_flight_requests_count to be a callback metric
This commit is contained in:
parent
dfa70adc33
commit
fb2806b186
1 changed files with 25 additions and 14 deletions
|
@ -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,22 +134,37 @@ def _collect_in_flight():
|
|||
the in flight request metrics
|
||||
"""
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
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:
|
||||
key = (rm.method, rm.name,)
|
||||
counts[key] = counts.get(key, 0) + 1
|
||||
|
||||
return counts
|
||||
|
||||
|
||||
metrics.register_callback(
|
||||
"in_flight_requests_count",
|
||||
_get_in_flight_counts,
|
||||
labels=["method", "servlet"]
|
||||
)
|
||||
|
||||
|
||||
class RequestMetrics(object):
|
||||
def start(self, time_msec, name, method):
|
||||
self.start = time_msec
|
||||
|
|
Loading…
Reference in a new issue