简体   繁体   English

如何在zabbix中监视网卡链接状态

[英]How to monitor network card link status in zabbix

I need to monitor physical interfaces link status in zabbix, and wondering, if there an internal zabbix check for that, or i need to write my own. 我需要监视zabbix中的物理接口链接状态,并且想知道是否有内部zabbix检查,或者我需要自己编写。 If so, how to determine if there is cable plugged in network card, and there is an voltage in the interface. 如果是这样,如何确定网卡中是否插入电缆,以及接口中是否有电压。

So yes a UserParameter it is (even in Zabbix 3.0) and it's reasonably easy to setup, at least on modern Linux boxes. 因此,是一个UserParameter (即使在Zabbix 3.0中也是如此),并且至少在现代Linux机器上,它的设置相当容易。 By parametrizing the UserParameter (if you follow...), it's possible to define a single Parameter to support monitoring of multiple NICs; 通过参数化UserParameter(如果您遵循...),可以定义单个参数来支持监视多个NIC。 here's how: 这是如何做:

  1. On a target box, locate the agent's directory where UserParamter definitions are stored, smth like /etc/zabbix/zabbix_agentd.d/ 在目标框中,找到存储UserParamter定义的代理目录,如/etc/zabbix/zabbix_agentd.d/
  2. Create a new file for the definition or amend an existing one; 为定义创建一个新文件或修改现有文件; I did this: 我这样做:

     cat > /etc/zabbix/zabbix_agentd.d/userparameter_niclink.conf << EOF UserParameter=net.if.link[*],cat /sys/class/net/$1/carrier EOF 
  3. Restart the agent, eg: service zabbix-agent restart 重新启动代理,例如: service zabbix-agent restart
  4. In the Zabbix UI, create an Item against the host as follows: 在Zabbix UI中,针对主机创建一个Item,如下所示:
    • Type: Zabbix agent (active if appropriate). 类型: Zabbix代理(如果适用,请激活)。
    • Key: has the actual NIC to be monitored between brackets, eg: net.if.link[em1] , 密钥:在括号之间具有要监视的实际NIC,例如: net.if.link[em1]
    • Type of information: Numeric (unsigned); 信息类型:数字(无符号); Data type: Decimal 数据类型:十进制
    • Show Value: as "Service state" (displays them as "Up/Down") 显示值:显示为“服务状态”(显示为“上/下”)
    • Application: Network Interfaces 应用程序:网络接口

That's it; 而已; go to Latest data; 转到最新数据; wait 30 secs or so and your NIC state should start populating. 等待30秒左右,您的NIC状态应开始填充。 It might also be useful to define a Trigger against the Item to be alerted if the link goes down. 如果链接断开,针对要提醒的项目定义触发器可能也很有用。

Here are some other ways to detect a NIC link's state ; 这是检测NIC链接状态的其他一些方法 the above cat /sys/class/net/${nic}/carrier works well for me (Ubuntu 14.04 server, physical NIC). 上面的cat /sys/class/net/${nic}/carrier对我来说很好用(Ubuntu 14.04服务器,物理NIC)。

No, there is no such check. 不,没有这样的检查。 You can achieve it using UserParameter . 您可以使用UserParameter实现它。 As for how, depends on the OS that runs the agent. 至于如何,取决于运行代理的操作系统。 On linux you can use either mii-tool or ethtool to check periodically. 在Linux上,您可以使用mii-tool或ethtool进行定期检查。 Or you can do some scripting and connect to D-Bus if you use NetworkManager. 或者,如果您使用NetworkManager,则可以进行一些脚本编写并连接到D-Bus。 Or you can monitor the system logs, drivers usually log link detection to the kernel log. 或者您可以监视系统日志,驱动程序通常会将链接检测记录到内核日志。

On windows I have no idea. 在Windows上,我不知道。 Probably netsh or ipconfig with some findstr can get you on polling the status. 可能带有某些findstr的netsh或ipconfig可以使您轮询状态。 Or powershell. 或powershell。 Ask on serverfault, I bet you will have exact answers. 询问serverfault,我敢打赌您会得到确切的答案。

@sxc731 is right, there is no such existing item in net.if keys. @ sxc731是正确的, net.if密钥中没有这样的现有项目。

If you want to make this solution universal, you can use discovery rules for discovering network interfaces. 如果要使该解决方案通用,则可以使用发现规则来发现网络接口。 This will find all interfaces, also the virtual, bridge, etc. But you can use regular expressions to match only interfaces which are physical. 这将找到所有接口,还包括虚拟接口,桥接器等。但是您可以使用正则表达式仅匹配物理接口。 I was deploying this in my work with multiple OS on many servers. 我在多台服务器上的多个操作系统中部署了该软件。 Here is my approach: 这是我的方法:

  1. Create or use existing Zabbix template. 创建或使用现有的Zabbix模板。
  2. In Administration -> General menu, go to Regular Expressions and do the following: 管理->常规菜单中,转到正则表达式,然后执行以下操作:
    1. Add new regular expression Physical network interface discovery . 添加新的正则表达式Physical network interface discovery
    2. Use regular expression ^em[0-9]{1,}|p[0-9]{1,}p[0-9]{1,}|eth[0-9]{1,}|ens[0-9]{1,}$ . 使用正则表达式^em[0-9]{1,}|p[0-9]{1,}p[0-9]{1,}|eth[0-9]{1,}|ens[0-9]{1,}$
  3. Create a discovery rule to your template with key net.if.discovery . 使用net.if.discovery键为模板创建发现规则。
  4. Create filter with Macro {#PHYSNET} and regular expression @Physical network interface discovery . 使用宏{#PHYSNET}和正则表达式@Physical network interface discovery创建过滤器。
  5. Add item prototype with key net.if.link[{#PHYSNET}] and trigger if you need one. 使用键net.if.link[{#PHYSNET}]添加项目原型,并在需要时触发。
  6. Create UserParameter on Zabbix client servers (example at the end). 在Zabbix客户端服务器上创建UserParameter(最后是示例)。

There is one issue with using cat /sys/class/net/$1/carrier as UserParameter. 使用cat /sys/class/net/$1/carrier作为UserParameter有一个问题。 If network interface is down (eg. with ip link set eth0 down ), the result of cat command is Invalid Argument . 如果网络接口关闭(例如ip link set eth0 down ),则cat命令的结果为Invalid Argument

I personally use this one-liner for UserParameter: 我个人使用了这行代码作为UserParameter:

UserParameter=net.if.link[*], if [ $(cat /sys/class/net/$1/operstate) = "up" ]; then cat /sys/class/net/$1/carrier; else echo "0"; fi;

Resources: 资源:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM