Merge lp:~lucio.torre/txstatsd/add-list-metrics into lp:txstatsd

Proposed by Lucio Torre
Status: Merged
Approved by: Sidnei da Silva
Approved revision: 78
Merged at revision: 78
Proposed branch: lp:~lucio.torre/txstatsd/add-list-metrics
Merge into: lp:txstatsd
Diff against target: 96 lines (+39/-0)
4 files modified
txstatsd/server/httpinfo.py (+12/-0)
txstatsd/server/processor.py (+10/-0)
txstatsd/tests/test_httpinfo.py (+10/-0)
txstatsd/tests/test_processor.py (+7/-0)
To merge this branch: bzr merge lp:~lucio.torre/txstatsd/add-list-metrics
Reviewer Review Type Date Requested Status
Sidnei da Silva Approve
Review via email: mp+103759@code.launchpad.net

Commit message

add the /list_metrics url resource so we know what metrics each instance knows about

Description of the change

add the /list_metrics url resource so we know what metrics each instance knows about

To post a comment you must log in.
Revision history for this message
Sidnei da Silva (sidnei) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'txstatsd/server/httpinfo.py'
2--- txstatsd/server/httpinfo.py 2012-02-08 22:19:54 +0000
3+++ txstatsd/server/httpinfo.py 2012-04-26 19:38:18 +0000
4@@ -27,6 +27,17 @@
5 return json.dumps(data)
6
7
8+class ListMetrics(resource.Resource):
9+
10+ def __init__(self, processor):
11+ resource.Resource.__init__(self)
12+ self.processor = processor
13+
14+ def render_GET(self, request):
15+ data = dict(names=self.processor.get_metric_names())
16+ return json.dumps(data)
17+
18+
19 class Metrics(resource.Resource):
20
21 def __init__(self, processor):
22@@ -55,6 +66,7 @@
23 root = resource.Resource()
24 root.putChild("status", Status(processor, statsd_service))
25 root.putChild("metrics", Metrics(processor))
26+ root.putChild("list_metrics", ListMetrics(processor))
27 site = server.Site(root)
28 s = internet.TCPServer(int(options["http-port"]), site)
29 return s
30
31=== modified file 'txstatsd/server/processor.py'
32--- txstatsd/server/processor.py 2012-02-07 21:11:42 +0000
33+++ txstatsd/server/processor.py 2012-04-26 19:38:18 +0000
34@@ -88,6 +88,16 @@
35 for plugin in plugins:
36 self.plugins[plugin.metric_type] = plugin
37
38+ def get_metric_names(self):
39+ """Return the names of all seen metrics."""
40+ metrics = set()
41+ metrics.update(self.timer_metrics.keys())
42+ metrics.update(self.counter_metrics.keys())
43+ metrics.update(v for k, v in self.gauge_metrics)
44+ metrics.update(self.meter_metrics.keys())
45+ metrics.update(self.plugin_metrics.keys())
46+ return list(metrics)
47+
48 def process_message(self, message, metric_type, key, fields):
49 """
50 Process a single entry, adding it to either C{counters}, C{timers},
51
52=== modified file 'txstatsd/tests/test_httpinfo.py'
53--- txstatsd/tests/test_httpinfo.py 2012-02-08 23:18:27 +0000
54+++ txstatsd/tests/test_httpinfo.py 2012-04-26 19:38:18 +0000
55@@ -17,6 +17,11 @@
56 last_flush_duration = 3
57 last_process_duration = 2
58
59+ metric_names = ["one", "two", "three"]
60+
61+ def get_metric_names(self):
62+ return self.metric_names
63+
64
65 class ResponseCollector(protocol.Protocol):
66
67@@ -73,6 +78,11 @@
68 self.service.stopService()
69
70 @defer.inlineCallbacks
71+ def test_httpinfo_metric_names(self):
72+ data = yield self.get_results("list_metrics")
73+ self.assertEquals(Dummy.metric_names, json.loads(data)["names"])
74+
75+ @defer.inlineCallbacks
76 def test_httpinfo_ok(self):
77 data = yield self.get_results("status")
78 self.assertEquals(json.loads(data)["status"], "OK")
79
80=== modified file 'txstatsd/tests/test_processor.py'
81--- txstatsd/tests/test_processor.py 2012-01-30 22:38:47 +0000
82+++ txstatsd/tests/test_processor.py 2012-04-26 19:38:18 +0000
83@@ -42,6 +42,13 @@
84 self.processor.rebuild_message("c", "gorets", ["1", "c"]),
85 "gorets:1|c")
86
87+ def test_metric_names(self):
88+ """We return the names of all seen metrics."""
89+ kinds = set(["ms", "c", "g", "pd"])
90+ for kind in kinds:
91+ self.processor.process("%s:1|%s" % (kind, kind))
92+ self.assertEquals(kinds, set(self.processor.get_metric_names()))
93+
94 def test_receive_counter(self):
95 """
96 A counter message takes the format 'gorets:1|c', where 'gorets' is the

Subscribers

People subscribed via source and target branches