diff --git a/vcsserver/lib/_vendor/statsd/base.py b/vcsserver/lib/_vendor/statsd/base.py --- a/vcsserver/lib/_vendor/statsd/base.py +++ b/vcsserver/lib/_vendor/statsd/base.py @@ -14,6 +14,11 @@ TAG_INVALID_CHARS_RE = re.compile( ) TAG_INVALID_CHARS_SUBS = "_" +# we save and expose methods called by statsd for discovery +buckets_dict = { + +} + @lru_cache(maxsize=500) def _normalize_tags_with_cache(tag_list): @@ -42,7 +47,7 @@ class StatsClientBase(object): def timer(self, stat, rate=1, tags=None): return Timer(self, stat, rate, tags) - def timing(self, stat, delta, rate=1, tags=None): + def timing(self, stat, delta, rate=1, tags=None, use_decimals=True): """ Send new timing information. @@ -51,7 +56,11 @@ class StatsClientBase(object): if isinstance(delta, timedelta): # Convert timedelta to number of milliseconds. delta = delta.total_seconds() * 1000. - self._send_stat(stat, '%0.6f|ms' % delta, rate, tags) + if use_decimals: + fmt = '%0.6f|ms' + else: + fmt = '%s|ms' + self._send_stat(stat, fmt % delta, rate, tags) def incr(self, stat, count=1, rate=1, tags=None): """Increment a stat by `count`.""" @@ -78,10 +87,17 @@ class StatsClientBase(object): """Set a set value.""" self._send_stat(stat, '%s|s' % value, rate) + def histogram(self, stat, value, rate=1, tags=None): + """Set a histogram""" + self._send_stat(stat, '%s|h' % value, rate, tags) + def _send_stat(self, stat, value, rate, tags=None): self._after(self._prepare(stat, value, rate, tags)) def _prepare(self, stat, value, rate, tags=None): + global buckets_dict + buckets_dict[stat] = 1 + if rate < 1: if random.random() > rate: return diff --git a/vcsserver/tweens/request_wrapper.py b/vcsserver/tweens/request_wrapper.py --- a/vcsserver/tweens/request_wrapper.py +++ b/vcsserver/tweens/request_wrapper.py @@ -60,13 +60,22 @@ class RequestWrapperTween(object): statsd = request.registry.statsd if statsd: - elapsed_time_ms = 1000.0 * total + match_route = request.matched_route.name if request.matched_route else _path + resp_code = response.status_code + elapsed_time_ms = round(1000.0 * total) # use ms only statsd.timing( - 'vcsserver_req_timing', elapsed_time_ms, - tags=["path:{}".format(_path)] + "vcsserver_req_timing.histogram", elapsed_time_ms, + tags=[ + "view_name:{}".format(match_route), + "code:{}".format(resp_code) + ], + use_decimals=False ) statsd.incr( - 'vcsserver_req_total', tags=["path:{}".format(_path)]) + "vcsserver_req_total", tags=[ + "view_name:{}".format(match_route), + "code:{}".format(resp_code) + ]) return response