Linux Monitoring system resources-memory

Source: Internet
Author: User
Tags memory usage

Monitor memory usage:

Idea: Use Free-m to extract the relevant data, calculate the amount of memory input to the file, and each calculation is compared with the data in the current file, larger than the data in the file is replaced. Keep the maximum memory usage for the day and send mail each day (you can write a separate script for sending messages). the script can be written to the scheduled task for how long it takes to execute. You can also add a wheel loop background start in the script

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/84/27/wKiom1eHFvPj-SG3AAAY0P_tIgA293.png "title=" Free.png "alt=" Wkiom1ehfvpj-sg3aaay0p_tiga293.png "/>

Total of MEM lines: Overall system memory

-/+ Buffers/cache Line used: actual use of memory

-/+ Buffers/cache Line of free: program actually callable memory



#!/bin/bashpath=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.7.0_45/bin:/usr/ java/jdk1.7.0_45/jre/bin:/usr/local/ccdtsoft/mvn_maven/bin:/root/bindays= ' date + '%Y%m%d "' freeDATE= ' date  + "%y-%m-%d--%h:%m:%s" ' data_path=/usr/local/ccdtsoft/data/bulldog/count/${days}file= ' hostname ' _ maxfree.txt# Total Memory total= ' free -m|grep mem|awk  ' {print $2} ' #free  -m  second row of user, Actual memory used= ' free -m|grep buffers/cache|awk  ' {print $3} ' #free  -m  second row of free, The program can invoke the actual memory free= ' free -m|grep buffers/cache|awk  ' {print $4} ' #百分比USED/total (percentage of actual memory used) Usage_ b= ' awk  ' begin{printf  "%.2f%\n", (' $USED '/' $TOTAL ') *100} ' If [ ! -d ${data_path}  ];    then        mkdir -p ${data_ path}fi# for the first time every day   statistics to create a statistical file and enter the first value, the next time the value of the file in the comparison, if it is greater than the percentage of used memory output replace the file content, retain the largest memory usage data if [ ! - F ${data_path}/${file} ];        then             touch ${DATA_PATH}/${FILE}                         echo -e  "${file}\ n Maximum Memory Usage: ${date}\n total memory (m):  ${total}\n Memory actual usage (m):  ${used}\n memory percent Used (m):  ${usage_b}\n---\ n "  > ${DATA_PATH}/${FILE}                  #echo   "Actual memory usage (m):  ${used}"  >> ${DATA_PATH}/${FILE}                  #echo  % used memory ( m):  ${usage_b} " >> ${DATA_PATH}/${FILE}         Else            if [ ${used} -gt   ' cat ${data_path}/${file}|grep  Memory Actual usage |awk  ' {print $2} '  ];                 then                     echo -e  "${file}\n Day Maximum memory usage: ${ date}\n Total Memory (m):  ${total}\n Memory actual usage (m):  ${used}\n memory percent Used (m):  ${usage_b}\n---\ n " > ${ Data_path}/${file}            fifi#mail -s   "${days}-host Nginxload-tomcat Memory usage"   @qq. Com < ${data_path}/${file} #echo  usage_b=$ Usage_b

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/84/27/wKiom1eHGrWgrh2LAAAdIy6H8t0011.png "title=" Free5.png "alt=" Wkiom1ehgrwgrh2laaadiy6h8t0011.png "/>

What advice and need to correct the place can leave a message, thank you

This article is from the "share is a virtue" blog, please be sure to keep this source http://passers.blog.51cto.com/9686614/1826336

Linux Monitoring system resources-memory

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.