.
├── Grafana
│ ├── data
│ └── docker-compose.yaml
├── Mysql
│ ├── conf
│ ├── data
│ ├── docker-compose.yaml
│ └── logs
├── Mysqld_exporter
│ ├── conf
│ └── docker-compose.yaml
├── node-exporter
│ └── docker-compose.yaml
└── Prometheus
├── data
├── docker-compose.yaml
└── yml
Prometheus
# Docker Compose 版本声明
version: '3'
# 定义服务列表,这里定义了一个名为 prometheus 的服务
services:
# 服务名称:prometheus
prometheus:
# 使用的Docker镜像,这里是 Prometheus 监控系统的官方镜像
image: prom/prometheus:v2.38.0
# 为容器指定一个名称
container_name: prometheus
# 定义卷挂载,将主机目录挂载到容器内的目录
volumes:
# 挂载 Prometheus 配置文件到容器内
- ./yml/prometheus.yml:/etc/prometheus/prometheus.yml
# 挂载数据目录,用于存储 Prometheus 的数据
- ./data:/prometheus
# 自定义命令来启动 Prometheus 容器
command:
# 指定 Prometheus 配置文件的位置
- '--config.file=/etc/prometheus/prometheus.yml'
# 指定 Prometheus 数据存储的路径
- '--storage.tsdb.path=/prometheus'
# 指定控制台库的目录
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
# 指定控制台模板的目录
- '--web.console.templates=/usr/share/prometheus/consoles'
# 启用 Prometheus 的生命周期功能
- '--web.enable-lifecycle'
# 端口映射,将容器的9090端口映射到宿主机的9090端口
ports:
- "9090:9090"
# 定义重启策略,除非明确停止,否则总是尝试重启容器
restart: unless-stopped
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['192.168.88.128:9090']
- job_name: 'grafana'
static_configs:
- targets: ['192.168.88.128:3000']
# 采集MySQL监控数据
- job_name: 'mysqld_exporter'
static_configs:
- targets: ['192.168.88.128:9104']
# 采集node exporter监控数据,即linux
- job_name: 'node-exporter'
static_configs:
- targets: ['192.168.88.128:9100']
Grafana
Grafana做持久化操作,使用MySQL,如果已有数据库直接使用,只需创建grafana库即可。
# Docker Compose 版本声明
version: '3'