Skip to content
Matej Vadnjal edited this page Jun 16, 2023 · 9 revisions

Setup

Add the following to your docker-compose.override.yml (or create that file if you haven't done so):

version: '3.4'
services:
  # netbox
  netbox:
    environment:
      METRICS_ENABLED: 'true'
      prometheus_multiproc_dir: /tmp/metrics
    volumes:
    - type: tmpfs
      target: /tmp/metrics
      read_only: false

  # nginx
  nginx-exporter:
    image: nginx/nginx-prometheus-exporter
    depends_on:
    - nginx
    command:
    - -nginx.scrape-uri
    - http://nginx:8081/stub_status

  # postgres
  postgres-exporter:
    image: wrouesnel/postgres_exporter:v0.8.0
    depends_on:
    - postgres
    environment:
      DATA_SOURCE_URI: postgres?sslmode=disable
      DATA_SOURCE_USER: netbox
      DATA_SOURCE_PASS: J5brHrAXFLQSif0K
      PG_EXPORTER_AUTO_DISCOVER_DATABASES: 'true'

  # redis
  redis-worker-exporter:
    image: oliver006/redis_exporter
    depends_on:
    - redis
    environment:
      REDIS_ADDR: redis://redis:6379
      REDIS_PASSWORD: H733Kdjndks81
  redis-cache-exporter:
    image: oliver006/redis_exporter
    depends_on:
    - redis-cache
    environment:
      REDIS_ADDR: redis://redis-cache:6379
      REDIS_PASSWORD: t4Ph722qJ5QHeQ1qfu36

  # prometheus
  prometheus:
    image: prom/prometheus:v2.22.0
    depends_on:
    - postgres-exporter
    - redis-cache-exporter
    - redis-worker-exporter
    - nginx-exporter
    - netbox
    ports:
    - '9090:9090'
    volumes:
    - ./prometheus.yml:/etc/prometheus/prometheus.yml
    - prometheus-data:/prometheus/data

  # grafana
  grafana:
    image: grafana/grafana:7.2.1
    depends_on:
    - prometheus
    environment:
      GF_SECURITY_ADMIN_USER: admin
      GF_SECURITY_ADMIN_PASSWORD: admin
      GF_SECURITY_SECRET_KEY: oew5RCBGGBba0MdsEKrj
      GF_METRICS_ENABLED: 'true'
    ports:
    - '3000:3000'
    volumes:
    #- ./monitoring/grafana/plugins/:/var/lib/grafana/plugins/:z,ro
    #- ./monitoring/grafana/provisioning/:/etc/grafana/provisioning/:z,ro
    #- ./monitoring/grafana/dashboards/:/etc/grafana/dashboards/:z,ro
    - grafana-data:/var/lib/grafana

volumes:
  prometheus-data:
    driver: local
  grafana-data:
    driver: local

Then create the new file prometheus.yml:

scrape_configs:
- job_name: prometheus
  static_configs:
  - targets: ['localhost:9090']

- job_name: netbox
  static_configs:
  - targets: ['netbox:8001']

- job_name: nginx
  static_configs:
  - targets: ['nginx-exporter:9113']

- job_name: postgresql
  static_configs:
  - targets: ['postgres-exporter:9187']

- job_name: redis
  static_configs:
  - targets: ['redis-worker-exporter:9121', 'redis-cache-exporter:9121']

- job_name: grafana
  static_configs:
  - targets: ['grafana:3000']

Then run docker-compose up.

Prometheus

Prometheus grabs the data once every minute from each service (NetBox, Nginx, PostgreSQL, 2x Redis, Prometheus itself) and stores it in a TSDB. You can access Prometheus on port 9090.

Grafana

Grafana provides visualization of the data, which can be composed into dashboard. To fetch the data it talks directly to the Prometheus service. You can access Grafana on port 3000. The default credentials are admin:admin.

You will find several user-made dashboards on the Grafana page which are easy to import using the Grafana Dashboard ID. There are already dashboard for Nginx, PostgreSQL, Redis, Prometheus and also Django (which is the framework on which NetBox is built). For more information see the importing a dashboard and discover dashboards on grafana.com articles.

Clone this wiki locally