Lädt...


🔧 Docker with Prometheus and Grafana: Real-Time Monitoring Simplified


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Docker with Prometheus and Grafana: Monitoring Made Easy

Prometheus and Grafana are powerful tools for monitoring containerized applications and infrastructure. Docker simplifies deploying and managing these tools, enabling real-time monitoring, metrics visualization, and alerting.

Overview

  • Prometheus: An open-source monitoring system that collects metrics from applications and infrastructure. It uses a pull-based mechanism and stores time-series data.
  • Grafana: A visualization tool that creates interactive and customizable dashboards using data from Prometheus and other sources.

Why Use Prometheus and Grafana with Docker?

  1. Easy Setup: Docker provides prebuilt images for Prometheus and Grafana, reducing setup complexity.
  2. Portability: Run Prometheus and Grafana in isolated containers, ensuring consistency across environments.
  3. Scalability: Easily scale monitoring setups by deploying containers on multiple hosts using Docker Compose or orchestrators like Kubernetes.
  4. Integration: Monitor other Docker containers, services, and infrastructure components.

Setting Up Prometheus and Grafana with Docker

1. Prerequisites

  • Install Docker and Docker Compose on your system.
  • Basic understanding of Docker and container networking.

2. Define a Docker Compose File

Create a docker-compose.yml file to configure Prometheus and Grafana.

version: '3.8'

services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    ports:
      - "9090:9090"

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    ports:
      - "3000:3000"
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=admin

3. Configure Prometheus

Create a prometheus.yml file to define the Prometheus configuration.

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'docker'
    static_configs:
      - targets: ['host.docker.internal:9323']

In this example:

  • Prometheus scrapes metrics from the Docker host using the Docker Daemon's metrics endpoint (via port 9323).

4. Run the Stack

Run the Prometheus and Grafana stack using Docker Compose:

docker-compose up -d

This will start:

  • Prometheus on http://localhost:9090
  • Grafana on http://localhost:3000

5. Add Data Source in Grafana

  1. Access Grafana at http://localhost:3000 (default username/password: admin/admin).
  2. Navigate to Configuration > Data Sources.
  3. Add Prometheus as a data source:
    • URL: http://host.docker.internal:9090
    • Save and Test.

6. Import a Dashboard

  1. Go to Create > Import in Grafana.
  2. Use a prebuilt dashboard by entering an ID from the Grafana Dashboard Library (e.g., Docker Monitoring Dashboard ID: 12210).
  3. Select Prometheus as the data source and import.

Monitoring Docker Containers

1. Expose Docker Metrics

Enable Docker metrics on the host by modifying the Docker Daemon configuration:

  1. Add the following to /etc/docker/daemon.json:
   {
     "metrics-addr": "0.0.0.0:9323",
     "experimental": true
   }
  1. Restart the Docker service:
   sudo systemctl restart docker

2. Visualize Container Metrics

  • Prometheus will scrape metrics from the Docker Daemon.
  • Use Grafana dashboards to visualize metrics like:
    • Container CPU and memory usage
    • Network traffic
    • Disk I/O

Advanced Configuration

Alerting in Prometheus

  1. Add alert rules in prometheus.yml:
   rule_files:
     - "alert.rules"

   alerting:
     alertmanagers:
       - static_configs:
           - targets: ['host.docker.internal:9093']
  1. Example alert.rules:
   groups:
     - name: example
       rules:
         - alert: HighCPUUsage
           expr: container_cpu_usage_seconds_total > 80
           for: 5m
           labels:
             severity: critical
           annotations:
             summary: "High CPU usage detected"
             description: "Container {{ $labels.container }} is using high CPU."

Custom Dashboards in Grafana

  • Use query builders or PromQL to create custom panels and dashboards tailored to your monitoring needs.

Scale with Docker Swarm or Kubernetes

Deploy Prometheus and Grafana on orchestrators for better scalability and fault tolerance:

  • Use Kubernetes Helm charts for a simplified setup.
  • Integrate with monitoring tools like Kubernetes Metrics Server.

Best Practices

  1. Optimize Scrape Intervals:
    Adjust the scrape interval in Prometheus for high-traffic environments to avoid overloading the system.

  2. Use Persistent Storage:
    Mount volumes to persist data:

   volumes:
     - prometheus_data:/prometheus
     - grafana_data:/var/lib/grafana
  1. Secure Access:

    • Use HTTPS for Grafana and Prometheus.
    • Set strong Grafana admin credentials.
  2. Automate Deployment:
    Use CI/CD pipelines to automate the deployment of monitoring stacks.

Conclusion

Using Docker to deploy Prometheus and Grafana offers a powerful, flexible, and scalable monitoring solution. With Docker's simplicity and containerization, setting up real-time monitoring becomes straightforward, ensuring your infrastructure and applications are running optimally.

...

🔧 DevOps Monitoring and Automation Tool using Jenkins, Prometheus, Grafana and Docker


📈 44.48 Punkte
🔧 Programmierung

🔧 Setting Up DevOps Monitoring and Automation with Jenkins, Prometheus, Grafana, and Docker


📈 44.48 Punkte
🔧 Programmierung

🔧 Monitoring MySQL with Prometheus and Grafana in Docker


📈 43.25 Punkte
🔧 Programmierung

🔧 Monitoring Your Server with Prometheus, Node Exporter, and Grafana Using Docker


📈 43.25 Punkte
🔧 Programmierung

🔧 Monitoring with cAdvisor, Prometheus and Grafana on Docker


📈 43.25 Punkte
🔧 Programmierung

🔧 Building a Docker-based Monitoring System with Prometheus and Grafana


📈 43.25 Punkte
🔧 Programmierung

🔧 Golang com Opentelemetry, prometheus, Grafana tempo OSS e Grafana padrão


📈 39.93 Punkte
🔧 Programmierung

🔧 Grafana Labs releases Grafana 11, Loki 3.0, and a new open source project called Grafana Alloy


📈 39.75 Punkte
🔧 Programmierung

📰 Mehrere Probleme in grafana-piechart-panel, grafana-status-panel und grafana (SUSE)


📈 38.52 Punkte
📰 IT Security Nachrichten

🕵️ Grafana up to 6.3.6 on Red Hat /etc/grafana/grafana.ini information disclosure


📈 38.52 Punkte
🕵️ Sicherheitslücken

🔧 Day 14: Advanced Logging and Monitoring with Prometheus, Grafana, and Alertmanager (Termux Edition!)


📈 37.44 Punkte
🔧 Programmierung

🔧 Project Documentation: Monitoring and Logging with Prometheus and Grafana


📈 37.44 Punkte
🔧 Programmierung

🔧 Setting Up Grafana, Prometheus, and ELK for Monitoring and Logging in AWS EKS


📈 37.44 Punkte
🔧 Programmierung

🔧 Why Prometheus and Grafana are Essential for Monitoring in DevOps and How They Enhance the SDLC


📈 37.44 Punkte
🔧 Programmierung

🔧 Kubernetes Metrics and Monitoring with Prometheus and Grafana


📈 37.44 Punkte
🔧 Programmierung

🔧 Building Observability and Monitoring for Modern Applications with Actuator, Prometheus and Grafana


📈 37.44 Punkte
🔧 Programmierung

🔧 Monitor HA Cluster running Pacemaker and Corosync using Prometheus and Grafana using Docker


📈 36.57 Punkte
🔧 Programmierung

🐧 How To Setup Prometheus | Prometheus For Monitoring.


📈 36.39 Punkte
🐧 Linux Tipps

🔧 Monitoring Linux instances with Prometheus and Grafana


📈 36.22 Punkte
🔧 Programmierung

🔧 EKS cluster Monitoring for AWS Fargate with Prometheus and managed Grafana


📈 36.22 Punkte
🔧 Programmierung

🎥 Matrix Tutorial #12 — Monitoring Synapse with Prometheus and Grafana


📈 36.22 Punkte
🎥 Video | Youtube

🔧 PM2 module to monitoring node.js application with export to Prometheus and Grafana


📈 36.22 Punkte
🔧 Programmierung

🔧 Achieving Kubernetes Monitoring Nirvana: Prometheus and Grafana Unleashed


📈 36.22 Punkte
🔧 Programmierung

📰 Linux System Monitoring with Prometheus, Grafana, and collectd


📈 36.22 Punkte
🐧 Unix Server

🔧 Monitoring API Performance with Express, Prometheus, and Grafana


📈 36.22 Punkte
🔧 Programmierung

🔧 Day 3 of My 90 Days of DevOps Projects: Monitoring with Prometheus and Grafana


📈 36.22 Punkte
🔧 Programmierung

🔧 Creating a CICD Pipeline using Jenkins on AWS EC2, Monitoring using Prometheus, and Grafana


📈 36.22 Punkte
🔧 Programmierung

🔧 Monitoring Spring Boot Applications with Prometheus and Grafana


📈 36.22 Punkte
🔧 Programmierung

🔧 Setting Up a Monitoring Stack with Nginx Logging Using Grafana, cAdvisor, Promtail, Prometheus, and Loki


📈 36.22 Punkte
🔧 Programmierung

🔧 Redis Monitoring with Prometheus Exporter and Grafana


📈 36.22 Punkte
🔧 Programmierung

🔧 Supercharge Your Node.js Monitoring with OpenTelemetry, Prometheus, and Grafana


📈 36.22 Punkte
🔧 Programmierung

🔧 Monitoring Solutions: Prometheus and Grafana


📈 36.22 Punkte
🔧 Programmierung

matomo