github编辑

Prometheus

Prometheusarrow-up-right 是一个开源的系统监控和报警工具包。它受 Google Borgmon 的启发,由 SoundCloud 在 2012 年创建。

架构简介

Prometheus 的主要组件包括:

  • Prometheus Server: 核心组件,负责收集和存储时间序列数据。

  • Exporters: 负责向 Prometheus 暴露监控数据(如 Node Exporter, cAdvisor)。

  • Alertmanager: 处理报警发送。

  • Pushgateway: 用于支持短生命周期的 Job 推送数据。

快速部署

我们可以使用 Docker Compose 快速部署一套 Prometheus + Grafana 监控环境。

1. 准备配置文件

创建 prometheus.yml:

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 文件

创建 docker-compose.yml:

3. 启动服务

启动后,访问以下地址:

  • Prometheus: http://localhost:9090

  • Grafana: http://localhost:3000 (默认账号密码: admin/admin)

配置 Grafana 面板

  1. 在 Grafana 中添加 Prometheus 数据源,URL 填写 http://prometheus:9090

  2. 导入现成的 Dashboard 模板,例如 Node Exporter Fullarrow-up-right (ID: 1860) 和 Docker Containerarrow-up-right (ID: 193)。

这样,你就拥有了一个直观的容器监控大屏。

最后更新于