Zabbix custom script to monitor the configuration of the NIC

Source: Internet
Author: User


Note: To add custom script monitoring, you must upgrade the Zabbix Agent version to 2.0.0 or more,



One: Configuration steps


1. Finish writing the custom monitoring script (Windows or Linux scripts)

Script Requirements:

(1) since it is monitoring, it is necessary to have the output value (string, the number can be )

(2) Zabbix users must be required to have execution rights, of course, can directly set all users have Row permissions (chmod 777 script file)

(3) If the script needs to pass in parameters, in the order in which the parameters are passed in, $1-$9 can be used in the script to draw with the parameters passed in


2 Locate the Zabbix agent configuration file zabbix_agentd.conf, modify the following two parameters


unsafeuserparameters=0 = Unsafeuserparameters=1 and remove the previous comment character

userparameter= = userparameter=aaa.bbb[*],

/usr/local/script/monitor.sh ...


Description: aaa.bbb[*] The key value to use when adding monitoring information---The Zabbix server.

Format: aaa.bbb[*] (example: system.file.size[*])

/usr/local/script/monitor.sh----Monitoring Script absolute path

for flexible monitoring, sometimes scripts need to pass in parameters, which can be used from the Zabbix server side incoming, all parameters are represented sequentially from $1-$9


Attention:

(1) If no parameters are passed in, the red part can be omitted

(2) This custom script can be controlled by the Zabbix server for the frequency of data collection (for example: every 30s run once), no need to add a scheduled task


(3) The above parameters, please fill in according to the actual situation, and note to remove the parameter before the comment (#)


(4) Note that there is a comma between the key value and the script behind it.


At this point, the custom Monitoring script Zabbix agent end configuration


3. Testing


Test command:/usr/local/bin/zabbix_agentd-t key[parameter]

Example:/usr/local/bin/zabbix_agentd-t system.file.size


[/etc/a.txt,abc,...]



This article was transferred from http://www.linuxidc.com/Linux/2013-11/92476.htm





Two: Examples:

to calculate the average real-time NIC traffic, divided into and out. If the script executes every 1 minutes, the calculated traffic value is

Is the average of 1 minutes.


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 $ $


2. Scripting

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

}


3. 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


4. Check if the script is available

Executing on the service side

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

Archive




This article was transferred from http://www.apelearn.com/bbs/thread-8091-1-1.html




Zabbix custom script to monitor the configuration of the NIC

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.