Skip to content

Commit

Permalink
Merge pull request #556 from EOxServer/prometheus-metrics
Browse files Browse the repository at this point in the history
Add support for prometheus metrics
  • Loading branch information
totycro committed Mar 30, 2023
2 parents 9ac6241 + ff6cf77 commit 4b57293
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.git
.venv
autotest
build
dist
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 . .
Expand Down
3 changes: 3 additions & 0 deletions autotest/autotest/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
]

MIDDLEWARE = [
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
Expand All @@ -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 = (
Expand Down Expand Up @@ -219,6 +221,7 @@
# Enable for better schema and data-migrations
# Enable for debugging
# 'django_extensions',
'django_prometheus',
# Enable EOxServer:
'eoxserver.core',
'eoxserver.services',
Expand Down
6 changes: 6 additions & 0 deletions autotest/autotest/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
3 changes: 3 additions & 0 deletions eoxserver/instance_template/project_name/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
]

MIDDLEWARE = [
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
Expand All @@ -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 = (
Expand Down Expand Up @@ -217,6 +219,7 @@
#'south',
# Enable for debugging
#'django_extensions',
'django_prometheus',
# Enable EOxServer:
'eoxserver.core',
'eoxserver.services',
Expand Down
6 changes: 6 additions & 0 deletions eoxserver/instance_template/project_name/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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",
),
]
6 changes: 6 additions & 0 deletions gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4b57293

Please sign in to comment.