Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Make Counter render floats #2778

Merged
merged 1 commit into from
Jan 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions synapse/metrics/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ def _render_key(self, values):

class CounterMetric(BaseMetric):
"""The simplest kind of metric; one that stores a monotonically-increasing
integer that counts events."""
value that counts events or running totals.

Example use cases for Counters:
- Number of requests processed
- Number of items that were inserted into a queue
- Total amount of data that a system has processed
Counters can only go up (and be reset when the process restarts).
"""

def __init__(self, *args, **kwargs):
super(CounterMetric, self).__init__(*args, **kwargs)
Expand All @@ -59,7 +66,7 @@ def __init__(self, *args, **kwargs):

# Scalar metrics are never empty
if self.is_scalar():
self.counts[()] = 0
self.counts[()] = 0.

def inc_by(self, incr, *values):
if len(values) != self.dimension():
Expand All @@ -78,7 +85,7 @@ def inc(self, *values):
self.inc_by(1, *values)

def render_item(self, k):
return ["%s%s %d" % (self.name, self._render_key(k), self.counts[k])]
return ["%s%s %.12g" % (self.name, self._render_key(k), self.counts[k])]

def render(self):
return map_concat(self.render_item, sorted(self.counts.keys()))
Expand Down