1)下载Prometheus软件包、解压(Prometheus 是采用 Go 语言开发的,直接使用独立的二进制文件即可部署)
$ wget https://github.com/prometheus/prometheus/releases/download/v2.30.2/prometheus-2.30.2.linux-amd64.tar.gz # 如果被限制可以使用下面的加速地址下载 # wget https://download.fastgit.org/prometheus/prometheus/releases/download/v2.30.2/prometheus-2.30.2.linux-amd64.tar.gz $ tar -xvf prometheus-2.30.2.linux-amd64.tar.gz $ cd prometheus-2.30.1.linux-amd64 $ ./prometheus -h 查看帮助
2) 配置Prometheus
Prometheus 本身也暴露 metrics 指标接口(默认9090端口),所以自然它也可以抓取并监控其自身的运行状况,下面用收集Prometheus自身的数据为例,配置文件prometheus.yml如下:
$ cd prometheus-2.30.1.linux-amd64
$ cat prometheus.yml
global:
scrape_interval: 5s
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
# global: 区域用于配置一些全局配置和默认值
# scrape_configs: 用来告诉 Prometheus 要抓取哪些目标的
3)配置好prometheus.yaml后./prometheus 运行,在浏览器访问Prometheus 的web 页面,检查下它是否正确的抓取了配置的目标,可以在浏览器中访问 http://
1)下载软件包、解压、运行node_exporter
$ wget https://download.fastgit.org/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz $ tar -xvf node_exporter-1.2.2.linux-amd64.tar.gz $ cd node_exporter-1.2.2.linux-amd64 进入目录后直接执行 node_exporter 文件即可运行: $ ./node_exporter -h 查看启动参数配置 $ ./node_exporter 启动
2)node_exporter 监听端口为9100,该 metrics 接口数据就是一个标准的 Prometheus 监控指标格式,在本地访问9100端口返回值为相关的监控指标如下
$ curl http://localhost:9100/metrics
......
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 9
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.16.7"} 1
3)使用静态配置的方式在 Prometheus 配置中新增一个 node_exporter 的抓取任务,来采集这个节点的监控指标数据,配置文件如下所示内容:
- job_name: "es_node_exporter"
static_configs:
- targets: ["10.20.30.40:9100"]
4)配置好后重启prometheus,即可在prometheus web 上查询node_exporter相关指标



