2、node_exporter包部署、暴露抓取prometheus server本机指标
  XsWF2uh32RxR 2023年11月13日 37 0
node_exporter默认暴露了本地的哪些数据可在此网址查看:

github.com/prometheus/node_exporter

node_exporter默认并没有收集所有的指标,默认哪些启用哪些没启用可以到github.com/prometheus/node_exporter获取

默认启用的在:Enabled by default   #如果这些不想启用,就得--no-collector.<name>禁用
默认禁用的在:Disabled by default  #如果这些想启用,就得--collector.<name>启用

启用某一个collector:使用--collector.<name>
禁用某一个collector:使用--no-collector.<name>
下载安装node_exporter
[root@ubuntu2004 ~]#curl -LO https://github.com/prometheus/node_exporter/releases/download/v1.4.0/node_exporter-1.4.0.linux-amd64.tar.gz

[root@ubuntu2004 ~]#tar xf node_exporter-1.4.0.linux-amd64.tar.gz -C /usr/local/
[root@ubuntu2004 ~]#cd /usr/local/

[root@ubuntu2004 local]#ln -s node_exporter-1.4.0.linux-amd64/ node_exporter

[root@ubuntu2004 local]#cd node_exporter 
[root@ubuntu2004 node_exporter]#ls
LICENSE  node_exporter  NOTICE

启动node_exporter,除了默认暴露的指标,额外增加暴露指标,使用--collertor.<name>暴露。
[root@ubuntu2004 node_exporter]#./node_exporter --collector.ntp --collector.tcpstat --no-collector.zfs
ts=2022-11-22T02:29:14.368Z caller=node_exporter.go:182 level=info msg="Starting node_exporter" version="(version=1.4.0, branch=HEAD, revision=7da1321761b3b8dfc9e496e1a60e6a476fec6018)"
ts=2022-11-22T02:29:14.368Z caller=node_exporter.go:183 level=info msg="Build context" build_context="(go.....
.....

开机自启  
[root@ubuntu2004 prometheus]#chown -R prometheus. /usr/local/node_exporter

指定node_exporter要暴露的指标(除了默认之外的,用'--collector.<name>'增加)
[root@ubuntu2004 local]#vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target

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

[Install]
WantedBy=multi-user.target

[root@ubuntu2004 local]#systemctl daemon-reload 
[root@ubuntu2004 local]#systemctl enable --now node_exporter.service 
[root@ubuntu2004 local]#systemctl status node_exporter.service 


#验证监听的端口,并测试访问其暴露的指标
[root@ubuntu2004 local]#ss -ntlp
State  Recv-Q  Send-Q   Local Address:Port   Peer Address:Port Process                                    
LISTEN 0       4096     127.0.0.53%lo:53          0.0.0.0:*     users:(("systemd-resolve",pid=736,fd=13)) 
LISTEN 0       128            0.0.0.0:22          0.0.0.0:*     users:(("sshd",pid=769,fd=3))             
LISTEN 0       4096                 *:9100              *:*     users:(("node_exporter",pid=41237,fd=7))  
LISTEN 0       128               [::]:22             [::]:*     users:(("sshd",pid=769,fd=4))             
LISTEN 0       4096                 *:9090              *:*     users:(("prometheus",pid=1311,fd=7))      

查看本机暴露的指标
http://prometheus.fanchao.com:9100/metrics 可查看peomQL帮助
node_exporter暴露了指标,在prometheus上进行收集
基于静态服务发现监控node_exporter(可用基于文件的服务发现代替)
[root@ubuntu2004 prometheus]#vim prometheus.yml
......
  - job_name: "node_exporter"    #在scrape_configs字段中添加job
    metrics_path: '/metrics'     #获取指标的路径如果不是标准的'/metrics'路径,就指定
    scheme: 'http'               #协议
    static_configs:              #使用静态服务发现的方式纳入到监控中来
      - targets:                 #指定被监控的端点
          - "10.0.0.106:9100"
          - "10.0.0.100:9100"   #如果100主机没有node_exporter,监控不到(需要安装node_exporter)

重载配置文件
(需要启用--web.enable-lifecycle接口才可以远程reload,在prometheus.service中已启用,./prometheus --help可查看启用信息)
[root@ubuntu2004 prometheus]#curl -XPOST http://localhost:9090/-/reload

prometheus server窗口出现信息
name=./prometheus.yml totalDuration=804.526µs db_storage=1.632µs remote_storage=1.744µs web_handler=460ns query_engine=1.461µs scrape=211.709µs scrape_sd=98.318µs notify=36.485µs notify_sd=18.073µs rules=2.664µs tracing=8.863µs
此时,打开http://prometheus.fanchao.com:9090/(因为10.0.0.100没有安装node_exporter,抓不到指标,此时它的up值就为0,显示DOWN状态)

2、node_exporter包部署、暴露抓取prometheus server本机指标_暴露prometheus所在节点指标

点击graph,输入up == 0,点击Execute可查看到有一个node_exportor处于down状态,满足条件,就应该告警了。因此每一个实例上都有一个指标叫up,用来标识当前实例是否处于正常工作状态。

查看prometheus server所在主机暴露的指标
http://prometheus.fanchao.com:9100/metrics

根据以上暴露信息,可以在prometheus的web ui上使用指标名+过滤条件进行过滤

如下:

查看磁盘的读取数据(默认15秒收集一次)

2、node_exporter包部署、暴露抓取prometheus server本机指标_node_exporter包部署_02


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月13日 0

暂无评论

XsWF2uh32RxR