Skip to content

Commit 126ac7d

Browse files
authored
To implement Prometheus metrics server for monitoring Django Server (#46)
* for implementing aap 8046 * update n rebase * update n rebase * fix bad request issue * remove prometheus monitoring * add grafana container
1 parent 4ef8fd3 commit 126ac7d

File tree

8 files changed

+46
-1
lines changed

8 files changed

+46
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ To get an authentication token without logging in via GitHub, you can navigate t
149149

150150
To test the API with no authentication, you can empty out REST_FRAMEWORK.DEFAULT_PERMISSION_CLASSES in base.py.
151151

152+
## Application metrics as a Prometheus-style endpoint
153+
154+
We enabled the Prometheus endpoint to scrape the configuration and check the service status to build observability into the Wisdom service for monitoring and measuring its availability.
155+
156+
To provide feedback for operational needs as well as for continuous service improvement.
157+
152158
## Test cases
153159

154160
Work in progress

ansible_wisdom/main/settings/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@
3838
"social_django",
3939
"users",
4040
"ai",
41+
"django_prometheus",
4142
]
4243

4344
MIDDLEWARE = [
45+
"django_prometheus.middleware.PrometheusBeforeMiddleware",
4446
"django.middleware.security.SecurityMiddleware",
4547
"django.contrib.sessions.middleware.SessionMiddleware",
4648
"django.middleware.common.CommonMiddleware",
@@ -49,6 +51,7 @@
4951
"django.contrib.messages.middleware.MessageMiddleware",
5052
"django.middleware.clickjacking.XFrameOptionsMiddleware",
5153
"social_django.middleware.SocialAuthExceptionMiddleware",
54+
"django_prometheus.middleware.PrometheusAfterMiddleware",
5255
]
5356

5457
AUTHENTICATION_BACKENDS = [

ansible_wisdom/main/settings/development.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
SECRET_KEY = os.environ["SECRET_KEY"]
77

8-
ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1"]
8+
ALLOWED_HOSTS = ["*"]
99

1010
ANSIBLE_AI_MODEL_NAME = "wisdom"
1111
ANSIBLE_AI_MODEL_MESH_HOST = os.getenv(

ansible_wisdom/main/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@
4141
name='login',
4242
),
4343
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
44+
path('', include('django_prometheus.urls'))
4445
]

ansible_wisdom/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ pydantic==1.10.2
66
psycopg2-binary==2.9.5
77
redis==4.4.2
88
uwsgi==2.0.21
9+
django_prometheus==2.2.0

prometheus/prometheus.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
global:
3+
scrape_interval: "60s"
4+
evaluation_interval: "60s"
5+
6+
scrape_configs:
7+
- job_name: monitoring
8+
metrics_path: /metrics
9+
static_configs:
10+
- targets:
11+
- django:8000

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies = [
1515
"django",
1616
"djangorestframework",
1717
"social-auth-app-django",
18+
"django_prometheus",
1819
]
1920
dynamic = ["version"]
2021

tools/docker-compose/compose.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,27 @@ services:
5454
# - $PWD/db_data:/var/lib/postgresql/data
5555
expose:
5656
- 5432
57+
prometheus:
58+
image: prom/prometheus
59+
command:
60+
- --config.file=/opt/prometheus/prometheus.yaml
61+
- --web.enable-lifecycle
62+
volumes:
63+
- $PWD/prometheus/prometheus.yaml:/opt/prometheus/prometheus.yaml
64+
restart: unless-stopped
65+
ports:
66+
- "9090:9090"
67+
networks:
68+
- dbnet
69+
grafana:
70+
image: grafana/grafana:latest
71+
ports:
72+
- "3000:3000"
73+
volumes:
74+
- $PWD/grafana:/opt/grafana
75+
restart: unless-stopped
76+
networks:
77+
- dbnet
78+
5779
networks:
5880
dbnet:

0 commit comments

Comments
 (0)