Zabbix monitoring external inspection script deployment-novice operation guide

The script was written last time, and an old colleague took a look at it in a few days, and then asked me to deploy it to the system. After all, I am a novice, so make a note.
1, First of all, I use Levi's zabbix monitoring system to operate. We must first consider that the script calling path for zabbix monitoring is cd /usr/local/zabbix/scripts/, where there are many active monitoring scripts.
Zabbix monitoring external inspection script deployment-novice operation guide
2. Enter the configuration file of zabbix, set the key value and configure the settings.
Vim usr/local/zabbix/etc/zabbix_agentd.conf After modifying the key values ​​and the parameters for script execution
Zabbix monitoring external inspection script deployment-novice operation guide
, remember to restart the agent, service zabbix_agentd restart
3, and create a new template on the zabbix monitoring system.
Zabbix monitoring external inspection script deployment-novice operation guide
Zabbix monitoring external inspection script deployment-novice operation guide
Follow the above configuration.
4. Then link the template to the host, and there will be data later.
5. When checking the data, this must be paid special attention. The conversion rate of bytes used by the linux system computing hardware to other units is 1000, while the conversion rate of our system is 1024. In other words, the disk size we see is the actual size of the physical disk. When I checked it, I thought it was a script error. Pay more attention.
Zabbix monitoring external inspection script deployment-novice operation guide
The storage conversion ratio of the system is 1000.
The problem is that the matching disk in the script is /dev/vba, and some disks are indeed /dev/sda. In fact, many systems are basically the same. Before monitoring the system, check the disk type of the system to modify the script. If you want to make a general version of the script, you can use if, then conditional statements to add a few more disk types to judge.
After all, the old colleague has experience, proposed an optimized script, and then changed it to this:
#!/bin/bash #Total
disk space size, byte unit
disk_total() {
d_t=$(fdisk -l | grep -oP'(?<=/dev/sd\S\W). '| awk'{print $3}'|awk'BEGIN{sum=0}{sum+=$1}END {print sum}')
echo -e "${d_t}"
} #Total
used disk size, unit 1k
disk_used() {
d_uk=$(df | awk'{print $3}' | grep [0-9] | awk 'BEGIN{sum=0}{sum+=$1}END{print sum}')
d_u=$((1000
d_uk))
echo -e "${d_u}"
} #Remaining
total space calculation
disk_free() {
d_t=$ (fdisk -l | grep -oP'(?<=/dev/sd\S\W). '| awk'{print $3}'|awk'BEGIN{sum=0}{sum+=$1}END{print sum }')
d_u=$(df | awk'{print $3}' | grep [0-9] | awk'BEGIN{sum=0}{sum+=$1}END{print sum}')
d_f=$[${ d_t}-d_u
1000]
echo -e "${d_f}"
}
case "$ 1" in
dt)
disk_total
;;
df)
disk_free
;;
du)
disk_used
;;
*)
echo "Usage: $0 {dt=disk_total}{df=disk_free}{du=disk_used}"
;;
esac
I think the script can be optimized, such as global variables, the beginning of the script Then optimize the matching rules, but I still have to do other projects, so it is enough to meet customer needs.
Although this is a small script to collect data, it is important to understand the working principle of zabbix external inspection, as well as the first operation. There are many things to pay attention to. I hope that a new big script can be collected in the future.

Guess you like

Origin blog.51cto.com/14483703/2546133