自10月份Zabbix发布5.2版本宣布兼容MODBUS和MQTT协议以来,我就有一种万物皆为我所监控的冲动,于是乎我开始了漫长的搜罗MODBUS的监控场景。
终于,我找到了一套优秀的MODBUS的设备,并且做了一套适配的模版,下面来详细讲讲我的实战过程与期间遇到的各种坑。如果你对我的文章感兴趣,请加入我们的QQ群:Zabbix研究院(QQ群:1107902496)
1、Zabbix 的modbus接口在哪里?
根据https://support.zabbix.com/browse/ZBXNEXT-6090发布的说明,我找到了agent2对modbus支持的相关说明。
那么,创建主机的时候,监控的接口选择肯定是Zabbix Agent/主动式的AGENT了。
2、Zabbix的Modbus模版怎么做?
于是乎我就创建了一个监控项寻找了一番。如下图:
3、这个modbus的键值,对应的参数,该怎么设置?
参照zabbix链接:https://www.zabbix.com/documentation/current/manual/appendix/items/modbus
Parameter | Description | Defaults | Example |
---|---|---|---|
endpoint | Protocol and address of the endpoint, defined as protocol://connection_string Possible protocol values: rtu, ascii (Agent 2 only), tcp Connection string format: with tcp - address:port with serial line: rtu, ascii - port_name:speed:params where 'speed' - 1200, 9600 etc 'params' - data bits (5,6,7 or 8), parity (n,e or o for none/even/odd), stop bits (1 or 2) | protocol: none rtu/ascii protocol: port_name: none speed: 115200 params: 8n1 tcp protocol: address: none port: 502 | tcp://192.168.6.1:511 tcp://192.168.6.2 tcp://[::1]:511 tcp://::1 tcp://localhost:511 tcp://localhost rtu://COM1:9600:8n ascii://COM2:1200:7o2 rtu://ttyS0:9600 ascii://ttyS1 |
slave id | Modbus address of the device it is intended for (1 to 247), see MODBUS Messaging Implementation Guide (page 23) tcp device (not GW) will ignore the field | serial: 1 tcp: 255 (0xFF) | 2 |
function | Empty or value of a supported function: 1 - Read Coil, 2 - Read Discrete Input, 3 - Read Holding Registers, 4 - Read Input Registers | empty | 3 |
address | Address of the first registry, coil or input. If 'function' is empty, then 'address' should be in range for: Coil - 00001 - 09999 Discrete input - 10001 - 19999 Input register - 30001 - 39999 Holding register - 40001 - 49999 If 'function' is not empty, the 'address' field will be from 0 till 65535 and used without modification (PDU) | empty function: 00001 non-empty function: 0 | 9999 |
count | Count of sequenced 'type' which will be read from device, where: for Coil or Discrete input the 'type' = 1 bit for other cases: (count*type)/2 = real count of registers for reading If 'offset' is not 0, the value will be added to 'real count' Acceptable range for 'real count' is 1:65535 | 1 | 2 |
type | Data type: for Read Coil and Read Discrete Input - bit for Read Holding Registers and Read Input Registers: int8 - 8bit uint8 - 8bit (unsigned) int16 - 16bit uint16 - 16bit (unsigned) int32 - 32bit uint32 - 32bit (unsigned) float - 32bit uint64 - 64bit (unsigned) double - 64bit | bit uint16 | uint64 |
endianness | Endianness type: be - Big Endian le - Little Endian mbe - Mid-Big Endian mle - Mid-Little Endian Limitations: for 1 bit - be for 8 bits - be,le for 16 bits - be,le | be | le |
offset | Number of registers, starting from 'address', the result of which will be discarded. The size of each register is 16bit (needed to support equipment that does not support random read access). | 0 | 4 |
4、我们根据以上的配置,做了数据中心机房的机柜门的开关探测、温湿度、PDU的监测、UPS、精密空调等监控。结合之前做的基础架构的监控。实现了统一监控管理的目标。
5、参考:基于MODBUS协议的PDU指标监控