Show More
@@ -135,10 +135,10 b' def make_pyramid_app(global_config, **se' | |||
|
135 | 135 | log.info('Pyramid app `%s` created and configured in %.2fs', |
|
136 | 136 | pyramid_app.func_name, total_time) |
|
137 | 137 | if statsd: |
|
138 | elapsed_time_ms = 1000.0 * total_time | |
|
138 | elapsed_time_ms = round(1000.0 * total_time) # use ms only rounded time | |
|
139 | 139 | statsd.timing('rhodecode_app_bootstrap_timing', elapsed_time_ms, tags=[ |
|
140 | 140 | "pyramid_app:{}".format(pyramid_app.func_name) |
|
141 | ]) | |
|
141 | ], use_decimals=False) | |
|
142 | 142 | return pyramid_app |
|
143 | 143 | |
|
144 | 144 |
@@ -14,6 +14,12 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 | stat_dict = { | |
|
19 | ||
|
20 | } | |
|
21 | ||
|
22 | ||
|
17 | 23 | |
|
18 | 24 | @lru_cache(maxsize=500) |
|
19 | 25 | def _normalize_tags_with_cache(tag_list): |
@@ -42,7 +48,7 b' class StatsClientBase(object):' | |||
|
42 | 48 | def timer(self, stat, rate=1, tags=None): |
|
43 | 49 | return Timer(self, stat, rate, tags) |
|
44 | 50 | |
|
45 | def timing(self, stat, delta, rate=1, tags=None): | |
|
51 | def timing(self, stat, delta, rate=1, tags=None, use_decimals=True): | |
|
46 | 52 | """ |
|
47 | 53 | Send new timing information. |
|
48 | 54 | |
@@ -51,7 +57,11 b' class StatsClientBase(object):' | |||
|
51 | 57 | if isinstance(delta, timedelta): |
|
52 | 58 | # Convert timedelta to number of milliseconds. |
|
53 | 59 | delta = delta.total_seconds() * 1000. |
|
54 | self._send_stat(stat, '%0.6f|ms' % delta, rate, tags) | |
|
60 | if use_decimals: | |
|
61 | fmt = '%0.6f|ms' | |
|
62 | else: | |
|
63 | fmt = '%s|ms' | |
|
64 | self._send_stat(stat, fmt % delta, rate, tags) | |
|
55 | 65 | |
|
56 | 66 | def incr(self, stat, count=1, rate=1, tags=None): |
|
57 | 67 | """Increment a stat by `count`.""" |
@@ -78,10 +88,17 b' class StatsClientBase(object):' | |||
|
78 | 88 | """Set a set value.""" |
|
79 | 89 | self._send_stat(stat, '%s|s' % value, rate) |
|
80 | 90 | |
|
91 | def histogram(self, stat, value, rate=1, tags=None): | |
|
92 | """Set a histogram""" | |
|
93 | self._send_stat(stat, '%s|h' % value, rate, tags) | |
|
94 | ||
|
81 | 95 | def _send_stat(self, stat, value, rate, tags=None): |
|
82 | 96 | self._after(self._prepare(stat, value, rate, tags)) |
|
83 | 97 | |
|
84 | 98 | def _prepare(self, stat, value, rate, tags=None): |
|
99 | global stat_dict | |
|
100 | stat_dict[stat] = 1 | |
|
101 | ||
|
85 | 102 | if rate < 1: |
|
86 | 103 | if random.random() > rate: |
|
87 | 104 | return |
@@ -21,7 +21,7 b' def safe_wraps(wrapper, *args, **kwargs)' | |||
|
21 | 21 | class Timer(object): |
|
22 | 22 | """A context manager/decorator for statsd.timing().""" |
|
23 | 23 | |
|
24 | def __init__(self, client, stat, rate=1, tags=None): | |
|
24 | def __init__(self, client, stat, rate=1, tags=None, use_decimals=True): | |
|
25 | 25 | self.client = client |
|
26 | 26 | self.stat = stat |
|
27 | 27 | self.rate = rate |
@@ -29,6 +29,7 b' class Timer(object):' | |||
|
29 | 29 | self.ms = None |
|
30 | 30 | self._sent = False |
|
31 | 31 | self._start_time = None |
|
32 | self.use_decimals = use_decimals | |
|
32 | 33 | |
|
33 | 34 | def __call__(self, f): |
|
34 | 35 | """Thread-safe timing function decorator.""" |
@@ -39,7 +40,7 b' class Timer(object):' | |||
|
39 | 40 | return f(*args, **kwargs) |
|
40 | 41 | finally: |
|
41 | 42 | elapsed_time_ms = 1000.0 * (time_now() - start_time) |
|
42 | self.client.timing(self.stat, elapsed_time_ms, self.rate, self.tags) | |
|
43 | self.client.timing(self.stat, elapsed_time_ms, self.rate, self.tags, self.use_decimals) | |
|
43 | 44 | return _wrapped |
|
44 | 45 | |
|
45 | 46 | def __enter__(self): |
@@ -69,4 +70,4 b' class Timer(object):' | |||
|
69 | 70 | if self._sent: |
|
70 | 71 | raise RuntimeError('Already sent data.') |
|
71 | 72 | self._sent = True |
|
72 | self.client.timing(self.stat, self.ms, self.rate) | |
|
73 | self.client.timing(self.stat, self.ms, self.rate, self.tags, self.use_decimals) |
@@ -65,14 +65,15 b' class RequestWrapperTween(object):' | |||
|
65 | 65 | if statsd: |
|
66 | 66 | match_route = request.matched_route.name if request.matched_route else _path |
|
67 | 67 | resp_code = response.status_code |
|
68 | elapsed_time_ms = 1000.0 * total | |
|
68 | elapsed_time_ms = round(1000.0 * total) # use ms only | |
|
69 | 69 | statsd.timing( |
|
70 | 70 | 'rhodecode_req_timing', elapsed_time_ms, |
|
71 | 71 | tags=[ |
|
72 | 72 | "view_name:{}".format(match_route), |
|
73 | 73 | #"user:{}".format(user_id), |
|
74 | 74 | "code:{}".format(resp_code) |
|
75 | ] | |
|
75 | ], | |
|
76 | use_decimals=False | |
|
76 | 77 | ) |
|
77 | 78 | statsd.incr( |
|
78 | 79 | 'rhodecode_req_total', tags=[ |
General Comments 0
You need to be logged in to leave comments.
Login now