def metrics(): """ Prometheus metrics endpoint. """ headers = {'Content-type': 'text/plain'} return flask.Response(generate_latest(registry=StatsCache().registry), 200, headers)
def test_shared_state(self): stats_cache_01 = StatsCache() with pytest.raises(AttributeError) as e_info: stats_cache_01.foo assert 'object has no attribute' in e_info.message assert stats_cache_01.counter._value._value == 0 stats_cache_01.count() stats_cache_01.count() assert stats_cache_01.counter._value._value == 2 stats_cache_02 = StatsCache() assert stats_cache_02.counter._value._value == 2 stats_cache_02.count() stats_cache_02.count() assert stats_cache_01.counter._value._value == 4 assert stats_cache_02.counter._value._value == 4
def metrics(): """ Prometheus metrics endpoint. """ headers = {'Content-type': 'text/plain'} stats_cache = StatsCache() requests_cache = RequestsCache() stats_cache.set_cache_size(sys.getsizeof(requests_cache)) stats_cache.set_cached_objects(len(requests_cache)) return flask.Response(generate_latest(registry=stats_cache.registry), 200, headers)
# Author: Amador Pahim <*****@*****.**> """ Metrics decorators. """ import time from functools import wraps import flask from ghmirror.data_structures.monostate import StatsCache STATS_CACHE = StatsCache() def requests_metrics(function): """ Decorator to collect metrics from the request and populate the StatsCache object. """ @wraps(function) def wrapper(*args, **kwargs): start = time.time() response = function(*args, **kwargs) # This is the total time spent to process the request elapsed_time = (time.time() - start)