Created
September 27, 2022 07:33
-
-
Save Mohammed-Sunasra/69693e7a5b77a010cf1f3e26fde99b8f to your computer and use it in GitHub Desktop.
Grafana and Prometheus using docker-compose and running behind NGINX reverse proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.8' | |
services: | |
prometheus: | |
image: prom/prometheus | |
container_name: prometheus | |
restart: 'no' | |
volumes: | |
- prometheus_data:/prometheus | |
- ./prometheus.yml:/etc/prometheus/prometheus.yml | |
ports: | |
- 9090:9090 | |
node-exporter: | |
image: prom/node-exporter:latest | |
container_name: node-exporter | |
restart: unless-stopped | |
volumes: | |
- '/:/host:ro' | |
command: | |
- '--path.rootfs=/host' | |
expose: | |
- 9100 | |
depends_on: | |
- prometheus | |
grafana: | |
image: grafana/grafana | |
container_name: grafana | |
environment: | |
GF_INSTALL_PLUGINS: "grafana-clock-panel,grafana-simple-json-datasource" | |
GF_SERVER_ROOT_URL: "https://domain/grafana/" | |
restart: 'no' | |
volumes: | |
- grafana_data:/var/lib/grafana | |
ports: | |
- 4000:3000 | |
depends_on: | |
- prometheus | |
volumes: | |
prometheus_data: | |
grafana_data: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map $http_upgrade $connection_upgrade { | |
default upgrade; | |
'' close; | |
} | |
upstream django_app { | |
server localhost:8000; | |
} | |
upstream grafana { | |
server localhost:4000; | |
} | |
upstream prometheus { | |
server localhost:9090; | |
} | |
# Proxy grafana dashboard | |
location /grafana/ { | |
proxy_pass http://grafana; | |
rewrite ^/grafana/(.*) /$1 break; | |
proxy_set_header X-Forwarded-Server $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
include proxy_params; | |
} | |
# Proxy prometheus app(NOTE: there is no authentication in prometheus app by default so keep that in mind) | |
location /prometheus { | |
proxy_pass http://prometheus; | |
proxy_set_header Accept-Encoding ""; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
rewrite ^/prometheus/?$ /prometheus/graph redirect; | |
rewrite ^/prometheus/(.*)$ /$1 break; | |
} | |
# Proxy Grafana Live WebSocket connections. | |
location /grafana/api/live/ { | |
rewrite ^/grafana/(.*) /$1 break; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection $connection_upgrade; | |
proxy_set_header Host $http_host; | |
proxy_pass http://grafana; | |
} | |
# Proxy django app | |
location / { | |
proxy_set_header Host $http_host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
proxy_pass http://django_app; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment