Monitoring items in the form of zabbix custom variables passing parameters
Sometimes when doing some custom monitoring items, there will be many monitoring items with the same command and different parameters. At this time, we can use the method of passing parameters to greatly reduce the number of lines in the configuration file.
1. The grammatical format of monitoring item parameter transfer
UserParameter=监控项key[*],命令 $1
2. Monitor tcp11 states by passing parameters
2.1. Writing configuration files
1.编写配置文件
[root@192_168_81_220 ~]# cd /etc/zabbix/zabbix_agentd.d/
[root@192_168_81_220 zabbix_agentd.d]# vim tcp2.conf
UserParameter=tcp_status[*],netstat -anpt | grep -c "$1"
配置文件解读:tcp_status表示监控项key,[*]表示传参接收,后面的$1是传的参数
2.重启zabbix-agent
[root@192_168_81_220 zabbix_agentd.d]# systemctl restart zabbix-agent
3.测试监控项
[root@zabbix-server ~]# zabbix_get -s 192.168.81.220 -k tcp_status[ESTABLISHED]
4
2.2. Create a monitoring template
2.3. Create monitoring items
Name: Number of ESTABLISHED states
Key-value: tcp_status[ESTABLISHED]
Application set: tcp 11 status
Other creations are consistent, just modify the variable value of the passed parameter
You can click on the clone below to save effort
All monitoring items are created
2.4. Link the template just created
Click to select first-click to add
Update
2.5. Check whether to get data
Click Monitoring—Latest Data—Select Host—Select Application Set