docker 安装

安装 Prometheus Server

docker run --name prometheus -d -p 127.0.0.1:9090:9090 prom/prometheus

启动完成后,可以通过 http://localhost:9090 访问 Prometheus 的 UI 界面。

使用 Node Exporter 采集主机数据

在 Prometheus 的架构设计中,Prometheus Server 并不直接监控特定的目标,其主要任务是负责数据的收集、存储,并且对外提供数据查询支持。因此为了能够能够监控到某些东西,如主机的 CPU 使用率,需要使用到 Exporter。Prometheus 周期性的从 Exporter 暴露的 HTTP 服务地址(通常是 /metrics)拉取监控样本数据。

为了能够采集到主机的运行指标如 CPU、内存、磁盘等信息,可以使用 Node Exporter。

从 Node Exporter 收集监控数据

为了能够让 Prometheus Server 能够从当前 node exporter 获取到监控数据,这里需要修改 Prometheus 配置文件。编辑 prometheus.yml 并在 scrape_configs 节点下添加以下内容:

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']
  # 采集node exporter监控数据
  - job_name: 'node'
    static_configs:
      - targets: ['localhost:9100']

重新启动 Prometheus Server,访问 http://localhost:9090,进入到 Prometheus Server。如果输入 “up” 并且点击执行按钮以后,可以看到如下结果:

最后更新于