MichelinMessi 2020-05-03
node-exporter它是使用go语言编写的收集器
使用文档:https://prometheus.io/docs/guides/node-exporter/
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.0-rc.0/node_exporter-1.0.0-rc.0.linux-amd64.tar.gz tar xf node_exporter-1.0.0-rc.0.linux-amd64.tar.gz -C /usr/local/ ln -s /usr/local/node_exporter-1.0.0-rc.0.linux-amd64/ /usr/local/node_exporter # 可以直接执行node_exporter程序启动服务 /usr/local/node_exporter/node_exporter
# vim /usr/lib/systemd/system/node_exporter.service [Unit] Description=https://prometheus.io [Service] Restart=on-failure ExecStart=/usr/local/node_exporter/node_exporter [Install] WantedBy=multi-user.target # systemctl daemon-reload # systemctl start node_exporter.service # 启动服务后监听端口9100 # netstat -lntp | grep node_export tcp6 0 0 :::9100 :::* LISTEN 2986150/node_export
前面已经配置了基于file_sd_configs的文件自动发现,所以添加完服务之后并不需要重启prometheus服务
[192-168-5-237 ~]# cd /usr/local/prometheus [192-168-5-237 prometheus]# vim sd_config/node.yml - targets: - 192.168.5.71:9100 labels: app: nginx [192-168-5-237 prometheus]# ./promtool check config prometheus.yml Checking prometheus.yml SUCCESS: 0 rule files found
在status中查看targets中能看到新添加的主机
# 磁盘使用率 100 - (node_filesystem_free_bytes{mountpoint="/",fstype=~"ext4|xfs"} / node_filesystem_size_bytes{mountpoint="/",fstype=~"ext4|xfs"} * 100) # cpu使用率 100 - (avg(irate(node_cpu_seconds_total{mode="idle"}[5m])) by (instance) * 100) # 内存使用率 100 - (node_memory_MemFree_bytes+node_memory_Cached_bytes+node_memory_Buffers_bytes) / node_memory_MemTotal_bytes * 100
5.1 查看node_exporter帮忙获取需要的参数选项
# ./node_exporter --help --collector.systemd # Enable the systemd collector (default: disabled). --collector.systemd.unit-whitelist=".+" # Regexp of systemd units to whitelist. Units must both match whitelist and not match blacklist to be included.
5.2 修改node_exporter服务启动参数(监控sshd和nginx服务)
# cat /usr/lib/systemd/system/node_exporter.service [Unit] Description=https://prometheus.io [Service] Restart=on-failure ExecStart=/usr/local/node_exporter/node_exporter --collector.systemd --collector.systemd.unit-whitelist=(sshd|nginx).service [Install] WantedBy=multi-user.target # systemctl daemon-reload # systemctl restart node_exporter.service
# ps aux | grep node
root 2993957 0.2 0.5 115760 10216 ? Ssl 20:46 0:00 /usr/local/node_exporter/node_exporter --collector.systemd --collector.systemd.unit-whitelist=(sshd|nginx).service
5.3 查看prometheus端是否成功