Skip to content

Commit f46d8a7

Browse files
committed
Adds Prometheus/Grafana monitoring infrastructure
1 parent 64d82b5 commit f46d8a7

21 files changed

+6414
-6
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ The default credentials are:
7979
## Documentation
8080

8181
Please refer [to our wiki on Github][netbox-docker-wiki] for further information on how to use this Netbox Docker image properly.
82-
It covers advanced topics such as using secret files, deployment to Kubernetes as well as NAPALM and LDAP configuration.
82+
You'll learn how to read the integrated metrics using [Prometheus][prometheus] and [Grafana][grafana].
83+
It also covers advanced topics such as using secret files, deployment to Kubernetes as well as NAPALM and LDAP configuration.
8384

85+
[prometheus]: https://prometheus.io/
86+
[grafana]: https://grafana.com/grafana/
8487
[netbox-docker-wiki]: https://github.com/netbox-community/netbox-docker/wiki/
8588

8689
## Getting Help

docker-compose.yml

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ services:
1818
- netbox-nginx-config:/etc/netbox-nginx:z
1919
- netbox-static-files:/opt/netbox/netbox/static:z
2020
- netbox-media-files:/opt/netbox/netbox/media:z
21+
- type: tmpfs
22+
target: /tmp/metrics
23+
read_only: false
2124
netbox-worker:
2225
<<: *netbox
2326
depends_on:
@@ -27,6 +30,8 @@ services:
2730
- /opt/netbox/netbox/manage.py
2831
command:
2932
- rqworker
33+
34+
# nginx
3035
nginx:
3136
command: nginx -c /etc/netbox-nginx/nginx.conf
3237
image: nginx:1.19-alpine
@@ -37,27 +42,85 @@ services:
3742
volumes:
3843
- netbox-static-files:/opt/netbox/netbox/static:ro
3944
- netbox-nginx-config:/etc/netbox-nginx/:ro
45+
46+
nginx-exporter:
47+
image: nginx/nginx-prometheus-exporter
48+
depends_on:
49+
- nginx
50+
command:
51+
- -nginx.scrape-uri
52+
- http://nginx:8081/stub_status
53+
54+
# postgres
4055
postgres:
4156
image: postgres:12-alpine
4257
env_file: env/postgres.env
4358
volumes:
4459
- netbox-postgres-data:/var/lib/postgresql/data
45-
redis:
60+
61+
postgres-exporter:
62+
image: wrouesnel/postgres_exporter:v0.8.0
63+
depends_on:
64+
- postgres
65+
env_file: env/postgres-exporter.env
66+
67+
# redis
68+
redis: &redis
4669
image: redis:6-alpine
4770
command:
4871
- sh
4972
- -c # this is to evaluate the $REDIS_PASSWORD from the env
5073
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
51-
env_file: env/redis.env
74+
env_file: env/redis-worker.env
5275
volumes:
5376
- netbox-redis-data:/data
5477
redis-cache:
5578
image: redis:6-alpine
5679
command:
5780
- sh
5881
- -c # this is to evaluate the $REDIS_PASSWORD from the env
59-
- redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
82+
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
6083
env_file: env/redis-cache.env
84+
85+
redis-worker-exporter:
86+
image: oliver006/redis_exporter
87+
depends_on:
88+
- redis
89+
env_file: env/redis-worker-exporter.env
90+
redis-cache-exporter:
91+
image: oliver006/redis_exporter
92+
depends_on:
93+
- redis-cache
94+
env_file: env/redis-cache-exporter.env
95+
96+
# prometheus
97+
prometheus:
98+
image: prom/prometheus:v2.22.0
99+
depends_on:
100+
- postgres-exporter
101+
- redis-cache-exporter
102+
- redis-worker-exporter
103+
- nginx-exporter
104+
- netbox
105+
ports:
106+
- 9090
107+
volumes:
108+
- ./monitoring/prometheus/:/etc/prometheus/
109+
- prometheus-data:/prometheus/data
110+
111+
# grafana
112+
grafana:
113+
image: grafana/grafana:7.2.1
114+
depends_on:
115+
- prometheus
116+
ports:
117+
- 3000
118+
volumes:
119+
- ./monitoring/grafana/plugins/:/var/lib/grafana/plugins/:z,ro
120+
- ./monitoring/grafana/provisioning/:/etc/grafana/provisioning/:z,ro
121+
- ./monitoring/grafana/dashboards/:/etc/grafana/dashboards/:z,ro
122+
- grafana-data:/var/lib/grafana
123+
61124
volumes:
62125
netbox-static-files:
63126
driver: local
@@ -69,3 +132,7 @@ volumes:
69132
driver: local
70133
netbox-redis-data:
71134
driver: local
135+
prometheus-data:
136+
driver: local
137+
grafana-data:
138+
driver: local

docker/gunicorn_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
accesslog = '-'
77
capture_output = False
88
loglevel = 'info'
9+
raw_env = 'prometheus_multiproc_dir=/tmp/metrics'

docker/nginx.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,13 @@ http {
3232
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
3333
}
3434
}
35+
36+
server {
37+
listen 8081;
38+
access_log off;
39+
40+
location = /stub_status {
41+
stub_status;
42+
}
43+
}
3544
}

env/grafana.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GF_SECURITY_ADMIN_USER=admin
2+
GF_SECURITY_ADMIN_PASSWORD=admin
3+
GF_SECURITY_SECRET_KEY=oew5RCBGGBba0MdsEKrj

env/netbox.env

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ EMAIL_USE_SSL=false
1414
EMAIL_USE_TLS=false
1515
EMAIL_SSL_CERTFILE=
1616
EMAIL_SSL_KEYFILE=
17+
MAX_PAGE_SIZE=1000
1718
MEDIA_ROOT=/opt/netbox/netbox/media
19+
METRICS_ENABLED=true
1820
NAPALM_USERNAME=
1921
NAPALM_PASSWORD=
2022
NAPALM_TIMEOUT=10
21-
MAX_PAGE_SIZE=1000
2223
REDIS_HOST=redis
2324
REDIS_PASSWORD=H733Kdjndks81
2425
REDIS_DATABASE=0
@@ -27,6 +28,7 @@ REDIS_CACHE_HOST=redis-cache
2728
REDIS_CACHE_PASSWORD=t4Ph722qJ5QHeQ1qfu36
2829
REDIS_CACHE_DATABASE=1
2930
REDIS_CACHE_SSL=false
31+
RELEASE_CHECK_URL=https://api.github.com/repos/netbox-community/netbox/releases
3032
SECRET_KEY=r8OwDznj!!dci#P9ghmRfdu1Ysxm0AiPeDCQhKE+N_rClfWNj
3133
SKIP_STARTUP_SCRIPTS=false
3234
SKIP_SUPERUSER=false
@@ -35,4 +37,3 @@ SUPERUSER_EMAIL=admin@example.com
3537
SUPERUSER_PASSWORD=admin
3638
SUPERUSER_API_TOKEN=0123456789abcdef0123456789abcdef01234567
3739
WEBHOOKS_ENABLED=true
38-
RELEASE_CHECK_URL=https://api.github.com/repos/netbox-community/netbox/releases

env/postgres-exporter.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DATA_SOURCE_URI=postgres?sslmode=disable
2+
DATA_SOURCE_USER=netbox
3+
DATA_SOURCE_PASS=J5brHrAXFLQSif0K
4+
PG_EXPORTER_AUTO_DISCOVER_DATABASES=true

env/redis-cache-exporter.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
REDIS_ADDR=redis://redis-cache:6379
2+
REDIS_PASSWORD=t4Ph722qJ5QHeQ1qfu36

env/redis-worker-exporter.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
REDIS_ADDR=redis://redis:6379
2+
REDIS_PASSWORD=H733Kdjndks81
File renamed without changes.

0 commit comments

Comments
 (0)