Step 1: Run your Prometheus and Grafana


     

    Version: '3.6'

    services:

    prometheus:

    Image: a PROM/Prometheus: v2.14.0

    volumes:

    -. / Prometheus: / etc/Prometheus

    command:

    . - '- config file = / etc/Prometheus/Prometheus yml'

    ports:

    - 9090:9090

    grafana:

    Image: grafana/grafana: tactical fix packs for 6.5.2

    ports:

    - 3060:3000

Copy the code

Step 2: Configure your Prometheus


     

    global:

    scrape_interval: 15s

    evaluation_interval: 15s

    rule_files:

    # - "first. The rules"

    # - "second. Rules"

    scrape_configs:

    -- job_name: monitoring

    static_configs:

    - the targets:

    - host. Docker. Internal

Copy the code

     

    $ docker-compose -f docker-compose.monitoring.yml up -d

Copy the code

Step 3: Add something to expose your Django application’s monitoring data


     

    pip install django-prometheus

Copy the code

     

    BASE_INSTALLED_APPS = [

    .

    "Django_prometheus",

    ]

    MIDDLEWARE = [

    "Django_prometheus. Middleware. PrometheusBeforeMiddleware",

    .

    "Django_prometheus. Middleware. PrometheusAfterMiddleware",

    ]

Copy the code

     

    Url (" ", include (" django_prometheus. Urls ")),

Copy the code

Step 4: Create your Grafana panel

  1. Click graph Title, then click Edit.

  2. On the “Metrics” TAB, select your Prometheus data source (bottom right).

  3. In the “Query” column, enter any Prometheus Query expression and use the “Metric” option to complete.

  1. https://hub.docker.com/r/grafana/grafana

  2. https://github.com/korfuri/django-prometheus/

  3. https://www.katacoda.com/courses/docker/deploying-first-container