Zabbix monitoring backup files with trapper

Source: Internet
Author: User

background:

There is a MySQL server in the production on a daily basis with the mysqldump command of the database logical backup, scheduled task execution time of 23:30, backup time of about 5 minutes, the resulting backup file name is ' mysql-$ (date +%y-%m- %d). sql ', size 3G or so, the backup file retains 3 copies, that is, after the mysqldump command was executed, the backup file was deleted the day before yesterday.

Demand:

Check and monitor backup files and trigger alarms If file production is abnormal.



1. Simulating production backup files

[[email protected] ~]# Cd/data/backup/[[email protected] backup]# dd If=/dev/zero of=mysql-2018-05-15.sql bs=1m count=10 00[[email protected] backup]# dd If=/dev/zero of=mysql-2018-05-16.sql bs=1m count=1000[[email protected] backup]# DD if=/ Dev/zero Of=mysql-2018-05-17.sql bs=1m count=1000



2. Monitoring script Writing

Script owner is Zabbix:zabbix, the script function is to check whether the previous day to produce backup files and determine the file size.

[[Email protected] script]# more file_check.sh #/bin/bashfile_path=/data/backupzabbix _sender=/usr/bin/zabbix_senderzabbix_server=172.27.9.63zabbix_agent=172.27.9.65ducheck () {date=$ (date -d   "Yesterday"  +%y-%m-%d) file= $file _path/mysql-$date. sqldu=$ (cd  $file _path &&  du -sm *|grep mysql-$date. sql|awk {' print $1 '}) if [[  $du  -ge 1000  ]]      #生产库每天都有新数据产生, the amount of backup is getting bigger then    echo 0else     ${ZABBIX_SENDER} -z ${zabbix_server} -s ${zabbix_agent} -k  file.check -o  "fail"  &> /dev/null    exit 1fi}sender () {if  [ $ (Ducheck)  -eq 0 ]then    ${zabbix_sender} -z ${ zabbix_server} -s ${zabbix_agent} -k file.check -o  "sucess"  &>  /dev/nullelse    return 0    fi}[ $# -eq 0 ] &&  sender | |  echo usage: $0


3. Create a new template

New template "File Check"


4. New Monitoring Item

New Monitor item "File status check" in template


5. Create a new Trigger


Return value triggers an alarm if it is fail


6. template-bound host

Bind host 172.27.9.65, visible as ' business system. Client Zabbix-test-centos7 '



7. View Inspection Results

Run the script to view the results of the execution, because the simulated backup file date is 15, 16, 173 days, execution will be error today

[Email protected] ~]# sh/etc/zabbix/script/file_check.sh



8. Writing timed Tasks

Daily 0 O'Clock 1 o'clock Execute file Check script

[[email protected] script]# crontab-l0 1 * * */etc/zabbix/script/file_check.sh &>/dev/null 2>&1


For the eighth step, if you do not want to push the monitoring message with a timed task, you can create a new monitoring item:

1. New Monitoring Item


2. Modify the configuration file

Modifying a configuration file zabbix_agentd.conf

[Email protected] zabbix]# View zabbix_agentd.confuserparameter=file.check.send,/etc/zabbix/script/file_check.sh

Restart Zabbix-agent Service

[Email protected] zabbix]# systemctl restart Zabbix-agent


Backup file Check monitoring complete


PS: thought of using built-in monitoring items ' vfs.file.exists[file] ', ' vfs.file.size[file ', ' vfs.file.time[file,<mode>] ' To directly monitor whether the file exists/size/build time, but the file name is not sure, the "key" in the monitoring item does not support the {DATE} and {time} built-in macros, so let go.


Zabbix monitoring backup files with trapper

Related Article

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.