3-Tier Architecture Deployment with Docker: Monitoring Setup (4)

·

2 min read

Traffic Flow

Prometheus Configuration

prometheus.yaml

  • This file is the main configuration file for Prometheus.
global:
  scrape_interval: 15s  # Default interval for scraping metrics.
  evaluation_interval: 15s  # Interval for evaluating rules.

scrape_configs:
  - job_name: 'prometheus'  # Monitor Prometheus itself.
    scrape_interval: 5s
    static_configs:
      - targets: ['prometheus:9090']

  - job_name: 'node-exporter'  # Collect metrics from Node Exporter.
    scrape_interval: 5s
    static_configs:
      - targets: ['node-exporter:9100']

  - job_name: 'cadvisor'  # Collect metrics from cAdvisor.
    scrape_interval: 5s
    static_configs:
      - targets: ['cadvisor:8080']
  • Scrape Interval: Defines how often Prometheus collects data.

  • Static Configs: Specifies the targets (services) Prometheus monitors.

Example Docker command or in docker-compose.yml:

version: '3.7'
services:
  prometheus:
    image: prom/prometheus
    volumes:
      - ./prometheus.yaml:/etc/prometheus/prometheus.yml
    ports:
      - "9090:9090"

Grafana Configuration

datasource.yaml

  • This file is used to preconfigure data sources in Grafana.
apiVersion: 1

deleteDatasources:
  - name: Prometheus  # Datasource to delete (if any).

datasources:
  - name: Prometheus  # Name of the datasource.
    type: prometheus  # Type of datasource.
    access: proxy
    orgId: 1
    url: http://prometheus:9090  # URL of the Prometheus server.
    basicAuth: false
    isDefault: true  # Set as the default datasource.
    version: 1
    editable: false  # Make datasource non-editable via UI.
  • Datasources: Configures Grafana to use Prometheus as the data source for visualizations.

  • Example Docker command or in docker-compose.yml:

      version: '3.7'
      services:
        grafana:
          image: grafana/grafana
          volumes:
            - ./datasource.yaml:/etc/grafana/provisioning/datasources/datasource.yaml
          ports:
            - "3000:3000"
    

Next Steps

In the next post, we'll explore three different methods to run and manage the services we've set up so far, including the frontend, backend, database, and monitoring services.