~theiw/txstatsd/txstatsd-fix-871735

« back to all changes in this revision

Viewing changes to txstatsd/metrics/extendedmetrics.py

  • Committer: Tarmac
  • Author(s): ian.wilkinson at canonical
  • Date: 2011-09-13 14:30:31 UTC
  • mfrom: (32.1.2 txstatsd-coda-hale-counters)
  • Revision ID: tarmac-20110913143031-526vudiri9ulptwn
[r=sidnei,lucio.torre] Include support for reporting counter metrics, fixes an issue with the prefix for meter metrics.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from txstatsd.metrics.countermetric import CounterMetric
 
3
from txstatsd.metrics.metrics import Metrics
 
4
 
 
5
 
 
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>}
 
11
        processor.
 
12
 
 
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.
 
17
        """
 
18
 
 
19
        super(ExtendedMetrics, self).__init__(connection, namespace)
 
20
 
 
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,
 
26
                                   name,
 
27
                                   sample_rate)
 
28
            self._metrics[name] = metric
 
29
        self._metrics[name].increment(value)
 
30
 
 
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,
 
36
                                   name,
 
37
                                   sample_rate)
 
38
            self._metrics[name] = metric
 
39
        self._metrics[name].decrement(value)