prometheus下载路径:https://prometheus.io/download/
下载如下三个组件
Prometheus Server
Pushgateway
Node Exporter
- 安装 Prometheus Server
Prometheus 基于 Golang 编写,编译后的软件包,不依赖于任何的第三方依赖。只需要下载对应平台的二进制包,解压并且添加基本的配置即可正常启动Prometheus Server。
解压到/date 目录下
tar -zxvf prometheus-2.36.1.linux-amd64.tar.gz -C /date
修改配置文件 prometheus.yml
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
# 添加 PushGateway 监控配置
- job_name: 'pushgateway'
static_configs:
- targets: ['localhost:9091']
labels:
instance: pushgateway
# 添加 Node Exporter 监控配置
- job_name: 'node exporter'
static_configs:
- targets: ['localhost:9100', 'localhost:9100', 'localhost:9100']
启 动:nohup ./prometheus --config.file=prometheus.yml > ./prometheus.log 2>&1 &
配置说明:
1、global 配置块:控制 Prometheus 服务器的全局配置
➢ scrape_interval:配置拉取数据的时间间隔,默认为 1 分钟。
➢ evaluation_interval:规则验证(生成 alert)的时间间隔,默认为 1 分钟。
2、rule_files 配置块:规则配置文件
3、scrape_configs 配置块:配置采集目标相关, prometheus 监视的目标。Prometheus
自身的运行信息可以通过 HTTP 访问,所以 Prometheus 可以监控自己的运行数据。
➢ job_name:监控作业的名称
➢ static_configs:表示静态目标配置,就是固定从某个 target 拉取数据
➢ targets : 指 定 监 控 的 目 标 , 其 实 就 是 从 哪 儿 拉 取 数 据 。 Prometheus 会 从
http://localhost:9090/metrics 上拉取数据。
Prometheus 是可以在运行时自动加载配置的。启动时需要添加:–web.enable-lifecycle
2. 安装 Pushgateway
解压:bashtar -zxvf pushgateway-1.4.3.linux-amd64.tar.gz -C /date
启动:nohup ./prometheus --config.file=prometheus.yml > ./prometheus.log 2>&1 &
3. 安装 Node Exporter
在 Prometheus 的架构设计中,Prometheus Server 主要负责数据的收集,存储并且对外提供数据查询支持,而实际的监控样本数据的收集则是由 Exporter 完成。因此为了能够监控到某些东西,如主机的 CPU 使用率,我们需要使用到 Exporter。Prometheus 周期性的从 Exporter 暴露的 HTTP 服务地址(通常是/metrics)拉取监控样本数据。
Exporter 可以是一个相对开放的概念,其可以是一个独立运行的程序独立于监控目标以外,也可以是直接内置在监控目标中。只要能够向 Prometheus 提供标准格式的监控样本数据即可。
为了能够采集到主机的运行指标如 CPU, 内存,磁盘等信息。我们可以使用 Node Exporter。Node Exporter 同样采用 Golang 编写,并且不存在任何的第三方依赖,只需要下载,解压即可运行。可以从 https://prometheus.io/download/ 获取最新的 node exporter 版本的二进制包。
解压:tar -zxvf node_exporter-1.3.1.linux-amd64.tar.gz -C /date
启动并通过页面查看是否成功
执行./node_exporter
浏览器输入:http://localhost:9100/metrics
,可以看到当前 node exporter 获取
到的当前主机的所有监控数据。
节点分发
➢ 将解压后的目录分发到要监控的节点
xsync node_exporter-1.2.2
➢ 修改 Prometheus 配置文件 prometheus.yml,
targets: ['localhost:9100', 'localhost:9100', 'localhost:9100']
4. 打开 web 页面查看
➢ 浏览器输入:http://localhost:9090/
status/targets下