diff --git a/.dockerignore b/.dockerignore index 891d78f5a..5e37f5a31 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,5 @@ .git +.venv autotest build dist diff --git a/Dockerfile b/Dockerfile index a422d3ffb..39195c3ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,6 +37,9 @@ RUN apt-get update \ && apt-get clean \ && rm -rf /var/lib/apt/lists/partial/* /tmp/* /var/tmp/* +ENV PROMETHEUS_MULTIPROC_DIR /var/tmp/prometheus_multiproc_dir +RUN mkdir $PROMETHEUS_MULTIPROC_DIR # make sure this is writable by webserver user + RUN mkdir /opt/eoxserver/ WORKDIR /opt/eoxserver COPY . . diff --git a/autotest/autotest/settings.py b/autotest/autotest/settings.py index d7c8733ad..86f1d85a5 100644 --- a/autotest/autotest/settings.py +++ b/autotest/autotest/settings.py @@ -176,6 +176,7 @@ ] MIDDLEWARE = [ + 'django_prometheus.middleware.PrometheusBeforeMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -186,6 +187,7 @@ 'django.middleware.clickjacking.XFrameOptionsMiddleware', # # For management of the per/request cache system. # 'eoxserver.backends.middleware.BackendsCacheMiddleware', + 'django_prometheus.middleware.PrometheusAfterMiddleware' ] MIDDLEWARE_CLASSES = ( @@ -219,6 +221,7 @@ # Enable for better schema and data-migrations # Enable for debugging # 'django_extensions', + 'django_prometheus', # Enable EOxServer: 'eoxserver.core', 'eoxserver.services', diff --git a/autotest/autotest/urls.py b/autotest/autotest/urls.py index f63efe4f7..f6e3331af 100644 --- a/autotest/autotest/urls.py +++ b/autotest/autotest/urls.py @@ -6,6 +6,7 @@ from django.urls import include, re_path from django.contrib import admin from django.conf.urls.static import static +import django_prometheus.exports from eoxserver.services.opensearch.urls import urlpatterns as opensearch from eoxserver.webclient.urls import urlpatterns as webclient @@ -30,4 +31,9 @@ re_path(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Enable the admin: re_path(r'^admin/', admin.site.urls), + re_path( + r'^metrics$', + django_prometheus.exports.ExportToDjangoView, + name="prometheus-django-metrics", + ), ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) diff --git a/eoxserver/instance_template/project_name/settings.py b/eoxserver/instance_template/project_name/settings.py index f606a5a7b..dfd01fbbe 100644 --- a/eoxserver/instance_template/project_name/settings.py +++ b/eoxserver/instance_template/project_name/settings.py @@ -169,6 +169,7 @@ ] MIDDLEWARE = [ + 'django_prometheus.middleware.PrometheusBeforeMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -179,6 +180,7 @@ 'django.middleware.clickjacking.XFrameOptionsMiddleware', # # For management of the per/request cache system. # 'eoxserver.backends.middleware.BackendsCacheMiddleware', + 'django_prometheus.middleware.PrometheusAfterMiddleware', ] MIDDLEWARE_CLASSES = ( @@ -217,6 +219,7 @@ #'south', # Enable for debugging #'django_extensions', + 'django_prometheus', # Enable EOxServer: 'eoxserver.core', 'eoxserver.services', diff --git a/eoxserver/instance_template/project_name/urls.py b/eoxserver/instance_template/project_name/urls.py index d6a4967c2..87464a0c0 100644 --- a/eoxserver/instance_template/project_name/urls.py +++ b/eoxserver/instance_template/project_name/urls.py @@ -36,6 +36,7 @@ from django.urls import include, re_path from django.contrib import admin +import django_prometheus.exports from eoxserver.views import index @@ -58,4 +59,9 @@ re_path(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Enable the admin: re_path(r'^admin/', admin.site.urls), + re_path( + r'^metrics$', + django_prometheus.exports.ExportToDjangoView, + name="prometheus-django-metrics", + ), ] diff --git a/gunicorn.conf.py b/gunicorn.conf.py index c2f6ac844..65ef93020 100644 --- a/gunicorn.conf.py +++ b/gunicorn.conf.py @@ -1,9 +1,15 @@ import os import multiprocessing +from prometheus_client import multiprocess + chdir = os.environ.get('INSTANCE_DIR', '') bind = ':8000' workers = multiprocessing.cpu_count() * 2 + 1 worker_class = 'sync' timeout = 600 + + +def child_exit(server, worker): + multiprocess.mark_process_dead(worker.pid) diff --git a/setup.py b/setup.py index da3894e74..839b2975b 100644 --- a/setup.py +++ b/setup.py @@ -102,6 +102,7 @@ def fullsplit(path, result=None): "python-dateutil", "django-model-utils<5.0.0", "django-utils-six==2.0", + "django-prometheus", 'tzdata', "zipstream", "psycopg2",