##// END OF EJS Templates
metrics: fixed celery task names, fixed hiistogram type metrics, client small fixes
super-admin -
r4807:1bd9683a default
parent child Browse files
Show More
@@ -15,12 +15,11 b' TAG_INVALID_CHARS_RE = re.compile('
15 TAG_INVALID_CHARS_SUBS = "_"
15 TAG_INVALID_CHARS_SUBS = "_"
16
16
17 # we save and expose methods called by statsd for discovery
17 # we save and expose methods called by statsd for discovery
18 stat_dict = {
18 buckets_dict = {
19
19
20 }
20 }
21
21
22
22
23
24 @lru_cache(maxsize=500)
23 @lru_cache(maxsize=500)
25 def _normalize_tags_with_cache(tag_list):
24 def _normalize_tags_with_cache(tag_list):
26 return [TAG_INVALID_CHARS_RE.sub(TAG_INVALID_CHARS_SUBS, tag) for tag in tag_list]
25 return [TAG_INVALID_CHARS_RE.sub(TAG_INVALID_CHARS_SUBS, tag) for tag in tag_list]
@@ -96,8 +95,8 b' class StatsClientBase(object):'
96 self._after(self._prepare(stat, value, rate, tags))
95 self._after(self._prepare(stat, value, rate, tags))
97
96
98 def _prepare(self, stat, value, rate, tags=None):
97 def _prepare(self, stat, value, rate, tags=None):
99 global stat_dict
98 global buckets_dict
100 stat_dict[stat] = 1
99 buckets_dict[stat] = 1
101
100
102 if rate < 1:
101 if rate < 1:
103 if random.random() > rate:
102 if random.random() > rate:
@@ -47,17 +47,14 b' def run_task(task, *args, **kwargs):'
47 if task is None:
47 if task is None:
48 raise ValueError('Got non-existing task for execution')
48 raise ValueError('Got non-existing task for execution')
49
49
50 statsd = StatsdClient.statsd
51 exec_mode = 'sync'
50 exec_mode = 'sync'
52
51
53 if rhodecode.CELERY_ENABLED:
52 if rhodecode.CELERY_ENABLED:
54
53 t = None
55 try:
54 try:
56 t = task.apply_async(args=args, kwargs=kwargs)
55 t = task.apply_async(args=args, kwargs=kwargs)
57 log.debug('executing task %s:%s in async mode', t.task_id, task)
56 log.debug('executing task %s:%s in async mode', t.task_id, task)
58 exec_mode = 'async'
57 exec_mode = 'async'
59 return t
60
61 except socket.error as e:
58 except socket.error as e:
62 if isinstance(e, IOError) and e.errno == 111:
59 if isinstance(e, IOError) and e.errno == 111:
63 log.error('Unable to connect to celeryd `%s`. Sync execution', e)
60 log.error('Unable to connect to celeryd `%s`. Sync execution', e)
@@ -73,9 +70,15 b' def run_task(task, *args, **kwargs):'
73 else:
70 else:
74 log.debug('executing task %s:%s in sync mode', 'TASK', task)
71 log.debug('executing task %s:%s in sync mode', 'TASK', task)
75
72
73 statsd = StatsdClient.statsd
76 if statsd:
74 if statsd:
75 task_repr = getattr(task, 'name', task)
77 statsd.incr('rhodecode_celery_task_total', tags=[
76 statsd.incr('rhodecode_celery_task_total', tags=[
78 'task:{}'.format(task),
77 'task:{}'.format(task_repr),
79 'mode:{}'.format(exec_mode)
78 'mode:{}'.format(exec_mode)
80 ])
79 ])
80
81 # we got async task, return it after statsd call
82 if t:
83 return t
81 return ResultWrapper(task(*args, **kwargs))
84 return ResultWrapper(task(*args, **kwargs))
@@ -53,7 +53,7 b' class RequestWrapperTween(object):'
53 _ver_ = rhodecode.__version__
53 _ver_ = rhodecode.__version__
54 _path = safe_str(get_access_path(request.environ))
54 _path = safe_str(get_access_path(request.environ))
55 _auth_user = self._get_user_info(request)
55 _auth_user = self._get_user_info(request)
56 user_id = getattr(_auth_user, 'user_id', _auth_user)
56
57 total = time.time() - start
57 total = time.time() - start
58 log.info(
58 log.info(
59 'Req[%4s] %s %s Request to %s time: %.4fs [%s], RhodeCode %s',
59 'Req[%4s] %s %s Request to %s time: %.4fs [%s], RhodeCode %s',
@@ -67,10 +67,9 b' class RequestWrapperTween(object):'
67 resp_code = response.status_code
67 resp_code = response.status_code
68 elapsed_time_ms = round(1000.0 * total) # use ms only
68 elapsed_time_ms = round(1000.0 * total) # use ms only
69 statsd.timing(
69 statsd.timing(
70 'rhodecode_req_timing', elapsed_time_ms,
70 "rhodecode_req_timing.histogram", elapsed_time_ms,
71 tags=[
71 tags=[
72 "view_name:{}".format(match_route),
72 "view_name:{}".format(match_route),
73 #"user:{}".format(user_id),
74 "code:{}".format(resp_code)
73 "code:{}".format(resp_code)
75 ],
74 ],
76 use_decimals=False
75 use_decimals=False
@@ -78,7 +77,6 b' class RequestWrapperTween(object):'
78 statsd.incr(
77 statsd.incr(
79 'rhodecode_req_total', tags=[
78 'rhodecode_req_total', tags=[
80 "view_name:{}".format(match_route),
79 "view_name:{}".format(match_route),
81 #"user:{}".format(user_id),
82 "code:{}".format(resp_code)
80 "code:{}".format(resp_code)
83 ])
81 ])
84
82
General Comments 0
You need to be logged in to leave comments. Login now