Shell scripts monitor system load using the uptime command

Source: Internet
Author: User

#!/bin/bash#author:yanconggod#date:2017-01-19#version:1.0#  using  uptime  command to monitor system load postfix_path= "/usr /sbin/postfix "mailx_path="/usr/bin/mailx "email=" [email protected] "#  get native IP address ip= ' IFCONFIG ENP2S0 |grep  ' \binet\b ' |awk  ' {print $2} ' #  formatted time display date= ' date  ' +%y-%m-%d %h:%m ' #  Declare integer variable declare -i cpu_num loads ave#  get current host  CPU  core number cpu_num= ' Grep -c   ' model name '  /proc/cpuinfo ' #  get current system within 15 minutes  CPU  average load rate value (take single digit) loads= ' Uptime|awk   ' {print $10} ' |awk -f '. '   ' {print $1} ' #  calculates the average load rate for a single core within 15 minutes (( ave = Loads / CPU_NUM )) #  Take the single digit of the above calculation average= ' echo  $ave |awk -f  '. '   ' {print $1} ' #if  [ ! -f  $POSTFIX _path  -o ! -f  $MAILX _ PATH " ];thenyum install -y postfix mailx    systemctl start  postfix && systemctl enable postfixfi#  when single core 15-minute load rate value is higher than  1  send alert mail if [  $average  -gt 1  ];then  echo -e  "Alarm:  system load too high!!! \ n time:  $DATE \ n server ip:  $IP \ n Current load rate:  $Loads "    | mail -s " system load too high "  $Emailfi


This article is from "Zen Sword as" blog, please be sure to keep this source http://yanconggod.blog.51cto.com/1351649/1893161

Shell scripts monitor system load using the uptime command

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.