Go Linux disk space Monitoring alarm

Source: Internet
Author: User
Tags disk usage

Linux disk space Monitoring alarm

Original: http://www.cnblogs.com/kerrycode/p/3415242.html

Linux systems need to monitor the use of each partition of the disk, to avoid a variety of unexpected situations, resulting in the depletion of disk space, such as a partition by the Oracle's archive log exhausted, resulting in the subsequent log files can not be archived, the Oracle database error occurs. Monitoring the use of disk space, there are many tools, such as Nagios, in fact, the simplest is the use of shell scripts. Here's how to monitor and alert disk space with shell scripts and crontab jobs.

General view the usage of each partition of the disk can be viewed through the DF command, there are two shell scripts to get the percentage of disk usage online.

1:df-h | Grep/dev | awk ' {print $} ' | Cut-f 1-d "%"

2:df-h | Grep/dev | awk ' {print $} ' | Sed ' s/%//g '

However, these two commands still have some bugs, such as the following: When the display is too long, it causes the line to break. At this point, the shell script above cannot get its value.

Especially in some special cases, it's impossible to get the data exactly.

Just a little bit of tweaking on the parameters.

1:df-p | Grep/dev | awk ' {print $} ' | Cut-f 1-d "%"

2:df-p | Grep/dev | awk ' {print $} ' | Sed ' s/%//g '

The following script is used to monitor the usage of each partition, when the threshold is exceeded (the default is 90%), send a warning message, notify the administrator to timely processing.

#*************************************************************************# Filename:disk_capatiy_ala rm.sh #*************************************************************************# author:kerry# Cr                               eatedate:2013-11-07# description:this script is mointoring the Linux disk# capacity, if disk used more than 90%,# then it'll send a alarm email#** ***********************************************************************#! /bin/bashemail_content= "/home/oracle/scripts/output/disk_sendmail.pl" email_logfile= "/home/oracle/scripts/ Output/diskdetail.txt "; cat/dev/null > ${email_content};cat/dev/null > ${email_logfile}; SendMail () {date_today= ' date +%y_%m_%d ' subject= "the server xxxxxx\ ' s Disk capacity Alarm" content= "Dear all, the server xx XX (xxx.xxx.xxx.xxx) disk capacity Alarm, please take action for it. Many thanks! " echo "#!/usr/bin/perl" >> ${Email_content}echo "Use Mail::sender;" >> ${email_content}echo "\ $sender = new Mail::sender {smtp =" xxx.xxx.xx X.xxx ', from = = ' [email protected] '}; ">> ${email_content}echo" \ $sender->mailfile ({to + = ' [email protected] ', ">> ${email_content} echo "cc=>" [email protected] ', ">> ${email_content}echo" subject = ' $subject ', ">> ${email_ Content}echo "msg = ' $content '," >> ${email_content}echo "file = ' ${email_logfile} ');" >> ${email_content}perl ${email_content}}for D in ' df-p | Grep/dev | awk ' {print $} ' | Sed ' s/%//g ' do if [$d-GT 90];           Then df-h >> $email _logfile;             SendMail;    Exit 0; Fidone

Go Linux disk space Monitoring alarm

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.