mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-09-07 22:11:57 +00:00
Export CacheMetric as hits+total, rather than hits+misses, as it's easier to derive hit ratio from that
This commit is contained in:
parent
1748605c5d
commit
cbc0406be8
@ -134,7 +134,7 @@ class TimerMetric(CounterMetric):
|
|||||||
|
|
||||||
class CacheMetric(object):
|
class CacheMetric(object):
|
||||||
"""A combination of two CounterMetrics, one to count cache hits and one to
|
"""A combination of two CounterMetrics, one to count cache hits and one to
|
||||||
count misses, and a callback metric to yield the current size.
|
count a total, and a callback metric to yield the current size.
|
||||||
|
|
||||||
This metric generates standard metric name pairs, so that monitoring rules
|
This metric generates standard metric name pairs, so that monitoring rules
|
||||||
can easily be applied to measure hit ratio."""
|
can easily be applied to measure hit ratio."""
|
||||||
@ -143,7 +143,7 @@ class CacheMetric(object):
|
|||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
self.hits = CounterMetric(name + ":hits", labels=labels)
|
self.hits = CounterMetric(name + ":hits", labels=labels)
|
||||||
self.misses = CounterMetric(name + ":misses", 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,
|
||||||
@ -152,9 +152,10 @@ class CacheMetric(object):
|
|||||||
|
|
||||||
def inc_hits(self, *values):
|
def inc_hits(self, *values):
|
||||||
self.hits.inc(*values)
|
self.hits.inc(*values)
|
||||||
|
self.total.inc(*values)
|
||||||
|
|
||||||
def inc_misses(self, *values):
|
def inc_misses(self, *values):
|
||||||
self.misses.inc(*values)
|
self.total.inc(*values)
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
return self.hits.render() + self.misses.render() + self.size.render()
|
return self.hits.render() + self.total.render() + self.size.render()
|
||||||
|
@ -140,7 +140,7 @@ class CacheMetricTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEquals(metric.render(), [
|
self.assertEquals(metric.render(), [
|
||||||
'cache:hits 0',
|
'cache:hits 0',
|
||||||
'cache:misses 0',
|
'cache:total 0',
|
||||||
'cache:size 0',
|
'cache:size 0',
|
||||||
])
|
])
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ class CacheMetricTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEquals(metric.render(), [
|
self.assertEquals(metric.render(), [
|
||||||
'cache:hits 0',
|
'cache:hits 0',
|
||||||
'cache:misses 1',
|
'cache:total 1',
|
||||||
'cache:size 1',
|
'cache:size 1',
|
||||||
])
|
])
|
||||||
|
|
||||||
@ -157,6 +157,6 @@ class CacheMetricTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEquals(metric.render(), [
|
self.assertEquals(metric.render(), [
|
||||||
'cache:hits 1',
|
'cache:hits 1',
|
||||||
'cache:misses 1',
|
'cache:total 2',
|
||||||
'cache:size 1',
|
'cache:size 1',
|
||||||
])
|
])
|
||||||
|
Loading…
Reference in New Issue
Block a user