Custom Zabbix Monitoring Scripts

Source: Internet
Author: User

1. Modify the configuration file/etc/zabbix/zabbix_agentd.conf on the client #为了方便这里是用yum安装的zabbix


Two places to change:

    1. (1) Unsafeuserparameters=1

    2. (2) userparameter=my.net.if[*],/usr/local/sbin/zabbix/net.sh $ #其中UserParameter用来自定义键值, the name can be customized, if you write a script with parameters, Then you need to add [*], this is a fixed notation, if the script does not have any parameters, then directly userparameter=my.net.if=my.net.if. The comma is followed by the path of the script we wrote, followed by the script to use the parameters, no parameters to write.


2. Scripting
Vim/usr/local/sbin/zabbix/net.sh #我随便写的一个简单的监控网卡流量的脚本

#!/bin/bash

Eth=$1

Io=$2

Net_file= "/proc/net/dev"

if [$io = = "in"]

Then

n_new= ' grep ' $eth ' $net _file|awk ' {print $} '

d_new= ' Date +%s '

If [-Z $n _new]

Then

echo "Not found $eth"

Exit

Fi


If [-f/tmp/$eth \_neti.log] # #neti表示输入流量, Neto indicates output traffic

Then

N_old= ' tail-1/tmp/$eth \_neti.log '

n=$[$n _new-$n _old]

D_old= ' tail-2/tmp/$eth \_neti.log|head-1 '

d=$[$d _new-$d _old]

If_net= ' echo ' $n/$d ' |BC ' # #求d_old到d_new时间段内每秒平均流量单位byte

Echo $if _net

echo $d _new >>/tmp/$eth \_neti.log

echo $n _new >>/tmp/$eth \_neti.log

Else

touch/tmp/$eth \_neti.log

Chown zabbix/tmp/$eth \_neti.log

echo $d _new >>/tmp/$eth \_neti.log

echo $n _new >>/tmp/$eth \_neti.log

echo "Please again try script"

Exit

Fi


elif [$io = = "Out"]

Then

n_new= ' grep ' $eth ' $net _file|awk ' {print $ A} '

d_new= ' Date +%s '

If [-Z $n _new]

Then

echo "Not found $eth"

Exit

Fi


If [-f/tmp/$eth \_neto.log]

Then

N_old= ' tail-1/tmp/$eth \_neto.log '

n=$[$n _new-$n _old]

D_old= ' tail-2/tmp/$eth \_neto.log|head-1 '

d=$[$d _new-$d _old]

If_net= ' echo ' $n/$d "|BC"

Echo $if _net

echo $d _new >>/tmp/$eth \_neto.log

echo $n _new >>/tmp/$eth \_neto.log

Else

touch/tmp/$eth \_neto.log

Chown zabbix/tmp/$eth \_neto.log

echo $d _new >>/tmp/$eth \_neto.log

echo $n _new >>/tmp/$eth \_neto.log

echo "Please again try script"

Exit

Fi


Else

If Grep-q "$eth" $net _file

Then

Echo 0

Else

echo "Not found $eth"

Fi

Fi


The idea of this 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, divided into and out. If the script executes every 1 minutes, the calculated traffic value is the flat value of 1 minutes. The script has two parameters the first is the name of the network card, such as: Eth0, the second is in or out is in or out of the traffic, the script can calculate the machine on all the network card traffic as long as the first parameter change Eth0,eth1,lo and so on. But it's a pity that the first run will automatically create a temporary file for the *net[io].log, the second run of the script to get the value, and of course you can manually create the file and write the timestamp but I don't think it's necessary.


3. Check if the script is available
Executing on the service side
Zabbix_get-s ip-p10050-k "My.net.if[eth0,out]" # #这个IP是客户端的ip

If you can return a numeric description, no problem.


4. Then configure the Zabbix inside the browser
Configure-to-host--and project--Create monitoring items
Name "Eth0_net_out" # #名字可以随意也可以写中文
Type default "Zabbix Agent"
Key value "My.net.if[eth0,out]"
Archive OK

Of course you can also add [eth0,in],[eth1,*] and so on to the monitoring item.


This article is from the Linux OPS blog, so be sure to keep this source http://zhumy.blog.51cto.com/11647651/1827906

Custom Zabbix Monitoring 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.