mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 10:46:06 -04:00
Initial hack at a TimerMetric; for storing counts + duration accumulators
This commit is contained in:
parent
e1a7e3564f
commit
72625f2f4d
2 changed files with 83 additions and 1 deletions
|
@ -16,7 +16,7 @@
|
|||
from tests import unittest
|
||||
|
||||
from synapse.metrics.metric import (
|
||||
CounterMetric, CallbackMetric, CacheMetric
|
||||
CounterMetric, CallbackMetric, TimerMetric, CacheMetric
|
||||
)
|
||||
|
||||
|
||||
|
@ -97,6 +97,40 @@ class CallbackMetricTestCase(unittest.TestCase):
|
|||
])
|
||||
|
||||
|
||||
class TimerMetricTestCase(unittest.TestCase):
|
||||
|
||||
def test_scalar(self):
|
||||
metric = TimerMetric("thing")
|
||||
|
||||
self.assertEquals(metric.render(), [
|
||||
"thing:count 0",
|
||||
"thing:msec 0",
|
||||
])
|
||||
|
||||
metric.inc_time(500)
|
||||
|
||||
self.assertEquals(metric.render(), [
|
||||
"thing:count 1",
|
||||
"thing:msec 500",
|
||||
])
|
||||
|
||||
def test_vector(self):
|
||||
metric = TimerMetric("queries", keys=["verb"])
|
||||
|
||||
self.assertEquals(metric.render(), [])
|
||||
|
||||
metric.inc_time(300, "SELECT")
|
||||
metric.inc_time(200, "SELECT")
|
||||
metric.inc_time(800, "INSERT")
|
||||
|
||||
self.assertEquals(metric.render(), [
|
||||
"queries{verb=INSERT}:count 1",
|
||||
"queries{verb=INSERT}:msec 800",
|
||||
"queries{verb=SELECT}:count 2",
|
||||
"queries{verb=SELECT}:msec 500",
|
||||
])
|
||||
|
||||
|
||||
class CacheMetricTestCase(unittest.TestCase):
|
||||
|
||||
def test_cache(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue