Fix naming of the chapter dir

This commit is contained in:
Baohua Yang
2026-02-22 12:42:15 -08:00
parent b9ac198f19
commit 92ea9623b2
130 changed files with 1001 additions and 852 deletions

View File

@@ -0,0 +1,109 @@
## 19.1 Prometheus + Grafana
Prometheus Grafana 是目前最流行的开源监控组合前者负责数据采集与存储后者负责数据可视化
[Prometheus](https://prometheus.io/) 是一个开源的系统监控和报警工具包。它受 Google Borgmon 的启发,由 SoundCloud 在 2012 年创建。
### 19.1.1 架构简介
Prometheus 的主要组件包括
* **Prometheus Server**核心组件负责收集和存储时间序列数据
* **Exporters**负责向 Prometheus 暴露监控数据 ( Node ExportercAdvisor)
* **Alertmanager**处理报警发送
* **Pushgateway**用于支持短生命周期的 Job 推送数据
### 19.1.2 快速部署
我们可以使用 Docker Compose 快速部署一套 Prometheus + Grafana 监控环境
#### 1准备配置文件
创建 `prometheus.yml`
```yaml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node-exporter'
static_configs:
- targets: ['node-exporter:9100']
- job_name: 'cadvisor'
static_configs:
- targets: ['cadvisor:8080']
```
#### 2编写 Docker Compose 文件
创建 `compose.yaml` ( `docker-compose.yml`)
```yaml
services:
prometheus:
image: prom/prometheus:latest
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
networks:
- monitoring
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
networks:
- monitoring
depends_on:
- prometheus
node-exporter:
image: prom/node-exporter:latest
ports:
- "9100:9100"
networks:
- monitoring
cadvisor:
image: gcr.io/cadvisor/cadvisor:latest
ports:
- "8080:8080"
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
networks:
- monitoring
networks:
monitoring:
```
#### 3启动服务
运行以下命令
```bash
$ docker compose up -d
```
启动后访问以下地址
* Prometheus: `http://localhost:9090`
* Grafana`http://localhost:3000` (默认账号密码admin/admin)
### 19.1.3 配置 Grafana 面板
1. Grafana 中添加 Prometheus 数据源URL 填写 `http://prometheus:9090`
2. 导入现成的 Dashboard 模板例如 [Node Exporter Full](https://grafana.com/grafana/dashboards/1860) (ID1860) 和 [Docker Container](https://grafana.com/grafana/dashboards/193) (ID193)。
这样你就拥有了一个直观的容器监控大屏