free memory test

free to print out the memory information is divided into two types of memory installed, one is to use virtual memory disk, Swap is here, I believe that the students had installed Linux system is certainly no stranger to the swap partition, Swap size is here when we allocated the size of the partition. 


We are explained below with the following meaning of each column:

total: removing the hardware and the amount of memory remaining after the memory reserved for the operating system. Many people wonder their computer installed a total of 8G of memory, but show total should now be no doubt that only seven of the few G, whether Linux or Windows will have some memory is reserved for hardware and operating systems! 
userd: the amount of memory currently in use. 
Free : total amount of free memory may be used or 
shared: shared memory size, is mainly used for interprocess communication 
buff (buffers): block devices mainly used for data buffering, e.g. (directory information, permissions, etc.) recorded Metadata File System . 
cache: The main contents of the file buffer for 
the total amount of memory that can be used: available

 

buffers and cached difference:

For applications, buffers / cached is equal to available, because buffer / cached file is read in order to improve the performance of, when the application needs to use the memory at the time, Buffer / cached will be recovered quickly. 
So from the perspective of the application is available memory = + System Memory buffers + Free . Cached 
buffers refers to a piece of equipment used to make the buffer size, he only records the file system metadata and Tracking in - Flight Pages, it is used to cached files do buffering. 
That is to say: buffers are used to store, catalog what's inside content, permissions, etc., and cached memory directly to our open files. 
About why the need to buffer, to briefly explain the following: We know that in speed between the CPU, memory, external memory, there is such a relationship: 
the CPU memory faster than 100 times faster than disk memory by 100,000 times, and between them the gap is increased! 
Therefore, in order to coordinate the mismatch between their speed, cache it arises in the interior of the CPU cache, in order to coordinate the speed between the CPU and memory do not match, but also to produce the memory disk and CPU speed coordinate mismatch . There is such a description of the image: a clock cycle of the CPU is regarded as one second. Then, information is read from the L1 cache (a cache of the CPU) is like scratch paper to pick up a table (3 seconds); reading information from the L2 cache (secondary cache of the CPU) is from the side remove a book on the shelf (14 seconds); and reading information from the main memory corresponding to the building go down to buy snacks (4 minutes), while waiting for the hard disk seek time corresponding to leave the office and start to grow Global travel up to one year and three months, but this is only the seek time!

 

The detailed use of free

Syntax: Free [-hbkmotV] [- S <interval in seconds> ] 

supplement: free command displays memory usage, including physical memory, the virtual memory swap file, shared memory segments, and the buffer used in the core of the system Wait. 

Parameters:
 - B Byte Displays in memory usage.
- K in KB display memory usage.
- m is displayed in MB in memory usage.
- H to display memory usage more humane manner.
- O buffer adjustment is not displayed columns.
-s <interval seconds>   consistently observed memory usage.
- T display memory column sums.
-V Display version information.   

 

Monitoring and alarm system memory

Acquisition memory size

free -m  |awk 'NR ==3{print $NF}'

 

free -m |grep buffers\/ |awk '{print $NF}'

 

Configure Mail (centos5 default Sendmail service to open, Centos6 default postfix service to open)

echo set [email protected]  smtp=smtp.qq.com smtp-auth-user=1484029127 smtp-auth-password=123456  smtp-auth=login > /etc/mail.rc

echo "LIU" | mail -s "title"  [email protected]

 

Regular tasks

0 9 * * * /bin/sh  /server/script/free.sh  &> /dev/null

 

cat free.sh

#/bin/bash

FREE=$(free -m  |awk 'NR ==3{print $NF}')

chars="current memory is $cur_free"

 

if [ "$FREE" -lt 100 ];then

  echo $chars|mail -s "$chars" [email protected]

  echo set [email protected]  smtp=smtp.qq.com smtp-auth-user=1484029127 smtp-auth-password=123456  smtp-auth=login > /etc/mail.rc

else

  echo "current memory $ FREE enough ..."

be

 

Note: open the mail service, PC virtual machine to test his company's non-mailboxes may experience problems not receive alarms.

 

Guess you like

Origin www.cnblogs.com/liuzhiyun/p/11266417.html