1. Modify the configuration file on the client/etc/zabbix/zabbix_agentd.conf
Two places to change:
(1) Unsafeuserparameters=1
(2) userparameter=my.net.if[*],/usr/local/sbin/zabbix/net.sh $ #其中UserParameter用来自定义键值, (similar to net.if.in), The script you write will often have parameters, so you need to add, this is a fixed notation, if the script has no 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. Before the script executes, you need to do an operation first
touch/tmp/net[io].log#先创建两个时间段日志文件
Date +%s >>/tmp/neti.log
grep eth0/proc/net/dev |awk ' {print $} ' >>/tmp/neti.log
Date +%s >>/tmp/neto.log
grep eth0/proc/net/dev |awk ' {print $} ' >>/tmp/neto.log
chown Zabbix/tmp/net[io].log
3. Editing scripts
Mkdir/usr/local/sbin/zabbix
vi/usr/local/sbin/zabbix/net.sh//content is as follows
#!/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
4. Check if the script is available
executing on the service side
zabbix_get-s 10.10.13.247-p10050-k "My.net.if[eth0,out]"
5. If you can return a numeric explanation, then configure it in the browser
Configure-to-host--and project-- Create monitoring items
name "network card traffic out"
type Default "Zabbix Agent"
key value "My.net.if[eth0,out]"
Data Update Interval
Archive
This article is from the "愺 Burgundy pounding his 豩" blog, please be sure to keep this source http://riverxyz.blog.51cto.com/533303/1793194
Use Zabbix to customize monitoring scripts