~ori-livneh/txstatsd/wikimedia

« back to all changes in this revision

Viewing changes to txstatsd/metrics/timermetric.py

  • Committer: Sidnei da Silva
  • Date: 2012-11-20 11:56:07 UTC
  • Revision ID: sidnei.da.silva@canonical.com-20121120115607-kpq495yxlb54571i
- Move TimerResource to httpinfo so that importing timermetric does not install a reactor by accident.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
20
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
 
import json
23
22
import time
24
23
 
25
 
from twisted.web import resource
26
 
 
27
24
from txstatsd.metrics.histogrammetric import HistogramMetricReporter
28
25
from txstatsd.metrics.metric import Metric
29
26
from txstatsd.stats.uniformsample import UniformSample
52
49
        self.send("%s|ms" % (duration * 1000))
53
50
 
54
51
 
55
 
class TimerResource(resource.Resource):
56
 
    isLeaf = True
57
 
 
58
 
    def __init__(self, reporter):
59
 
        resource.Resource.__init__(self)
60
 
        self.reporter = reporter
61
 
 
62
 
    def render_GET(self, request):
63
 
        result = dict(
64
 
            histogram=self.reporter.histogram.histogram(),
65
 
            max_value=self.reporter.max(),
66
 
            min_value=self.reporter.min())
67
 
        return json.dumps(result)
68
 
 
69
 
 
70
52
class TimerMetricReporter(object):
71
53
    """
72
54
    A timer metric which aggregates timing durations and provides duration
126
108
 
127
109
    def getResource(self):
128
110
        """Return an http resource to represent this."""
 
111
        from txstatsd.server.httpinfo import TimerResource
129
112
        return TimerResource(self)
130
113
 
131
114
    def percentiles(self, *percentiles):