Node Exporter 安装使用

node_exporter 主要用于 *NIX 系统监控, 用 Golang 编写。

功能对照表

默认开启的功能

默认关闭的功能

将被废弃功能

注意:我们可以使用 --collectors.enabled 运行参数指定 node_exporter 收集的功能模块, 如果不指定,将使用默认模块。

程序安装和启动

二进制安装

我们可以到下载页面 选择对应的二进制安装包,下面我将以 0.14.0 作为例子,

  • 使用 wget 下载 Node Exporter

cd ~/Download
https://github.com/prometheus/node_exporter/releases/download/v0.14.0/node_exporter-0.14.0.linux-amd64.tar.gz
  • 使用 tar 解压缩 node_exporter-0.14.0.linux-amd64.tar.gz

cd ~/Prometheus
tar -xvzf ~/Download/node_exporter-0.14.0.linux-amd64.tar.gz
cd node_exporter-0.14.0.linux-amd64
  • 启动 Node Exporter

我们可以使用 ./node_exporter -h 查看运行选项,./node_exporter 运行 Node Exporter, 如果看到类似输出,表示启动成功。

INFO[0000] Starting node_exporter (version=0.14.0, branch=master, revision=840ba5dcc71a084a3bc63cb6063003c1f94435a6)  source="node_exporter.go:140"
INFO[0000] Build context (go=go1.7.5, user=root@bb6d0678e7f3, date=20170321-12:13:32)  source="node_exporter.go:141"
INFO[0000] No directory specified, see --collector.textfile.directory  source="textfile.go:57"
INFO[0000] Enabled collectors:                           source="node_exporter.go:160"
.....
INFO[0000] Listening on :9100                            source="node_exporter.go:186"

Docker 安装

我们可以使用 docker 镜像 安装,命令为:

docker run -d -p 9100:9100 \
  -v "/proc:/host/proc:ro" \
  -v "/sys:/host/sys:ro" \
  -v "/:/rootfs:ro" \
  --net="host" \
  quay.io/prometheus/node-exporter \
    -collector.procfs /host/proc \
    -collector.sysfs /host/sys \
    -collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"

当 Node Exporter 运行起来后,在浏览器中访问 http://IP: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"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0
. . .

数据存储

我们可以利用 Prometheus 的 static_configs 来拉取 node_exporter 的数据。

打开 prometheus.yml 文件, 在 scrape_configs 中添加如下配置:

- job_name: "node"
    static_configs:
      - targets: ["127.0.0.1:9100"]

重启加载配置,然后到 Prometheus Console 查询,你会看到 node_exporter 的数据。

Last updated