2
from txstatsd.metrics.countermetric import CounterMetric
3
from txstatsd.metrics.metrics import Metrics
6
class ExtendedMetrics(Metrics):
7
def __init__(self, connection=None, namespace=""):
8
"""A convenience class for reporting metric samples
9
to a C{txstatsd} server configured with the
10
L{ConfigurableProcessor<txstatsd.server.configurableprocessor>}
13
@param connection: The connection endpoint representing
14
the C{txstatsd} server.
15
@param namespace: The top-level namespace identifying the
16
origin of the samples.
19
super(ExtendedMetrics, self).__init__(connection, namespace)
21
def increment(self, name, value=1, sample_rate=1):
22
"""Report and increase in name by count."""
23
name = self.fully_qualify_name(name)
24
if not name in self._metrics:
25
metric = CounterMetric(self.connection,
28
self._metrics[name] = metric
29
self._metrics[name].increment(value)
31
def decrement(self, name, value=1, sample_rate=1):
32
"""Report and decrease in name by count."""
33
name = self.fully_qualify_name(name)
34
if not name in self._metrics:
35
metric = CounterMetric(self.connection,
38
self._metrics[name] = metric
39
self._metrics[name].decrement(value)