misc: remove support for publishing prometheus metrics (#79709)
gitea/hobo/pipeline/head Build queued...
Details
gitea/hobo/pipeline/head Build queued...
Details
This commit is contained in:
parent
d9d6bb4e1d
commit
60434dc39d
|
@ -19,7 +19,6 @@ Depends: python3-apt,
|
|||
python3-dnspython,
|
||||
python3-memcache,
|
||||
python3-num2words,
|
||||
python3-prometheus-client,
|
||||
python3-publik-django-templatetags,
|
||||
python3-requests,
|
||||
python3-systemd,
|
||||
|
|
|
@ -382,8 +382,6 @@ MIDDLEWARE = (
|
|||
'hobo.middleware.xforwardedfor.XForwardedForMiddleware',
|
||||
) + MIDDLEWARE
|
||||
|
||||
MIDDLEWARE = MIDDLEWARE + ('hobo.middleware.PrometheusStatsMiddleware',)
|
||||
|
||||
|
||||
HOBO_MANAGER_HOMEPAGE_URL_VAR = 'portal_agent_url'
|
||||
HOBO_MANAGER_HOMEPAGE_TITLE_VAR = 'portal_agent_title'
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from .cookies_samesite import CookiesSameSiteFixMiddleware
|
||||
from .cors import CORSMiddleware
|
||||
from .seo import RobotsTxtMiddleware
|
||||
from .stats import PrometheusStatsMiddleware
|
||||
from .version import VersionMiddleware
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
# hobo - portal to configure and deploy applications
|
||||
# Copyright (C) 2017 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import inspect
|
||||
import time
|
||||
|
||||
import django
|
||||
import prometheus_client
|
||||
from django.db import connection
|
||||
from django.http import HttpResponse
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
|
||||
requests_total_by_host_view_status_method = prometheus_client.Counter(
|
||||
'django_http_requests_total_by_host_view_status_method',
|
||||
'Count of requests by host, view, status, method.',
|
||||
['host', 'view', 'status', 'method'],
|
||||
)
|
||||
|
||||
requests_bytes_by_host_view_status_method = prometheus_client.Summary(
|
||||
'django_http_requests_bytes_by_host_view_status_method',
|
||||
'Bytes of requests by host, view, status, method.',
|
||||
['host', 'view', 'status', 'method'],
|
||||
)
|
||||
|
||||
requests_times_by_host_view_status_method = prometheus_client.Summary(
|
||||
'django_http_requests_times_by_host_view_status_method',
|
||||
'Duration of requests by host, view, status, method.',
|
||||
['host', 'view', 'status', 'method'],
|
||||
)
|
||||
|
||||
requests_queries_count_by_host_view_status_method = prometheus_client.Summary(
|
||||
'django_http_requests_queries_count_by_host_view_status_method',
|
||||
'Query count by host, view, status, method.',
|
||||
['host', 'view', 'status', 'method'],
|
||||
)
|
||||
|
||||
requests_queries_time_by_host_view_status_method = prometheus_client.Summary(
|
||||
'django_http_requests_queries_time_by_host_view_status_method',
|
||||
'Query time by host, view, status, method.',
|
||||
['host', 'view', 'status', 'method'],
|
||||
)
|
||||
|
||||
|
||||
class PrometheusStatsMiddleware(MiddlewareMixin):
|
||||
def process_request(self, request):
|
||||
if request.method == 'GET' and request.path == '/__metrics__/':
|
||||
return HttpResponse(
|
||||
prometheus_client.generate_latest(), content_type=prometheus_client.CONTENT_TYPE_LATEST
|
||||
)
|
||||
|
||||
connection.force_debug_cursor = True # to count queries
|
||||
request._stats_t0 = time.time()
|
||||
return None
|
||||
|
||||
def process_view(self, request, view_func, view_args, view_kwargs):
|
||||
view = view_func
|
||||
if not inspect.isfunction(view_func):
|
||||
view = view.__class__
|
||||
try:
|
||||
request._view_name = '%s.%s' % (view.__module__, view.__name__)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
def process_response(self, request, response):
|
||||
if not hasattr(request, '_stats_t0'):
|
||||
return response
|
||||
http_method = request.method
|
||||
host_name = request.get_host()
|
||||
total_time = time.time() - request._stats_t0
|
||||
|
||||
status_code = response.status_code
|
||||
view_name = getattr(request, '_view_name', '<unnamed view>')
|
||||
requests_total_by_host_view_status_method.labels(host_name, view_name, status_code, http_method).inc()
|
||||
|
||||
if hasattr(response, 'content'):
|
||||
response_size = len(response.content)
|
||||
requests_bytes_by_host_view_status_method.labels(
|
||||
host_name, view_name, status_code, http_method
|
||||
).observe(response_size)
|
||||
|
||||
requests_times_by_host_view_status_method.labels(
|
||||
host_name, view_name, status_code, http_method
|
||||
).observe(total_time)
|
||||
|
||||
if connection.queries_logged:
|
||||
sql_queries_count = len(connection.queries)
|
||||
sql_queries_time = sum(float(x['time']) for x in connection.queries)
|
||||
requests_queries_count_by_host_view_status_method.labels(
|
||||
host_name, view_name, status_code, http_method
|
||||
).observe(sql_queries_count)
|
||||
requests_queries_time_by_host_view_status_method.labels(
|
||||
host_name, view_name, status_code, http_method
|
||||
).observe(sql_queries_time)
|
||||
|
||||
return response
|
|
@ -3,4 +3,3 @@ django>=1.11,<1.12
|
|||
celery<4
|
||||
django-mellon
|
||||
lxml
|
||||
prometheus_client
|
||||
|
|
Loading…
Reference in New Issue