RAM :
free command
The free command is provided by procps.*.rpm (on Redhat series OS), and all output values of the free command are read from /proc/meminfo.
1 2 3 4 5 6 total used free shared buffers cached 1 Mem: 24677460 23276064 1401396 0 870540 12084008 2 -/+ buffers/cache: 10321516 14355944 3 Swap: 25151484 224188 24927296
The first line is from the perspective of the operating system, total represents the total memory, used represents the used memory, shared represents the memory shared by the process, there are more wonderful explanations about buffers and cached:
- A buffer is something that has yet to be "written" to disk.
- A cache is something that has been "read" from the disk and stored for later use.
total = used + free 即: 24677460 = 23276064 + 1401396
The second line is from a program perspective,
program used = system used - system buffers - system cached,
i.e. 10321516=23276064-870540-12084008
Program available free = system free + system buffers + system cached,
i.e. 14355944=1401396+870540+12084008
Example: Monitor the swap partition, if the swap exceeds 3000M, send an alarm email.
#!/bin/bash useSwap=`free -m |tail -1 |awk '{print $3}'` if [ $useSwap -ge 3000 ]; then echo " Use swap more than 3000M, Please add memory in time" |mail -s "(Memory Warning)" ***@qq.com be
Note: The alarm triggering rule should be determined according to the specific running program
CPU
uptime 或 vi / proc / cpuinfo
13:40:08 up 4:48, 1 user, load average: 0.46, 0.28, 0.15
0.46, 0.28, and 0.15 represent 1 minute, 5 minutes, and 15 minutes of CPU load, respectively. The value n=cpu cores means that the load just reaches 100%, and the larger the value, the greater the CPU load.
Example: Monitoring CPU Load
#!/bin/bash cpus=`cat /proc/cpuinfo |grep "physical id" |wc -l` threshold=$[ $cpus - 1 ] load=`uptime |cut -d, -f 4 | cut -d: -f 2` control=`echo "$load > $threshold"|bc` #In the shell, decimals and integers cannot be directly compared, use the bc calculator if [ $control -eq 1 ];then echo " 10.1.1.183(nginx server) CPU load is too large" |mail -s "10.1.1.183(nginx server)" lianshubash.com be
disk
df
Commonly used df -hl
Example: Monitoring Disk Usage
#!/bin/bash sda2DiskFree=`df -hl |grep "^/dev/sda2"|awk '{print $4}'|cut -dG -f 1` sda3DiskFree=`df -hl |grep "^/dev/sda3"|awk '{print $4}'|cut -dG -f 1` sda5DiskFree=`df -hl |grep "^/dev/sda5"|awk '{print $4}'|cut -dG -f 1` if [ $sda2DiskFree -le 100 ]; then echo " /dev/sda2 Disk space less than 100G,Please check the disk occupancy" |mail -s "(Disk Warning)" com be if [ $sda3DiskFree -le 100 ]; then echo " /dev/sda3 Disk space less than 100G,Please check the disk occupancy" |mail -s "(Disk Warning)" com be if [ $sda5DiskFree -le 70 ] ;then echo " /dev/sda5 Disk space less than 70G,Please check the disk occupancy" |mail -s "(Disk Warning)" com be
from
View the disk size of a folder commonly used du -sh /
fdisk
View disk partitions commonly used fdisk -l
Network traffic
cat /proc/net/dev
View network traffic
Example Write an alarm email and send an alarm email when the outbound traffic of the host exceeds 500M
#!/bin/bash # outcount=`cat /proc/net/dev | grep eth1 | gawk '{print $10}'` outcheck=`echo "${outcount} > 500*1024*1024" |bc` if [ $outcheck -eq 1 ];then echo "Output on eth1 is greator than 500M." | mail -s "Network Waring" *@qq.com beNote: View other commands on the network http://os.51cto.com/art/201404/435279.htm