Open sentenz opened 11 months ago
Certainly! Below is an Ansible playbook example to set up the mentioned Prometheus, Grafana, and Node Exporter stack:
---
- hosts: localhost
become: true
tasks:
- name: Create Docker Compose file
copy:
content: |
version: '3'
services:
prometheus:
image: prom/prometheus:latest
volumes:
- ./prometheus:/etc/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- '9090:9090'
grafana:
image: grafana/grafana:latest
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
ports:
- '3000:3000'
depends_on:
- prometheus
node-exporter:
image: prom/node-exporter:latest
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- '--path.procfs=/host/proc'
- '--path.sysfs=/host/sys'
- '--collector.filesystem.ignored-mount-points=^/(sys|proc|dev|host|etc)($$|/)'
dest: ~/docker-compose.yml
- name: Create Prometheus Configuration
copy:
content: |
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'docker-containers'
static_configs:
- targets: ['node-exporter:9100']
dest: ~/prometheus/prometheus.yml
- name: Run Docker Compose
command: docker-compose up -d
args:
chdir: ~
- name: Wait for services to start
wait_for:
host: localhost
port: 3000
This Ansible playbook does the following:
docker-compose up -d
.Make sure Docker and Ansible are installed on the target machine, and adjust the paths and configurations as needed.
Prometheus & Grafana
Prometheus and Grafana are versatile and can be used to monitor a variety of applications and systems. They're commonly applied to monitor web servers, databases (like MySQL or PostgreSQL), container orchestration platforms (such as Kubernetes), and even custom applications. Their flexibility makes them handy for diverse monitoring needs.
Below is a simple example of using Prometheus and Grafana to monitor the metrics of all containers in a Docker environment:
Docker Compose File (docker-compose.yml):
Prometheus Configuration (prometheus/prometheus.yml):
Run Docker Compose:
Access Grafana:
Open your browser and go to
http://localhost:3000
. Log in with usernameadmin
and passwordadmin
. Add Prometheus as a data source and import dashboards for Docker and Node Exporter.This setup includes Prometheus, Grafana, and Node Exporter. Node Exporter collects system metrics, and Prometheus scrapes those metrics. Grafana visualizes the data using pre-built Docker and Node Exporter dashboards. Adjust configurations based on your specific needs.