Prometheus Node Exporter 暴露了各种与硬件和内核相关的指标。
在本指南中,你将:
- 在
localhost上启动一个 Node Exporter - 在
localhost上启动一个 Prometheus 实例,配置为从运行中的 Node Exporter 抓取指标
NOTE: 虽然 Prometheus Node Exporter 适用于 *nix 系统,但对于 Windows 有 Windows exporter 提供类似的功能。
安装和运行 Node Exporter
Prometheus Node Exporter 是一个单独的静态二进制文件,可以通过 tarball 安装。从 Prometheus 下载页面下载后,解压并运行:
# NOTE: Replace the URL with one from the above mentioned "downloads" page.
# Node Exporter is available for multiple OS targets and architectures.
# Downloads are available at:
# https://github.com/prometheus/node_exporter/releases/download/v<VERSION>/node_exporter-<VERSION>.<OS>-<ARCH>.tar.gz
#
# <VERSION>, <OS>, and <ARCH> are placeholders:
# - <VERSION>: Release version (e.g., 1.10.2)
# - <OS>: Operating system (e.g., linux, darwin, freebsd)
# - <ARCH>: Architecture (e.g., amd64, arm64, 386)
#
# For this example, we will use Node Exporter version 1.10.2 for a Linux system with amd64 architecture.
wget https://github.com/prometheus/node_exporter/releases/download/v1.10.2/node_exporter-1.10.2.linux-amd64.tar.gz
tar xvfz node_exporter-1.10.2.linux-amd64.tar.gz
cd node_exporter-1.10.2.linux-amd64
./node_exporter
你应该看到类似以下的输出,表明 Node Exporter 正在运行并在端口 9100 上暴露指标:
INFO[0000] Starting node_exporter (version=0.16.0, branch=HEAD, revision=d42bd70f4363dced6b77d8fc311ea57b63387e4f) source="node_exporter.go:82"
INFO[0000] Build context (go=go1.9.6, user=root@a67a9bc13a69, date=20180515-15:53:28) source="node_exporter.go:83"
INFO[0000] Enabled collectors: source="node_exporter.go:90"
INFO[0000] - boottime source="node_exporter.go:97"
...
INFO[0000] Listening on :9100 source="node_exporter.go:111"
Node Exporter 指标
Node Exporter 安装并运行后,你可以通过 cURL 访问 /metrics 端点来验证指标是否正在被导出:
curl http://localhost:9100/metrics
你应该看到类似以下的输出:
# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 3.8996e-05
go_gc_duration_seconds{quantile="0.25"} 4.5926e-05
go_gc_duration_seconds{quantile="0.5"} 5.846e-05
# etc.
成功!Node Exporter 现在正在暴露 Prometheus 可以抓取的指标,包括输出中更后面的各种系统指标(以 node_ 为前缀)。要查看这些指标(以及帮助和类型信息):
curl http://localhost:9100/metrics | grep "node_"
配置 Prometheus 实例
你本地运行的 Prometheus 实例需要正确配置才能访问 Node Exporter 的指标。以下 prometheus.yml 示例配置文件将告诉 Prometheus 实例通过 localhost:9100 抓取 Node Exporter 的指标及其频率:
global:
scrape_interval: 15s
scrape_configs:
- job_name: node
static_configs:
- targets: ['localhost:9100']
要安装 Prometheus,请为你的平台下载最新版本并解压:
wget https://github.com/prometheus/prometheus/releases/download/v*/prometheus-*.*-amd64.tar.gz
tar xvf prometheus-*.*-amd64.tar.gz
cd prometheus-*.*
Prometheus 安装后,你可以使用 --config.file 标志启动它,指向你上面创建的 Prometheus 配置:
./prometheus --config.file=./prometheus.yml
通过 Prometheus 表达式浏览器浏览 Node Exporter 指标
现在 Prometheus 正在从运行中的 Node Exporter 实例抓取指标,你可以使用 Prometheus UI(也称为表达式浏览器)来浏览这些指标。在浏览器中导航到 localhost:9090/graph,使用页面顶部的主表达式栏来输入表达式。表达式栏看起来像这样:

Node Exporter 特有的指标以 node_ 为前缀,包括 node_cpu_seconds_total 和 node_exporter_build_info 等指标。
点击下面的链接查看一些示例指标:
| 指标 | 含义 |
|---|---|
rate(node_cpu_seconds_total{mode="system"}[1m]) |
最近一分钟内,每秒花费在系统模式下的平均 CPU 时间(以秒为单位) |
node_filesystem_avail_bytes |
非 root 用户可用的文件系统空间(以字节为单位) |
rate(node_network_receive_bytes_total[1m]) |
最近一分钟内,每秒接收的平均网络流量(以字节为单位) |