Show More
@@ -14,6 +14,11 b' TAG_INVALID_CHARS_RE = re.compile(' | |||
|
14 | 14 | ) |
|
15 | 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 | 23 | @lru_cache(maxsize=500) |
|
19 | 24 | def _normalize_tags_with_cache(tag_list): |
@@ -42,7 +47,7 b' class StatsClientBase(object):' | |||
|
42 | 47 | def timer(self, stat, rate=1, tags=None): |
|
43 | 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 | 52 | Send new timing information. |
|
48 | 53 | |
@@ -51,7 +56,11 b' class StatsClientBase(object):' | |||
|
51 | 56 | if isinstance(delta, timedelta): |
|
52 | 57 | # Convert timedelta to number of milliseconds. |
|
53 | 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 | 65 | def incr(self, stat, count=1, rate=1, tags=None): |
|
57 | 66 | """Increment a stat by `count`.""" |
@@ -78,10 +87,17 b' class StatsClientBase(object):' | |||
|
78 | 87 | """Set a set value.""" |
|
79 | 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 | 94 | def _send_stat(self, stat, value, rate, tags=None): |
|
82 | 95 | self._after(self._prepare(stat, value, rate, tags)) |
|
83 | 96 | |
|
84 | 97 | def _prepare(self, stat, value, rate, tags=None): |
|
98 | global buckets_dict | |
|
99 | buckets_dict[stat] = 1 | |
|
100 | ||
|
85 | 101 | if rate < 1: |
|
86 | 102 | if random.random() > rate: |
|
87 | 103 | return |
@@ -60,13 +60,22 b' class RequestWrapperTween(object):' | |||
|
60 | 60 | |
|
61 | 61 | statsd = request.registry.statsd |
|
62 | 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 | 66 | statsd.timing( |
|
65 |
|
|
|
66 |
tags=[ |
|
|
67 | "vcsserver_req_timing.histogram", elapsed_time_ms, | |
|
68 | tags=[ | |
|
69 | "view_name:{}".format(match_route), | |
|
70 | "code:{}".format(resp_code) | |
|
71 | ], | |
|
72 | use_decimals=False | |
|
67 | 73 | ) |
|
68 | 74 | statsd.incr( |
|
69 |
|
|
|
75 | "vcsserver_req_total", tags=[ | |
|
76 | "view_name:{}".format(match_route), | |
|
77 | "code:{}".format(resp_code) | |
|
78 | ]) | |
|
70 | 79 | return response |
|
71 | 80 | |
|
72 | 81 |
General Comments 0
You need to be logged in to leave comments.
Login now