diff options
author | Richard van der Hoff <richard@matrix.org> | 2018-01-15 16:52:52 +0000 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2018-01-15 16:52:52 +0000 |
commit | 80fa610f9c8702d6b7256be9d97668de29ba2e06 (patch) | |
tree | 98cc2a474ea4df5d9202e098618440654e459a17 /synapse/metrics/metric.py | |
parent | Merge pull request #2778 from matrix-org/rav/counters_should_be_floats (diff) | |
download | synapse-80fa610f9c8702d6b7256be9d97668de29ba2e06.tar.xz |
Add some comments to metrics classes
Diffstat (limited to '')
-rw-r--r-- | synapse/metrics/metric.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/synapse/metrics/metric.py b/synapse/metrics/metric.py index 1d054dd557..c5f0bcbc15 100644 --- a/synapse/metrics/metric.py +++ b/synapse/metrics/metric.py @@ -24,8 +24,16 @@ def map_concat(func, items): class BaseMetric(object): + """Base class for metrics which report a single value per label set + """ def __init__(self, name, labels=[]): + """ + Args: + name (str): principal name for this metric + labels (list(str)): names of the labels which will be reported + for this metric + """ self.name = name self.labels = labels # OK not to clone as we never write it @@ -36,7 +44,7 @@ class BaseMetric(object): return not len(self.labels) def _render_labelvalue(self, value): - # TODO: some kind of value escape + # TODO: escape backslashes, quotes and newlines return '"%s"' % (value) def _render_key(self, values): @@ -47,6 +55,20 @@ class BaseMetric(object): for k, v in zip(self.labels, values)]) ) + def render(self): + """Render this metric + + Each metric is rendered as: + + name{label1="val1",label2="val2"} value + + https://prometheus.io/docs/instrumenting/exposition_formats/#text-format-details + + Returns: + iterable[str]: rendered metrics + """ + raise NotImplementedError() + class CounterMetric(BaseMetric): """The simplest kind of metric; one that stores a monotonically-increasing @@ -62,6 +84,10 @@ class CounterMetric(BaseMetric): def __init__(self, *args, **kwargs): super(CounterMetric, self).__init__(*args, **kwargs) + # dict[list[str]]: value for each set of label values. the keys are the + # label values, in the same order as the labels in self.labels. + # + # (if the metric is a scalar, the (single) key is the empty list). self.counts = {} # Scalar metrics are never empty |