~ricardokirkner/txstatsd/gauge-with-delta

« back to all changes in this revision

Viewing changes to txstatsd/metrics/metrics.py

  • Committer: lucio.torre@gmail.com
  • Date: 2011-11-18 19:42:56 UTC
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: git-v1:f435b5b8c6464c8a714601936328de91fdd60a43
fixed per review comments

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
        super(GenericMetric, self).__init__(connection, name,
11
11
                                            sample_rate=sample_rate)
12
12
        self.key = key
13
 
        
 
13
 
14
14
    def mark(self, value):
15
15
        self.send("%s|%s" % (value, self.key))
16
16
 
17
 
        
 
17
 
18
18
class Metrics(object):
19
19
    def __init__(self, connection=None, namespace=""):
20
20
        """A convenience class for reporting metric samples
31
31
        self._metrics = {}
32
32
 
33
33
    def report(self, name, value, key, sample_rate=1):
34
 
        """Report a generic metric. 
 
34
        """Report a generic metric.
35
35
 
36
36
        Used for server side plugins without client support.
37
37
        """
38
38
        name = self.fully_qualify_name(name)
39
39
        if not name in self._metrics:
40
 
            gauge_metric = GenericMetric(self.connection,
 
40
            metric = GenericMetric(self.connection,
41
41
                                        key,
42
42
                                        name,
43
43
                                        sample_rate)
44
 
            self._metrics[name] = gauge_metric
 
44
            self._metrics[name] = metric
45
45
        self._metrics[name].mark(value)
46
 
        
 
46
 
47
47
    def gauge(self, name, value, sample_rate=1):
48
48
        """Report an instantaneous reading of a particular value."""
49
49
        name = self.fully_qualify_name(name)
100
100
            metric = DistinctMetric(self.connection, name)
101
101
            self._metrics[name] = metric
102
102
        self._metrics[name].mark(item)
103
 
        
 
103
 
104
104
    def clear(self, name):
105
105
        """Allow the metric to re-initialize its internal state."""
106
106
        name = self.fully_qualify_name(name)