该项目是在官方主分支202ecf9
基础上进行定制,主要为我们从open-falcon迁移到Prometheus监控平台中端口以及URL监控策略适应而进行的二次开发。
对于发布版本预编译的二进制是可用的,下载方式如下,可参考releases
wget https://github.com/jwping/node_exporter/releases/download/v0.0.1/node_exporter
---or---
curl -o node_exporter https://github.com/jwping/node_exporter/releases/download/v0.0.1/node_exporter
./node_exporter <flags>
- GO环境
- RHEL/CentOS:
glibc-static
依赖.
这里编译可以直接go build
或者是使用官方的make
注意,如果使用官方的方式来进行编译的话,需要安装有
golangci-lint
go get github.com/jwping/node_exporter
cd ${GOPATH-$HOME/go}/src/github.com/prometheus/node_exporter
# go build
# make
./node_exporter <flags>
make test
该node_exporter
设计用于监控主机系统。不建议将其部署为Docker容器,因为它需要访问主机系统。请注意,您要监视的所有非root挂载点都需要绑定挂载到容器中。如果启动用于宿主机监视的容器,请指定path.rootfs
参数。此参数必须与主机/
中挂载安装的路径匹配。node_exporter将 path.rootfs
用作访问主机文件系统的前缀。
docker run -d \
--net="host" \
--pid="host" \
-v "/:/host:ro,rslave" \
quay.io/prometheus/node-exporter \
--path.rootfs=/host
在某些系统上,timex
收集器需要附加的Docker标志: --cap-add=SYS_TIME
才能访问所需的syscall。
新增collector/port_checking.go
需要在Prometheus上配置params:
params:
portlist:
- 127.0.0.1:22
- :9100
上列配置相当于告诉Prometheus在请求该Target时附带URL参数,如下:
http://192.168.14.130:9100/metrics?portlist=127.0.0.1:22&&portlist=:9100
node_export接收到附加portlist
参数的请求后,会使用probeTCP
函数对目标端口的连通性进行采集,具体源码实现请参考collector/port_checking.go#L29行。
新增http_checking.go
基本同上,需要在Prometheus上配置params:
params:
httplist:
- https://www.baidu.com
- https://aliyun.com
上列配置相当于告诉Prometheus在请求该Target时附带URL参数,如下:
http://192.168.14.130:9100/metrics?httplist=https://www.baidu.com&&httplist=https://aliyun.com
node_export接收到附加httplist
参数的请求后,会使用probeHTTP
函数对目标端口的连通性进行采集,具体源码实现请参考collector/http_checking.go#L29行。
node_export.go
// L75新增url参数解析,用于http、port参数获取
...
# HELP port_connectivity_detection Running on each node
# TYPE port_connectivity_detection gauge
port_connectivity_detection{port="127.0.0.1:22"} 1
port_connectivity_detection{port=":9100"} 1
...
# HELP http_connectivity_detection Running on each node
# TYPE http_connectivity_detection gauge
http_connectivity_detection{http="https://aliyun.com",httpStatusCode="200"} 399
http_connectivity_detection{http="https://www.baidu.com",httpStatusCode="200"} 130
...
另请注意,URL请求的超时时间为3秒,返回数据的耗时单位为毫秒