Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from PascalEgn/add-metrics
Browse files Browse the repository at this point in the history
metrics: add prometheus endpoint
  • Loading branch information
drjova authored Nov 20, 2023
2 parents 3aacdd2 + ea1592c commit 6d621d2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
5 changes: 4 additions & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"ENGINE": "django_prometheus.db.backends.postgresql",
"NAME": env("POSTGRES_DB"),
"USER": env("POSTGRES_USER"),
"PASSWORD": env("POSTGRES_PASSWORD"),
Expand Down Expand Up @@ -97,6 +97,7 @@
"corsheaders",
"drf_spectacular",
"allauth.socialaccount.providers.orcid",
"django_prometheus",
]

LOCAL_APPS = ["backoffice.users", "backoffice.workflows", "backoffice.management"]
Expand Down Expand Up @@ -144,6 +145,7 @@
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#middleware
MIDDLEWARE = [
"django_prometheus.middleware.PrometheusBeforeMiddleware",
"django.middleware.security.SecurityMiddleware",
"corsheaders.middleware.CorsMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
Expand All @@ -155,6 +157,7 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"allauth.account.middleware.AccountMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django_prometheus.middleware.PrometheusAfterMiddleware",
]

# STATIC
Expand Down
4 changes: 3 additions & 1 deletion config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# ------------------------------------------------------------------------------
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"BACKEND": "django_prometheus.cache.backends.redis.RedisCache",
"LOCATION": env("REDIS_URL"),
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
Expand Down Expand Up @@ -55,6 +55,8 @@
SECURE_HSTS_PRELOAD = env.bool("DJANGO_SECURE_HSTS_PRELOAD", default=True)
# https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff
SECURE_CONTENT_TYPE_NOSNIFF = env.bool("DJANGO_SECURE_CONTENT_TYPE_NOSNIFF", default=True)
# Metrics endpoint needs to be http for prometheus to access it
SECURE_REDIRECT_EXEMPT = [r"^metrics$"]

# STORAGES
# ------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# User management
path("users/", include("backoffice.users.urls", namespace="users")),
path("accounts/", include("allauth.urls")),
path("", include("django_prometheus.urls")),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
if settings.DEBUG:
# Static file serving when using Gunicorn + Uvicorn for local web socket development
Expand Down
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ django-storages = {version = "1.14.2", extras = ["s3"]}
django-anymail = "10.1"
dj-database-url = "^2.1.0"
whitenoise = "^6.6.0"
django-prometheus = "^2.3.1"

[tool.poetry.dev-dependencies]
factory-boy = "3.3.0"
Expand Down

0 comments on commit 6d621d2

Please sign in to comment.