Prometheus监控AirNet服务器(node_exporter)
  YKMEHzdP8aoh 2023年11月19日 18 0

摘要:

node-exporter;Endpoint;


1、AirNet物理主机安装node-exporter服务;

[Unit]
Description=node_exporter
Documentation=https://github.com/prometheus/node_exporter
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/node_exporter  --collector.ntp  --collector.mountstats --collector.systemd  --collector.perf --collector.tcpstat
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
Restart=always
[Install]
WantedBy=multi-user.target

配置ServiceMonitor,通过Labels选择无头Service,没有selector的service不会出现Endpoint的信息,需要手工创建Endpoint绑定,Endpoint可以是内部的pod,下面是外部的服务,这里指定到要监控的AirNet物理主机的IP,一个Endpoints切片方式配置可以绑定多台物理服务器的IP

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: airnet-node-exporter
  namespace: monitoring
  labels:
    airnet: airnet-node-exporter
    namespace: monitoring
spec:
  jobLabel: airnet-app
  endpoints:
  - interval: 30s
    port: api
    scheme: http    
  namespaceSelector:
    matchNames:
    - monitoring
  selector:
    matchLabels:
      airnet: airnet-node-exporter
---
apiVersion: v1
kind: Service
metadata:
  labels:
    airnet: airnet-node-exporter
  name: airnet
  namespace: monitoring
spec:
  clusterIP: None
  clusterIPs:
  - None
  ports:
  - name: api
    port: 9100
    protocol: TCP
    targetPort: api
  type: ClusterIP 
---
kind: Endpoints
apiVersion: v1
metadata:
  name: airnet
  namespace: monitoring  
subsets:
  - addresses:
      - ip: 192.168.31.158
        nodeName: airnet-fdp1
      - ip: 192.168.31.184
        nodeName: airnet-acc-fdo1               
    ports:
      - port: 9100
        name: api
        protocol: TCP

问题:手动指定的外部Endpoints的IP地址过一段时间自动变为空值,导致Grafana监控无数据:

  • 原因是对于没有selector的service不会出现Endpoint的信息,需要手工创建Endpoint绑定,Endpoint可以是内部的pod,也可以是外部的服务。
  • 对于配置了selector的service,Service Controller会自动查找匹配这个selector的pod,并且创建出一个同名的endpoint对象,如果没有查找到匹配这个selector的pod,会出现自动创建的endpoint的IP地址为空的情况,因为与之前手工创建的外部Endpoint同名,覆写了手工创建Endpoint外部IP绑定,所以导致手工创建Endpoint绑定的外部IP没了。
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

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

暂无评论

推荐阅读
  4Txe79BjyroE   2023年12月08日   11   0   0 TCP
  Yoru5qB4TSKM   2023年12月10日   15   0   0 服务器重启IP
  ozzp9aSSE46S   2023年11月30日   21   0   0 DNSIPPod
  48fXx4UfWSFg   2023年12月06日   41   0   0 bcIPbundle
  pfb3gDAOHucg   2023年12月09日   19   0   0 TCP网络层协议UDP
  mjtHZIki74si   2023年12月06日   14   0   0 TCP重传
  aYmIB3fiUdn9   2023年12月08日   38   0   0 客户端IPNATlvs