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
=== modified file 'txstatsd/server/httpinfo.py'
--- txstatsd/server/httpinfo.py 2012-02-08 22:19:54 +0000
+++ txstatsd/server/httpinfo.py 2012-04-26 19:38:18 +0000
@@ -27,6 +27,17 @@
27 return json.dumps(data)27 return json.dumps(data)
2828
2929
30class ListMetrics(resource.Resource):
31
32 def __init__(self, processor):
33 resource.Resource.__init__(self)
34 self.processor = processor
35
36 def render_GET(self, request):
37 data = dict(names=self.processor.get_metric_names())
38 return json.dumps(data)
39
40
30class Metrics(resource.Resource):41class Metrics(resource.Resource):
3142
32 def __init__(self, processor):43 def __init__(self, processor):
@@ -55,6 +66,7 @@
55 root = resource.Resource()66 root = resource.Resource()
56 root.putChild("status", Status(processor, statsd_service))67 root.putChild("status", Status(processor, statsd_service))
57 root.putChild("metrics", Metrics(processor))68 root.putChild("metrics", Metrics(processor))
69 root.putChild("list_metrics", ListMetrics(processor))
58 site = server.Site(root)70 site = server.Site(root)
59 s = internet.TCPServer(int(options["http-port"]), site)71 s = internet.TCPServer(int(options["http-port"]), site)
60 return s72 return s
6173
=== modified file 'txstatsd/server/processor.py'
--- txstatsd/server/processor.py 2012-02-07 21:11:42 +0000
+++ txstatsd/server/processor.py 2012-04-26 19:38:18 +0000
@@ -88,6 +88,16 @@
88 for plugin in plugins:88 for plugin in plugins:
89 self.plugins[plugin.metric_type] = plugin89 self.plugins[plugin.metric_type] = plugin
9090
91 def get_metric_names(self):
92 """Return the names of all seen metrics."""
93 metrics = set()
94 metrics.update(self.timer_metrics.keys())
95 metrics.update(self.counter_metrics.keys())
96 metrics.update(v for k, v in self.gauge_metrics)
97 metrics.update(self.meter_metrics.keys())
98 metrics.update(self.plugin_metrics.keys())
99 return list(metrics)
100
91 def process_message(self, message, metric_type, key, fields):101 def process_message(self, message, metric_type, key, fields):
92 """102 """
93 Process a single entry, adding it to either C{counters}, C{timers},103 Process a single entry, adding it to either C{counters}, C{timers},
94104
=== modified file 'txstatsd/tests/test_httpinfo.py'
--- txstatsd/tests/test_httpinfo.py 2012-02-08 23:18:27 +0000
+++ txstatsd/tests/test_httpinfo.py 2012-04-26 19:38:18 +0000
@@ -17,6 +17,11 @@
17 last_flush_duration = 317 last_flush_duration = 3
18 last_process_duration = 218 last_process_duration = 2
1919
20 metric_names = ["one", "two", "three"]
21
22 def get_metric_names(self):
23 return self.metric_names
24
2025
21class ResponseCollector(protocol.Protocol):26class ResponseCollector(protocol.Protocol):
2227
@@ -73,6 +78,11 @@
73 self.service.stopService()78 self.service.stopService()
7479
75 @defer.inlineCallbacks80 @defer.inlineCallbacks
81 def test_httpinfo_metric_names(self):
82 data = yield self.get_results("list_metrics")
83 self.assertEquals(Dummy.metric_names, json.loads(data)["names"])
84
85 @defer.inlineCallbacks
76 def test_httpinfo_ok(self):86 def test_httpinfo_ok(self):
77 data = yield self.get_results("status")87 data = yield self.get_results("status")
78 self.assertEquals(json.loads(data)["status"], "OK")88 self.assertEquals(json.loads(data)["status"], "OK")
7989
=== modified file 'txstatsd/tests/test_processor.py'
--- txstatsd/tests/test_processor.py 2012-01-30 22:38:47 +0000
+++ txstatsd/tests/test_processor.py 2012-04-26 19:38:18 +0000
@@ -42,6 +42,13 @@
42 self.processor.rebuild_message("c", "gorets", ["1", "c"]),42 self.processor.rebuild_message("c", "gorets", ["1", "c"]),
43 "gorets:1|c")43 "gorets:1|c")
4444
45 def test_metric_names(self):
46 """We return the names of all seen metrics."""
47 kinds = set(["ms", "c", "g", "pd"])
48 for kind in kinds:
49 self.processor.process("%s:1|%s" % (kind, kind))
50 self.assertEquals(kinds, set(self.processor.get_metric_names()))
51
45 def test_receive_counter(self):52 def test_receive_counter(self):
46 """53 """
47 A counter message takes the format 'gorets:1|c', where 'gorets' is the54 A counter message takes the format 'gorets:1|c', where 'gorets' is the

Subscribers

People subscribed via source and target branches