3.4-zabbix Custom Scripts

Source: Internet
Author: User

Custom Zabbix Scripts

1. Modify the configuration file/etc/zabbix/zabbix_agentd.conf the client and then restart the service

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 [*] will be 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. Scripting

vi/usr/local/sbin/zabbix/net.sh//content is as follows


Eth=$1 #定义网卡名

Io=$2 #定义进或者出流量

Net_file= "/proc/net/dev" #流量的来源, can self-cat/proc/net/dev a bit, the total traffic after the boot.

if [$ = = "in"] #接上, the flow of a certain period is obtained by the difference between different time periods.


n_new= ' grep ' $eth ' $net _file|awk ' {print $} ' #得出指定网卡的receive总值

n_old= ' tail-1/tmp/neti.log ' #查看上一次网卡的receive总值

N= ' echo ' $n _new-$n _old "|BC" #得出2次的receive差值

d_new= ' Date +%s ' #定义新的时间戳

d_old= ' Tail-2/tmp/neti.log|head-1 ' #定义上一次的时间戳

D= ' echo ' $d _new-$d _old "|BC" #得出2次间隔的时间差

If_net= ' echo ' $n/$d ' |BC ' #receive差值除以时间差 to get the average flow value

echo $if _net #显示得的出平均流量值

Date +%s>>/tmp/neti.log #追加新的时间戳

grep "$eth" $net _file|awk ' {print $} ' >>/tmp/neti.log #追加新的receive总值

elif [$ = = "Out"]


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} '


Echo 0


The idea of this script is to calculate the real-time network card traffic by looking at the values in the file/proc/net/dev, in fact, I calculate an average. into and out. If the script executes every 1 minutes, the calculated traffic value is the average of 1 minutes.

3. Before the script executes, you need to do an operation first

Touch/tmp/net[io].log #有的SHELL不支持 [] This command, related to version

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

#次脚本有缺陷, because the log file is for only one network card, an error occurs if you change the network card. Requires different network cards, corresponding to different logs.

4. Check if the script is available

Executing on the service side

Zabbix_get-s "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 60


3.4-zabbix Custom Scripts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.