feat(backend): added django_prometheus
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
DJANGO_SECRET_KEY=secretees
|
DJANGO_SECRET_KEY=very_insecure_key
|
||||||
DJANGO_DEBUG=False
|
DJANGO_DEBUG=False
|
||||||
DJANGO_ALLOWED_HOSTS=*
|
DJANGO_ALLOWED_HOSTS=*
|
||||||
DJANGO_CSRF_TRUSTED_ORIGINS=http://localhost,http://127.0.0.1
|
DJANGO_CSRF_TRUSTED_ORIGINS=http://localhost,http://127.0.0.1
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ REDIS_URI = env("REDIS_URI", default="redis://localhost:6379")
|
|||||||
|
|
||||||
CACHES = {
|
CACHES = {
|
||||||
"default": {
|
"default": {
|
||||||
"BACKEND": "django.core.cache.backends.redis.RedisCache",
|
"BACKEND": "django_prometheus.cache.backends.redis.RedisCache",
|
||||||
"LOCATION": REDIS_URI,
|
"LOCATION": REDIS_URI,
|
||||||
"TIMEOUT": None,
|
"TIMEOUT": None,
|
||||||
"KEY_PREFIX": "backend",
|
"KEY_PREFIX": "backend",
|
||||||
@@ -80,6 +80,9 @@ CELERY_TASK_TRACK_STARTED = True
|
|||||||
# Database
|
# Database
|
||||||
|
|
||||||
DB_URI = env.db_url("DJANGO_DB_URI", default="sqlite:///db.sqlite3")
|
DB_URI = env.db_url("DJANGO_DB_URI", default="sqlite:///db.sqlite3")
|
||||||
|
DB_URI["ENGINE"] = DB_URI["ENGINE"].replace(
|
||||||
|
"django.db.backends", "django_prometheus.db.backends"
|
||||||
|
)
|
||||||
|
|
||||||
DATABASES = {"default": {**DB_URI, "CONN_MAX_AGE": 50}}
|
DATABASES = {"default": {**DB_URI, "CONN_MAX_AGE": 50}}
|
||||||
|
|
||||||
@@ -284,12 +287,14 @@ INTERNAL_IPS = env(
|
|||||||
)
|
)
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
"django_prometheus.middleware.PrometheusBeforeMiddleware",
|
||||||
"django_guid.middleware.guid_middleware",
|
"django_guid.middleware.guid_middleware",
|
||||||
"corsheaders.middleware.CorsMiddleware",
|
"corsheaders.middleware.CorsMiddleware",
|
||||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||||
"django.middleware.csrf.CsrfViewMiddleware",
|
"django.middleware.csrf.CsrfViewMiddleware",
|
||||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||||
"django.contrib.messages.middleware.MessageMiddleware",
|
"django.contrib.messages.middleware.MessageMiddleware",
|
||||||
|
"django_prometheus.middleware.PrometheusAfterMiddleware",
|
||||||
]
|
]
|
||||||
|
|
||||||
SIGNING_BACKEND = "django.core.signing.TimestampSigner"
|
SIGNING_BACKEND = "django.core.signing.TimestampSigner"
|
||||||
@@ -442,6 +447,7 @@ INSTALLED_APPS = [
|
|||||||
"corsheaders",
|
"corsheaders",
|
||||||
"django_extensions",
|
"django_extensions",
|
||||||
"django_guid",
|
"django_guid",
|
||||||
|
"django_prometheus",
|
||||||
"ninja",
|
"ninja",
|
||||||
"minio_storage",
|
"minio_storage",
|
||||||
# Internal apps
|
# Internal apps
|
||||||
@@ -594,3 +600,27 @@ DEBUG_TOOLBAR_CONFIG = {"SHOW_COLLAPSED": True, "UPDATE_ON_FETCH": True}
|
|||||||
if DEBUG and DEBUG_TOOLBAR_ENABLED:
|
if DEBUG and DEBUG_TOOLBAR_ENABLED:
|
||||||
INSTALLED_APPS.append("debug_toolbar")
|
INSTALLED_APPS.append("debug_toolbar")
|
||||||
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
|
MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware")
|
||||||
|
|
||||||
|
|
||||||
|
# Prometheus
|
||||||
|
|
||||||
|
PROMETHEUS_LATENCY_BUCKETS = (
|
||||||
|
0.005,
|
||||||
|
0.01,
|
||||||
|
0.025,
|
||||||
|
0.05,
|
||||||
|
0.075,
|
||||||
|
0.1,
|
||||||
|
0.25,
|
||||||
|
0.5,
|
||||||
|
0.75,
|
||||||
|
1.0,
|
||||||
|
2.5,
|
||||||
|
5.0,
|
||||||
|
7.5,
|
||||||
|
10.0,
|
||||||
|
25.0,
|
||||||
|
50.0,
|
||||||
|
75.0,
|
||||||
|
float("inf"),
|
||||||
|
)
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ urlpatterns = [
|
|||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
# API urls
|
# API urls
|
||||||
path("", include("api.urls")),
|
path("", include("api.urls")),
|
||||||
|
# Prometheus urls
|
||||||
|
path("", include("django_prometheus.urls")),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ dependencies = [
|
|||||||
"django-health-check>=3.18.3,<4.0.0",
|
"django-health-check>=3.18.3,<4.0.0",
|
||||||
"django-minio-storage>=0.5.7,<0.6.0",
|
"django-minio-storage>=0.5.7,<0.6.0",
|
||||||
"django-ninja>=1.3.0,<2.0.0",
|
"django-ninja>=1.3.0,<2.0.0",
|
||||||
|
"django-prometheus>=2.4.1,<3.0.0",
|
||||||
|
"django-redis>=6.0.0,<7.0.0",
|
||||||
"django-stubs-ext>=5.1.3,<6.0.0",
|
"django-stubs-ext>=5.1.3,<6.0.0",
|
||||||
"gunicorn>=23.0.0,<24.0.0",
|
"gunicorn>=23.0.0,<24.0.0",
|
||||||
"httpx>=0.28.1,<0.29.0",
|
"httpx>=0.28.1,<0.29.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user