编程语言
首页 > 编程语言> > Prometheus之node exporter

Prometheus之node exporter

作者:互联网

一 下载node_exporter

root@k8s-master-01:~# wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz

二 安装node_exporter

root@k8s-master-01:~# tar xf node_exporter-1.2.2.linux-amd64.tar.gz -C /usr/local/
root@k8s-master-01:~# ln -sv /usr/local/node_exporter-1.2.2.linux-amd64/ /usr/local/node_exporter
'/usr/local/node_exporter' -> '/usr/local/node_exporter-1.2.2.linux-amd64/'

三 验证安装版本

root@k8s-master-01:~# /usr/local/node_exporter/node_exporter --version
node_exporter, version 1.2.2 (branch: HEAD, revision: 26645363b486e12be40af7ce4fc91e731a33104e)
  build user:       root@b9cb4aa2eb17
  build date:       20210806-13:44:18
  go version:       go1.16.7
  platform:         linux/amd64

四 创建node-exporter.service文件

root@k8s-master-01:~# cat /lib/systemd/system/node-exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io
After=network.target

[Service]
type=simple
ExecStart=/usr/local/node_exporter/node_exporter --collector.ntp --collector.mountstats --collector.systemd --collector.tcpstat
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
Restart=always


[Install]
WantedBy=multi-user.target

五 node-exporter开机启动

点击查看代码
root@k8s-master-01:~# systemctl enable node-exporter
Created symlink /etc/systemd/system/multi-user.target.wants/node-exporter.service → /lib/systemd/system/node-exporter.service.

root@k8s-master-01:~# systemctl start node-exporter
root@k8s-master-01:~# systemctl status node-exporter
● node-exporter.service - node_exporter
     Loaded: loaded (/lib/systemd/system/node-exporter.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-11-16 14:54:04 CST; 2s ago
       Docs: https://prometheus.io
   Main PID: 270390 (node_exporter)
      Tasks: 4 (limit: 2245)
     Memory: 2.6M
     CGroup: /system.slice/node-exporter.service
             └─270390 /usr/local/node_exporter/node_exporter --collector.ntp --collector.mountstats --collector.systemd --collector.tcpstat

Nov 16 14:54:04 k8s-master-01 node_exporter[270390]: level=info ts=2021-11-16T06:54:04.882Z caller=node_exporter.go:115 collector=thermal_zone
Nov 16 14:54:04 k8s-master-01 node_exporter[270390]: level=info ts=2021-11-16T06:54:04.882Z caller=node_exporter.go:115 collector=time
Nov 16 14:54:04 k8s-master-01 node_exporter[270390]: level=info ts=2021-11-16T06:54:04.882Z caller=node_exporter.go:115 collector=timex
Nov 16 14:54:04 k8s-master-01 node_exporter[270390]: level=info ts=2021-11-16T06:54:04.882Z caller=node_exporter.go:115 collector=udp_queues
Nov 16 14:54:04 k8s-master-01 node_exporter[270390]: level=info ts=2021-11-16T06:54:04.882Z caller=node_exporter.go:115 collector=uname
Nov 16 14:54:04 k8s-master-01 node_exporter[270390]: level=info ts=2021-11-16T06:54:04.882Z caller=node_exporter.go:115 collector=vmstat
Nov 16 14:54:04 k8s-master-01 node_exporter[270390]: level=info ts=2021-11-16T06:54:04.882Z caller=node_exporter.go:115 collector=xfs
Nov 16 14:54:04 k8s-master-01 node_exporter[270390]: level=info ts=2021-11-16T06:54:04.882Z caller=node_exporter.go:115 collector=zfs
Nov 16 14:54:04 k8s-master-01 node_exporter[270390]: level=info ts=2021-11-16T06:54:04.882Z caller=node_exporter.go:199 msg="Listening on" address=:9100
Nov 16 14:54:04 k8s-master-01 node_exporter[270390]: level=info ts=2021-11-16T06:54:04.883Z caller=tls_config.go:191 msg="TLS is disabled." http2=false

六 访问node-exporter web界面

七 Prometheus采集node指标数据

7.1 修改Prometheus.yml文件

root@prometheus-01:~# cat /usr/local/prometheus/prometheus.yml 

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["192.168.174.103:9090"]
  - job_name: "prometheus-node"
    static_configs:
      - targets: ['192.168.174.100:9100']

7.2 重启Prometheus服务

root@prometheus-01:~# systemctl restart prometheus

7.3 登录Prometheus web界面验证node节点状态

7.4 Prometheus 验证node节点监控数据

八 Node Exporter的指标

GitHub地址:https://github.com/prometheus/node_exporter

8.1 node-exporter启动内置指标

/usr/local/node_exporter/node_exporter --collector.ntp --collector.mountstats --collector.systemd --collector.tcpstat

8.2 node-exporter禁用内置指标

/usr/local/node_exporter/node_exporter --no-collector.ntp --no-collector.mountstats --no-collector.systemd --no-collector.tcpstat

8.3 node-exporter常用指标

8.4 CPU使用率

每台主机cpu在5分钟内的平均使用率: (1-avg(irate(node_cpu_seconds_total{mode='idle'}[5m]))by(instance))*100

8.5 CPU 饱和度

跟踪CPU的平均负载就能获取到相关主机的CPU饱和度,实际上,它是将主机上的CPU数据考虑在内的一段时间内的平均运行队列长度。

平均负载少于cpu的数量是正常情况,而长时间内超过cpu数量则表示cpu已然饱和;

8.6 内存使用率

标签:node,exporter,54,Prometheus,01,k8s,collector
来源: https://www.cnblogs.com/wangguishe/p/15561275.html