diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2019-07-24 11:33:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-24 11:33:13 +0100 |
commit | 418635e68a127da24bf887adcbf19d3110c57630 (patch) | |
tree | c896f9452021f75ec0351f3e7fb4664463d49687 /synapse/util/caches/__init__.py | |
parent | Make Jaeger fully configurable (#5694) (diff) | |
download | synapse-418635e68a127da24bf887adcbf19d3110c57630.tar.xz |
Add a prometheus metric for active cache lookups. (#5750)
* Add a prometheus metric for active cache lookups. * changelog
Diffstat (limited to 'synapse/util/caches/__init__.py')
-rw-r--r-- | synapse/util/caches/__init__.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/synapse/util/caches/__init__.py b/synapse/util/caches/__init__.py index 8271229015..b50e3503f0 100644 --- a/synapse/util/caches/__init__.py +++ b/synapse/util/caches/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # Copyright 2015, 2016 OpenMarket Ltd +# Copyright 2019 The Matrix.org Foundation C.I.C. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -51,7 +52,19 @@ response_cache_evicted = Gauge( response_cache_total = Gauge("synapse_util_caches_response_cache:total", "", ["name"]) -def register_cache(cache_type, cache_name, cache): +def register_cache(cache_type, cache_name, cache, collect_callback=None): + """Register a cache object for metric collection. + + Args: + cache_type (str): + cache_name (str): name of the cache + cache (object): cache itself + collect_callback (callable|None): if not None, a function which is called during + metric collection to update additional metrics. + + Returns: + CacheMetric: an object which provides inc_{hits,misses,evictions} methods + """ # Check if the metric is already registered. Unregister it, if so. # This usually happens during tests, as at runtime these caches are @@ -90,6 +103,8 @@ def register_cache(cache_type, cache_name, cache): cache_hits.labels(cache_name).set(self.hits) cache_evicted.labels(cache_name).set(self.evicted_size) cache_total.labels(cache_name).set(self.hits + self.misses) + if collect_callback: + collect_callback() except Exception as e: logger.warn("Error calculating metrics for %s: %s", cache_name, e) raise |