node_exporter安装
node_exporter主要是用于监控宿主机的信息
项目地址https://github.com/prometheus/node_exporter
官方文档提示: node_exporter设计用于监控主机系统。不建议将其部署为Docker容器,因为它需要访问主机系统。请注意,您要监视的任何非根安装点都需要绑定到容器中。如果启动容器以进行主机监视,请指定path.rootfs参数。此参数必须与host root的bind-mount中的路径匹配。node_exporter将path.rootfs用作访问主机文件系统的前缀。
官方下载地址https://prometheus.io/download/#node_exporter
https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
tar xf node_exporter-1.5.0.linux-amd64.tar.gz
cd node_exporter-1.5.0.linux-amd64
mkdir -p /usr/local/node_exporter
mv node_exporter /usr/local/node_exporter/node_exporter
创建systemd服务
#创建prometheus用户
#useradd -s /sbin/nologin -m prometheuscat >>/etc/systemd/system/node_exporter.service<<EOF
[Unit]
Description=node_exporter
After=network.target[Service]
Type=simple
#User=prometheus
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure[Install]
WantedBy=multi-user.target
EOF
启动服务
在通过systemd启动之前我们先测试一下node_exporter是否正常,直接./usr/local/node_exporter/node_exporter运行成功即可
cd /usr/local/node_exporter/./node_exporter #启动level=info ts=2020-06-08T15:56:43.206Z caller=node_exporter.go:177 msg="Starting node_exporter"
level=info ts=2020-06-08T15:56:43.207Z caller=node_exporter.go:112 collector=zfs
...
...
...
level=info ts=2020-06-08T15:56:43.207Z caller=node_exporter.go:191 msg="Listening on" address=:9100
level=info ts=2020-06-08T15:56:43.207Z caller=tls_config.go:170 msg="TLS is disabled and it cannot be enabled on the fly." http2=false#直接执行没有问题,我们可以访问测一下。 需要单独在开通一个窗口进行curl,测试完毕以后通过ctrl -c结束node_exporter进程
# curl localhost:9100/metrics
...
go_memstats_alloc_bytes 1.256328e+06
#这里只要有数据即可
通过systemd进行管理
systemctl daemon-reload
systemctl enable node_exporter --now
systemctl status node_exporter
docker启动
docker run -d \--net="host" \--pid="host" \-v "/:/host:ro,rslave" \quay.io/prometheus/node-exporter:latest \--path.rootfs=/host
prom配置,我这里打了标签
- job_name: server #任务名称static_configs:- targets: ['172.24.177.167:9100']labels:project: "prometheus"environment: "prod"os: "linux"ip: '172.24.177.167'instance: '监控服务器'- targets: ['172.24.177.104:9100']labels:project: "VPN-FRP-Server"environment: "prod"os: "linux"ip: '172.24.177.104'instance: 'VPN服务器'
granfa监控模板 11074



