##// END OF EJS Templates
metrics: updated statsd client and fixed some metrics
super-admin -
r1013:dcc06da1 default
parent child Browse files
Show More
@@ -14,6 +14,11 b' TAG_INVALID_CHARS_RE = re.compile('
14 )
14 )
15 TAG_INVALID_CHARS_SUBS = "_"
15 TAG_INVALID_CHARS_SUBS = "_"
16
16
17 # we save and expose methods called by statsd for discovery
18 buckets_dict = {
19
20 }
21
17
22
18 @lru_cache(maxsize=500)
23 @lru_cache(maxsize=500)
19 def _normalize_tags_with_cache(tag_list):
24 def _normalize_tags_with_cache(tag_list):
@@ -42,7 +47,7 b' class StatsClientBase(object):'
42 def timer(self, stat, rate=1, tags=None):
47 def timer(self, stat, rate=1, tags=None):
43 return Timer(self, stat, rate, tags)
48 return Timer(self, stat, rate, tags)
44
49
45 def timing(self, stat, delta, rate=1, tags=None):
50 def timing(self, stat, delta, rate=1, tags=None, use_decimals=True):
46 """
51 """
47 Send new timing information.
52 Send new timing information.
48
53
@@ -51,7 +56,11 b' class StatsClientBase(object):'
51 if isinstance(delta, timedelta):
56 if isinstance(delta, timedelta):
52 # Convert timedelta to number of milliseconds.
57 # Convert timedelta to number of milliseconds.
53 delta = delta.total_seconds() * 1000.
58 delta = delta.total_seconds() * 1000.
54 self._send_stat(stat, '%0.6f|ms' % delta, rate, tags)
59 if use_decimals:
60 fmt = '%0.6f|ms'
61 else:
62 fmt = '%s|ms'
63 self._send_stat(stat, fmt % delta, rate, tags)
55
64
56 def incr(self, stat, count=1, rate=1, tags=None):
65 def incr(self, stat, count=1, rate=1, tags=None):
57 """Increment a stat by `count`."""
66 """Increment a stat by `count`."""
@@ -78,10 +87,17 b' class StatsClientBase(object):'
78 """Set a set value."""
87 """Set a set value."""
79 self._send_stat(stat, '%s|s' % value, rate)
88 self._send_stat(stat, '%s|s' % value, rate)
80
89
90 def histogram(self, stat, value, rate=1, tags=None):
91 """Set a histogram"""
92 self._send_stat(stat, '%s|h' % value, rate, tags)
93
81 def _send_stat(self, stat, value, rate, tags=None):
94 def _send_stat(self, stat, value, rate, tags=None):
82 self._after(self._prepare(stat, value, rate, tags))
95 self._after(self._prepare(stat, value, rate, tags))
83
96
84 def _prepare(self, stat, value, rate, tags=None):
97 def _prepare(self, stat, value, rate, tags=None):
98 global buckets_dict
99 buckets_dict[stat] = 1
100
85 if rate < 1:
101 if rate < 1:
86 if random.random() > rate:
102 if random.random() > rate:
87 return
103 return
@@ -60,13 +60,22 b' class RequestWrapperTween(object):'
60
60
61 statsd = request.registry.statsd
61 statsd = request.registry.statsd
62 if statsd:
62 if statsd:
63 elapsed_time_ms = 1000.0 * total
63 match_route = request.matched_route.name if request.matched_route else _path
64 resp_code = response.status_code
65 elapsed_time_ms = round(1000.0 * total) # use ms only
64 statsd.timing(
66 statsd.timing(
65 'vcsserver_req_timing', elapsed_time_ms,
67 "vcsserver_req_timing.histogram", elapsed_time_ms,
66 tags=["path:{}".format(_path)]
68 tags=[
69 "view_name:{}".format(match_route),
70 "code:{}".format(resp_code)
71 ],
72 use_decimals=False
67 )
73 )
68 statsd.incr(
74 statsd.incr(
69 'vcsserver_req_total', tags=["path:{}".format(_path)])
75 "vcsserver_req_total", tags=[
76 "view_name:{}".format(match_route),
77 "code:{}".format(resp_code)
78 ])
70 return response
79 return response
71
80
72
81
General Comments 0
You need to be logged in to leave comments. Login now