Monitor CPU, disk, and memory usage with the shell

Source: Internet
Author: User
Tags disk usage diskusage

Use the shell to monitor CPU, disk, memory usage, reach alert thresholds and email notifications

And with the task plan, you can get the alarm information in time

#!/bin/bash############################################## #Author: liuzhengwei - [email  Protected] #QQ: 1135960569#last modified: 2017-04-19 21:50#filename: jiankong.sh#description :  ############################################## #获取cpu使用率cpuUsage = ' Top -n 1 | awk  -F  ' [ %]+ '   ' nr==3 {print $2} ' #获取磁盘使用率data_name = '/dev/vda1 ' diskusage= ' df - h | grep  $data _name | awk -f  ' [ %]+ '   ' {print $5} ' logFile=/ tmp/jiankong.log# get memory situation mem_total= ' free -m | awk -f  ' [ :]+ '   ' NR==2{print  $2} ' mem_used= ' free -m | awk -f  ' [ :]+ '   ' nr==3{print $3} ' # Statistical memory Utilization mem_used_persent= ' awk  ' begin{printf  "%.0f\n", (' $mem _used '/' $mem _total ') *100} ' #获取报警时间now_time = ' date  ' +%f %t ' Function send_mail () {        mail  -s  "Monitoring Alarm"  [email&Nbsp;protected] < /tmp/jiankong.log}function check () {         if [[  "$cpuUsage"  > 80 ]] | |  [[  "$diskUsage"  > 80 ]] | |  [[  "$mem _used_persent"  > 80 ]];then                 echo  "Alarm Time: ${now_time}"  >  $logFile                 echo  " CPU Usage:${cpuusage}% -->  disk usage:${diskusage}% -->  memory usage: ${mem_used_persent}% "  >>  $logFile                  send_mail        fi}function main () {         check}main


This article is from the "burning Years of Passion" blog, please be sure to keep this source http://liuzhengwei521.blog.51cto.com/4855442/1917501

Monitor CPU, disk, and memory usage with the shell

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.