##// END OF EJS Templates
metrics: use prom metrics, and added some additional metrics
super-admin -
r4803:4c2bed55 default
parent child Browse files
Show More
@@ -179,7 +179,7 b' def exception_view(exc, request):'
179
179
180 statsd = request.registry.statsd
180 statsd = request.registry.statsd
181 if statsd:
181 if statsd:
182 statsd.incr('rhodecode_exception', tags=["api"])
182 statsd.incr('rhodecode_exception_total', tags=["exc_source:api"])
183
183
184 return jsonrpc_error(request, fault_message, rpc_id)
184 return jsonrpc_error(request, fault_message, rpc_id)
185
185
@@ -296,9 +296,14 b' def request_view(request):'
296 # register some common functions for usage
296 # register some common functions for usage
297 attach_context_attributes(TemplateArgs(), request, request.rpc_user.user_id)
297 attach_context_attributes(TemplateArgs(), request, request.rpc_user.user_id)
298
298
299 statsd = request.registry.statsd
300
299 try:
301 try:
300 ret_value = func(**call_params)
302 ret_value = func(**call_params)
301 return jsonrpc_response(request, ret_value)
303 resp = jsonrpc_response(request, ret_value)
304 if statsd:
305 statsd.incr('rhodecode_api_call_success_total')
306 return resp
302 except JSONRPCBaseError:
307 except JSONRPCBaseError:
303 raise
308 raise
304 except Exception:
309 except Exception:
@@ -308,9 +313,12 b' def request_view(request):'
308 id(exc_info), exc_info, prefix='rhodecode-api')
313 id(exc_info), exc_info, prefix='rhodecode-api')
309 error_headers = [('RhodeCode-Exception-Id', str(exc_id)),
314 error_headers = [('RhodeCode-Exception-Id', str(exc_id)),
310 ('RhodeCode-Exception-Type', str(exc_type_name))]
315 ('RhodeCode-Exception-Type', str(exc_type_name))]
311 return jsonrpc_error(
316 err_resp = jsonrpc_error(
312 request, retid=request.rpc_id, message='Internal server error',
317 request, retid=request.rpc_id, message='Internal server error',
313 headers=error_headers)
318 headers=error_headers)
319 if statsd:
320 statsd.incr('rhodecode_api_call_fail_total')
321 return err_resp
314
322
315
323
316 def setup_request(request):
324 def setup_request(request):
@@ -36,10 +36,10 b' from pyramid.threadlocal import get_curr'
36 from rhodecode.authentication.interface import IAuthnPluginRegistry
36 from rhodecode.authentication.interface import IAuthnPluginRegistry
37 from rhodecode.authentication.schema import AuthnPluginSettingsSchemaBase
37 from rhodecode.authentication.schema import AuthnPluginSettingsSchemaBase
38 from rhodecode.lib import rc_cache
38 from rhodecode.lib import rc_cache
39 from rhodecode.lib.statsd_client import StatsdClient
39 from rhodecode.lib.auth import PasswordGenerator, _RhodeCodeCryptoBCrypt
40 from rhodecode.lib.auth import PasswordGenerator, _RhodeCodeCryptoBCrypt
40 from rhodecode.lib.utils2 import safe_int, safe_str
41 from rhodecode.lib.utils2 import safe_int, safe_str
41 from rhodecode.lib.exceptions import LdapConnectionError, LdapUsernameError, \
42 from rhodecode.lib.exceptions import (LdapConnectionError, LdapUsernameError, LdapPasswordError)
42 LdapPasswordError
43 from rhodecode.model.db import User
43 from rhodecode.model.db import User
44 from rhodecode.model.meta import Session
44 from rhodecode.model.meta import Session
45 from rhodecode.model.settings import SettingsModel
45 from rhodecode.model.settings import SettingsModel
@@ -780,12 +780,19 b' def authenticate(username, password, env'
780
780
781 log.debug('PLUGIN USER DATA: %s', plugin_user)
781 log.debug('PLUGIN USER DATA: %s', plugin_user)
782
782
783 statsd = StatsdClient.statsd
784
783 if plugin_user:
785 if plugin_user:
784 log.debug('Plugin returned proper authentication data')
786 log.debug('Plugin returned proper authentication data')
787 if statsd:
788 statsd.incr('rhodecode_login_success_total')
785 return plugin_user
789 return plugin_user
790
786 # we failed to Auth because .auth() method didn't return proper user
791 # we failed to Auth because .auth() method didn't return proper user
787 log.debug("User `%s` failed to authenticate against %s",
792 log.debug("User `%s` failed to authenticate against %s",
788 display_user, plugin.get_id())
793 display_user, plugin.get_id())
794 if statsd:
795 statsd.incr('rhodecode_login_fail_total')
789
796
790 # case when we failed to authenticate against all defined plugins
797 # case when we failed to authenticate against all defined plugins
791 return None
798 return None
@@ -182,7 +182,7 b' def error_handler(exception, request):'
182
182
183 statsd = request.registry.statsd
183 statsd = request.registry.statsd
184 if statsd and base_response.status_code > 499:
184 if statsd and base_response.status_code > 499:
185 statsd.incr('rhodecode_exception', tags=["code:{}".format(base_response.status_code)])
185 statsd.incr('rhodecode_exception_total', tags=["code:{}".format(base_response.status_code)])
186
186
187 error_explanation = base_response.explanation or str(base_response)
187 error_explanation = base_response.explanation or str(base_response)
188 if base_response.status_code == 404:
188 if base_response.status_code == 404:
@@ -74,7 +74,7 b' def run_task(task, *args, **kwargs):'
74 log.debug('executing task %s:%s in sync mode', 'TASK', task)
74 log.debug('executing task %s:%s in sync mode', 'TASK', task)
75
75
76 if statsd:
76 if statsd:
77 statsd.incr('rhodecode_celery_task', tags=[
77 statsd.incr('rhodecode_celery_task_total', tags=[
78 'task:{}'.format(task),
78 'task:{}'.format(task),
79 'mode:{}'.format(exec_mode)
79 'mode:{}'.format(exec_mode)
80 ])
80 ])
@@ -179,7 +179,7 b' def task_failure_signal('
179 store_exception(id(exc_info), exc_info, prefix='rhodecode-celery')
179 store_exception(id(exc_info), exc_info, prefix='rhodecode-celery')
180 statsd = StatsdClient.statsd
180 statsd = StatsdClient.statsd
181 if statsd:
181 if statsd:
182 statsd.incr('rhodecode_exception', tags=["celery"])
182 statsd.incr('rhodecode_exception_total', tags=["exc_source:celery"])
183
183
184 closer = celery_app.conf['PYRAMID_CLOSER']
184 closer = celery_app.conf['PYRAMID_CLOSER']
185 if closer:
185 if closer:
@@ -36,6 +36,7 b' from rhodecode.lib import audit_logger'
36 from rhodecode.lib.celerylib import get_logger, async_task, RequestContextTask, run_task
36 from rhodecode.lib.celerylib import get_logger, async_task, RequestContextTask, run_task
37 from rhodecode.lib import hooks_base
37 from rhodecode.lib import hooks_base
38 from rhodecode.lib.utils2 import safe_int, str2bool, aslist
38 from rhodecode.lib.utils2 import safe_int, str2bool, aslist
39 from rhodecode.lib.statsd_client import StatsdClient
39 from rhodecode.model.db import (
40 from rhodecode.model.db import (
40 Session, IntegrityError, true, Repository, RepoGroup, User)
41 Session, IntegrityError, true, Repository, RepoGroup, User)
41 from rhodecode.model.permission import PermissionModel
42 from rhodecode.model.permission import PermissionModel
@@ -130,6 +131,9 b' def send_email(recipients, subject, body'
130 body=body, html=html_body,
131 body=body, html=html_body,
131 extra_headers=extra_headers)
132 extra_headers=extra_headers)
132 mailer.send_immediately(message)
133 mailer.send_immediately(message)
134 statsd = StatsdClient.statsd
135 if statsd:
136 statsd.incr('rhodecode_email_sent_total')
133
137
134 except Exception:
138 except Exception:
135 log.exception('Mail sending failed')
139 log.exception('Mail sending failed')
@@ -222,7 +222,7 b' def post_pull(extras):'
222
222
223 statsd = StatsdClient.statsd
223 statsd = StatsdClient.statsd
224 if statsd:
224 if statsd:
225 statsd.incr('rhodecode_pull')
225 statsd.incr('rhodecode_pull_total')
226
226
227 output = ''
227 output = ''
228 # make lock is a tri state False, True, None. We only make lock on True
228 # make lock is a tri state False, True, None. We only make lock on True
@@ -271,7 +271,7 b' def post_push(extras):'
271
271
272 statsd = StatsdClient.statsd
272 statsd = StatsdClient.statsd
273 if statsd:
273 if statsd:
274 statsd.incr('rhodecode_push')
274 statsd.incr('rhodecode_push_total')
275
275
276 # Propagate to external components.
276 # Propagate to external components.
277 output = ''
277 output = ''
@@ -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
56 user_id = getattr(_auth_user, 'user_id', _auth_user)
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',
@@ -64,19 +64,18 b' class RequestWrapperTween(object):'
64 statsd = request.registry.statsd
64 statsd = request.registry.statsd
65 if statsd:
65 if statsd:
66 resp_code = response.status_code
66 resp_code = response.status_code
67 user_id = getattr(_auth_user, 'user_id', _auth_user)
68 elapsed_time_ms = 1000.0 * total
67 elapsed_time_ms = 1000.0 * total
69 statsd.timing(
68 statsd.timing(
70 'rhodecode_req_timing', elapsed_time_ms,
69 'rhodecode_req_timing', elapsed_time_ms,
71 tags=[
70 tags=[
72 #"path:{}".format(_path),
71 "view_name:{}".format(request.matched_route.name),
73 #"user:{}".format(user_id),
72 #"user:{}".format(user_id),
74 "code:{}".format(resp_code)
73 "code:{}".format(resp_code)
75 ]
74 ]
76 )
75 )
77 statsd.incr(
76 statsd.incr(
78 'rhodecode_req_count', tags=[
77 'rhodecode_req_count_total', tags=[
79 #"path:{}".format(_path),
78 "view_name:{}".format(request.matched_route.name),
80 #"user:{}".format(user_id),
79 #"user:{}".format(user_id),
81 "code:{}".format(resp_code)
80 "code:{}".format(resp_code)
82 ])
81 ])
General Comments 0
You need to be logged in to leave comments. Login now