Nagios Monitoring Server remaining memory

Source: Internet
Author: User

Linux system memory mechanism: In Linux there is such a thought, the memory is not white, so it as far as possible cache and buffer some data to facilitate the next use. But in fact, the memory is also available for immediate use. So free memory =free+buffers+cached

#!/bin/bash  usage= "' Basename $0 '  [-w|--warning]<percent free> [-c|-- Critical]<percent free> "  threshold_usage=" warning threshold must be  greater than critical:  ' basename $0 '  $* '   calc=/tmp/memcalc   Percent_free=/tmp/mempercent  critical= "  warning=" "  STATE_OK=0   State_warning=1  state_critical=2  state_unknown=3  # print usage   if [ $# -lt 4 ]; then      echo  " "      echo " wrong syntax:  ' basename $0 '  $* "       echo  ""       echo  "usage:  $USAGE"       echo  ""       exit 0  fi   # read input&Nbsp; while [ $# -gt 0 ]  do      case   "$"  in          -w|--warning)                shift               warning=$1               ;;           -c|--critical)                shift               critical=$1               ;;       esac      shift  done       # verify input  if [[  $warning -eq  $critical  | |   $warning  -lt  $critical  ]]; then      echo  ""       echo  "$THRESHOLD _usage"       echo  "      echo " usage:  $USAGE "      echo   ""       exit 0  fi  # total memory  available  total= ' free -m | head -2 |tail -1 |gawk  ' { print $2} '   # total memory used  used= ' Free -m | head  -3 |tail -1 |awk  ' {print $3} '   # calc total minus  used  free= ' free -m | head -3 |tail -1 |awk  ' {print  $4} '   # normal values   #echo   $total mb total  #echo   $used mb used   #echo   $free mb free  # make it  into % percent free =  ((FREE&NBSP;MEM&NBSP;/&NBSP;TOTAL&NBSP;MEM)  * 100)   echo  "5"  >  $calc  # decimal accuracy  echo  "K"  >>  $calc  # commit  echo  "+"  >>  $calc  #  multiply  echo  "$free"  >>  $calc  # division integer   echo  "$total"  >>  $calc  # division integer  echo  "/"   >>  $calc  # division sign  echo  "*"  >>  $calc  #  multiplication sign  echo  "P"  >>  $calc  # print   Percent= '/usr/bin/dc  $calc |/bin/sed  ' s/^\./0./' |/usr/bin/tr  '. "   " " |/usr/bin/gawk {' print $1 '} '  &nbsp: #percent1 = '/usr/bin/dc  $calc '    #echo   ' $percent 1   if [[  ' $percent " -le   $critical  ]];  then      echo " critical -  $free  MB  ($percent%)  free memory "       exit 2  fi  if [[  "$percent"  -le   $warning  ]];  then      echo  "warning -  $free  MB  ($percent%)   Free memory "      exit 1  fi  if [[ " $ Percent " -gt   $warning  ]]; then      echo " OK  -  $free  MB  ($percent%)  free memory "      exit  0  fi


This article is from the "Smurf Linux ops" blog, so be sure to keep this source http://jin771998569.blog.51cto.com/2147853/1636439

Nagios Monitoring Server remaining memory

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.