prometheus basics and aws fix

This commit is contained in:
vabene1111 2021-06-05 14:41:32 +02:00
parent 8181a6d416
commit c83eb1a42b
4 changed files with 20 additions and 2 deletions

View File

@ -57,8 +57,9 @@ GUNICORN_MEDIA=0
# S3_ACCESS_KEY=
# S3_SECRET_ACCESS_KEY=
# S3_BUCKET_NAME=
# S3_REGION_NAME= # default none, set your region might be required
# S3_QUERYSTRING_AUTH=1 # default true, set to 0 to serve media from a public bucket without signed urls
# AWS_QUERYSTRING_EXPIRE=3600 # number of seconds querystring are valid for
# S3_QUERYSTRING_EXPIRE=3600 # number of seconds querystring are valid for
# S3_ENDPOINT_URL= # when using a custom endpoint like minio
# Email Settings, see https://docs.djangoproject.com/en/3.2/ref/settings/#email-host
@ -86,6 +87,11 @@ REVERSE_PROXY_AUTH=0
# when unset: 0 (false)
# ENABLE_SIGNUP=0
# enable serving of prometheus metrics under the /metrics path
# ATTENTION: view is not secured (as per the prometheus default way) so make sure to secure it
# trough your web server (or leave it open of you dont care if the stats are exposed)
# ENABLE_METRICS=0
# allows you to setup OAuth providers
# see docs for more information https://vabene1111.github.io/recipes/features/authentication/
# SOCIAL_PROVIDERS = allauth.socialaccount.providers.github, allauth.socialaccount.providers.nextcloud,

View File

@ -81,6 +81,7 @@ INSTALLED_APPS = [
'django.contrib.sites',
'django.contrib.staticfiles',
'django.contrib.postgres',
'django_prometheus',
'django_tables2',
'corsheaders',
'django_filters',
@ -105,6 +106,8 @@ SOCIALACCOUNT_PROVIDERS = ast.literal_eval(
ENABLE_SIGNUP = bool(int(os.getenv('ENABLE_SIGNUP', False)))
ENABLE_METRICS = bool(int(os.getenv('ENABLE_METRICS', False)))
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
@ -119,6 +122,9 @@ MIDDLEWARE = [
'cookbook.helper.scope_middleware.ScopeMiddleware',
]
if ENABLE_METRICS:
MIDDLEWARE += 'django_prometheus.middleware.PrometheusAfterMiddleware',
# Auth related settings
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
@ -308,6 +314,7 @@ if os.getenv('S3_ACCESS_KEY', ''):
AWS_QUERYSTRING_AUTH = bool(int(os.getenv('S3_QUERYSTRING_AUTH', True)))
AWS_QUERYSTRING_EXPIRE = int(os.getenv('S3_QUERYSTRING_EXPIRE', 3600))
AWS_S3_SIGNATURE_VERSION = os.getenv('S3_SIGNATURE_VERSION', 's3v4')
AWS_S3_REGION_NAME = os.getenv('S3_REGION_NAME', None)
if os.getenv('S3_ENDPOINT_URL', ''):
AWS_S3_ENDPOINT_URL = os.getenv('S3_ENDPOINT_URL', '')

View File

@ -15,6 +15,7 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls import url
from django.contrib import admin
from django.urls import include, path, re_path
from django.views.i18n import JavaScriptCatalog
@ -33,6 +34,9 @@ urlpatterns = [
),
]
if settings.ENABLE_METRICS:
urlpatterns += url('', include('django_prometheus.urls')),
if settings.GUNICORN_MEDIA or settings.DEBUG:
urlpatterns += re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}),
urlpatterns += re_path(r'^jsreverse.json$', reverse_views.urls_js, name='js_reverse'),

View File

@ -37,4 +37,5 @@ pytest==6.2.4
pytest-django==4.3.0
django-cors-headers==3.7.0
django-storages==1.11.1
boto3==1.17.84
boto3==1.17.84
django-prometheus==2.1.0