before writing an article mainly introduces the construction of Zabbix use http://msiyuetian.blog.51cto.com/8637744/1705396
This article mainly introduces the script implementation of Zabbix custom monitoring network card traffic
Pre-preparation
1. Description
Server ip:192.168.0.115
Client ip:192.168.0.114
2. Open Service
Because previously built Zabbix environment, here will not repeat, directly open the service side of the required services:
[[email protected] ~]#/etc/init.d/httpd start
[[email protected] ~]#/etc/init.d/mysqld start
[[email protected] ~]#/etc/init.d/zabbix-server start
[[email protected] ~]#/etc/init.d/zabbix-agent start
then enter in the browser: Http://192.168.0.115/zabbix , enter the user name password and verify login to the Zabbix main interface.
The client also opens the Zabbix-agent service:
[[email protected] ~]#/etc/init.d/zabbix-agent start
The following commands are executed on the client
1. Modify the configuration file
[[email protected] ~]# vim/etc/zabbix/zabbix_agentd.conf//Change two places
Unsafeuserparameters=1 Userparameter=my.net.if[*],/usr/local/sbin/zabbix/net.sh |
description : Userparameter used to customize the key value, (similar to net.if.in), their own script will often have parameters, so need to add, this is a fixed notation, if the script does not have any parameters, then this is saved. After the comma is the path of the script we wrote, and then the parameters to use, there are a few to write a few.
2. Writing scripts
[Email protected] ~]# Mkdir/usr/local/sbin/zabbix
[Email protected] ~]# vim/usr/local/sbin/zabbix/net.sh
#!/bin/bash Eth=$1 Io=$2 Net_file= "/proc/net/dev" if [$ = = "in"] Then n_new= ' grep ' $eth ' $net _file|awk ' {print $} ' n_old= ' Tail-1/tmp/neti.log ' N= ' echo ' $n _new-$n _old "|BC" d_new= ' Date +%s ' d_old= ' Tail-2/tmp/neti.log|head-1 ' D= ' echo ' $d _new-$d _old "|BC" If_net= ' echo ' $n/$d "|BC" Echo $if _net Date +%s>>/tmp/neti.log grep "$eth" $net _file|awk ' {print $} ' >>/tmp/neti.log elif [$ = = "Out"] Then n_new= ' grep ' $eth ' $net _file|awk ' {print $ A} ' n_old= ' Tail-1/tmp/neto.log ' N= ' echo ' $n _new-$n _old "|BC" d_new= ' Date +%s ' d_old= ' Tail-2/tmp/neto.log|head-1 ' D= ' echo ' $d _new-$d _old "|BC" If_net= ' echo ' $n/$d "|BC" Echo $if _net Date +%s>>/tmp/neto.log grep "$eth" $net _file|awk ' {print $ >>/tmp/neto.log} ' Else Echo 0 Fi |
Description : The idea of the script is to calculate the real-time network card traffic by looking at the value inside the file/proc/net/dev, in fact, I calculate is an average. into and out. If the script executes every 1 minutes, the calculated traffic value is the average of 1 minutes.
3. Modify Permissions
[Email protected] ~]# chmod a+x/usr/local/sbin/zabbix/net.sh
4, the operation before the execution of the script
[Email protected] ~]# Touch/tmp/net[io].log
[Email protected] ~]# date +%s >>/tmp/neti.log
[[email protected] ~]# grep eth0/proc/net/dev |awk ' {print $} ' >>/tmp/neti.log
[Email protected] ~]# date +%s >>/tmp/neto.log
[[email protected] ~]# grep eth0/proc/net/dev |awk ' {print $} ' >>/tmp/neto.log
[Email protected] ~]# chown Zabbix/tmp/net[io].log
[Email protected] ~]#/etc/init.d/zabbix-agent restart
5. Execute script
[Email protected] ~]#/usr/local/sbin/zabbix/net.sh eth0 in//
[[email protected] ~]#/usr/local/sbin/zabbix/net.sh eth0 out
6. Check if the script is available (performed on the server)
[Email protected] ~]# zabbix_get-s 192.168.0.114-p10050-k "My.net.if[eth0,in]"
[Email protected] ~]# zabbix_get-s 192.168.0.114-p10050-k "My.net.if[eth0,out]"
7. Configure on the Zabbix Web page
First find the corresponding add host, here I use the previous article to do the experiment when the host, called the TPP, here only to modify the following:
Add Eth0_in:
Configuration--Hosts----Create item Name:eth0_net_in Type:zabbix Agent
Key:my.net.if[eth0,in] Update interval (in sec): 30
Save |
650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/76/41/wKioL1ZN9FDB85VbAAEik_2BRng103.jpg "title=" 4.jpg " alt= "Wkiol1zn9fdb85vbaaeik_2brng103.jpg"/>
Add Eth0_out:
Configuration--Hosts----Create item Name:eth0_net_out Type:zabbix Agent Key:my.net.if[eth0,out] Update interval (in sec): 30
Save |
650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M02/76/42/wKiom1ZN9BKx3hoNAAElA1rImys139.jpg "title=" 5.jpg " alt= "Wkiom1zn9bkx3honaaela1rimys139.jpg"/>
and then we're in Monitoring -- Latest data find the corresponding host name and see the corresponding project
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M02/76/41/wKioL1ZN8sqD4pEtAACYsjBYTnQ592.jpg "title=" 3.jpg " alt= "Wkiol1zn8sqd4petaacysjbytnq592.jpg"/>
You can also view the chart form by opening the graph on the right.
This article is from the "M April Days" blog, please be sure to keep this source http://msiyuetian.blog.51cto.com/8637744/1714873
Shell Programming "Zabbix custom monitoring network card traffic script"