metrics: use prom metrics, and added some additional metrics

This commit is contained in:
RhodeCode Admin 2022-10-25 13:08:47 +02:00
parent de71212b00
commit bc8d59f1a7
8 changed files with 33 additions and 15 deletions

View file

@ -179,7 +179,7 @@ def exception_view(exc, request):
statsd = request.registry.statsd
if statsd:
statsd.incr('rhodecode_exception', tags=["api"])
statsd.incr('rhodecode_exception_total', tags=["exc_source:api"])
return jsonrpc_error(request, fault_message, rpc_id)
@ -296,9 +296,14 @@ def request_view(request):
# register some common functions for usage
attach_context_attributes(TemplateArgs(), request, request.rpc_user.user_id)
statsd = request.registry.statsd
try:
ret_value = func(**call_params)
return jsonrpc_response(request, ret_value)
resp = jsonrpc_response(request, ret_value)
if statsd:
statsd.incr('rhodecode_api_call_success_total')
return resp
except JSONRPCBaseError:
raise
except Exception:
@ -308,9 +313,12 @@ def request_view(request):
id(exc_info), exc_info, prefix='rhodecode-api')
error_headers = [('RhodeCode-Exception-Id', str(exc_id)),
('RhodeCode-Exception-Type', str(exc_type_name))]
return jsonrpc_error(
err_resp = jsonrpc_error(
request, retid=request.rpc_id, message='Internal server error',
headers=error_headers)
if statsd:
statsd.incr('rhodecode_api_call_fail_total')
return err_resp
def setup_request(request):

View file

@ -36,10 +36,10 @@ from pyramid.threadlocal import get_current_registry
from rhodecode.authentication.interface import IAuthnPluginRegistry
from rhodecode.authentication.schema import AuthnPluginSettingsSchemaBase
from rhodecode.lib import rc_cache
from rhodecode.lib.statsd_client import StatsdClient
from rhodecode.lib.auth import PasswordGenerator, _RhodeCodeCryptoBCrypt
from rhodecode.lib.utils2 import safe_int, safe_str
from rhodecode.lib.exceptions import LdapConnectionError, LdapUsernameError, \
LdapPasswordError
from rhodecode.lib.exceptions import (LdapConnectionError, LdapUsernameError, LdapPasswordError)
from rhodecode.model.db import User
from rhodecode.model.meta import Session
from rhodecode.model.settings import SettingsModel
@ -780,12 +780,19 @@ def authenticate(username, password, environ=None, auth_type=None,
log.debug('PLUGIN USER DATA: %s', plugin_user)
statsd = StatsdClient.statsd
if plugin_user:
log.debug('Plugin returned proper authentication data')
if statsd:
statsd.incr('rhodecode_login_success_total')
return plugin_user
# we failed to Auth because .auth() method didn't return proper user
log.debug("User `%s` failed to authenticate against %s",
display_user, plugin.get_id())
if statsd:
statsd.incr('rhodecode_login_fail_total')
# case when we failed to authenticate against all defined plugins
return None

View file

@ -182,7 +182,7 @@ def error_handler(exception, request):
statsd = request.registry.statsd
if statsd and base_response.status_code > 499:
statsd.incr('rhodecode_exception', tags=["code:{}".format(base_response.status_code)])
statsd.incr('rhodecode_exception_total', tags=["code:{}".format(base_response.status_code)])
error_explanation = base_response.explanation or str(base_response)
if base_response.status_code == 404:

View file

@ -74,7 +74,7 @@ def run_task(task, *args, **kwargs):
log.debug('executing task %s:%s in sync mode', 'TASK', task)
if statsd:
statsd.incr('rhodecode_celery_task', tags=[
statsd.incr('rhodecode_celery_task_total', tags=[
'task:{}'.format(task),
'mode:{}'.format(exec_mode)
])

View file

@ -179,7 +179,7 @@ def task_failure_signal(
store_exception(id(exc_info), exc_info, prefix='rhodecode-celery')
statsd = StatsdClient.statsd
if statsd:
statsd.incr('rhodecode_exception', tags=["celery"])
statsd.incr('rhodecode_exception_total', tags=["exc_source:celery"])
closer = celery_app.conf['PYRAMID_CLOSER']
if closer:

View file

@ -36,6 +36,7 @@ from rhodecode.lib import audit_logger
from rhodecode.lib.celerylib import get_logger, async_task, RequestContextTask, run_task
from rhodecode.lib import hooks_base
from rhodecode.lib.utils2 import safe_int, str2bool, aslist
from rhodecode.lib.statsd_client import StatsdClient
from rhodecode.model.db import (
Session, IntegrityError, true, Repository, RepoGroup, User)
from rhodecode.model.permission import PermissionModel
@ -130,6 +131,9 @@ def send_email(recipients, subject, body='', html_body='', email_config=None,
body=body, html=html_body,
extra_headers=extra_headers)
mailer.send_immediately(message)
statsd = StatsdClient.statsd
if statsd:
statsd.incr('rhodecode_email_sent_total')
except Exception:
log.exception('Mail sending failed')

View file

@ -222,7 +222,7 @@ def post_pull(extras):
statsd = StatsdClient.statsd
if statsd:
statsd.incr('rhodecode_pull')
statsd.incr('rhodecode_pull_total')
output = ''
# make lock is a tri state False, True, None. We only make lock on True
@ -271,7 +271,7 @@ def post_push(extras):
statsd = StatsdClient.statsd
if statsd:
statsd.incr('rhodecode_push')
statsd.incr('rhodecode_push_total')
# Propagate to external components.
output = ''

View file

@ -53,7 +53,7 @@ class RequestWrapperTween(object):
_ver_ = rhodecode.__version__
_path = safe_str(get_access_path(request.environ))
_auth_user = self._get_user_info(request)
user_id = getattr(_auth_user, 'user_id', _auth_user)
total = time.time() - start
log.info(
'Req[%4s] %s %s Request to %s time: %.4fs [%s], RhodeCode %s',
@ -64,19 +64,18 @@ class RequestWrapperTween(object):
statsd = request.registry.statsd
if statsd:
resp_code = response.status_code
user_id = getattr(_auth_user, 'user_id', _auth_user)
elapsed_time_ms = 1000.0 * total
statsd.timing(
'rhodecode_req_timing', elapsed_time_ms,
tags=[
#"path:{}".format(_path),
"view_name:{}".format(request.matched_route.name),
#"user:{}".format(user_id),
"code:{}".format(resp_code)
]
)
statsd.incr(
'rhodecode_req_count', tags=[
#"path:{}".format(_path),
'rhodecode_req_count_total', tags=[
"view_name:{}".format(request.matched_route.name),
#"user:{}".format(user_id),
"code:{}".format(resp_code)
])