LINUX-monitor server status and linux Monitoring Server
This document describes how to monitor the operating status of linux servers, including CPU, hard disk, memory, network interfaces, and motherboard.
How to monitor Hard Disks
- Core Ideology
Use command df.
- Sample program
#! /Bin/bashIP = 'hostname-I 'hostname = 'hostname' disk _ sda2 = 'df-Ph | grep/dev/sda2 | awk' {print $5} '| cut -f 1-d "%" 'mailtitle = "server hard disk alert "; if ($ disk_sda2> 90) then MailContent = "Hi: <br> the SDA2 usage of the server $ HostName ($ IP) Hard Disk Partition has exceeded $ disk_sda2 %. Please handle it in time. "; Php sendEmail. php $ MailTitle $ MailContentfi
How to monitor memory
- Core Ideology
Use command free. Then, use the ps command to output the process occupying the first 10 of the memory.
Note that the actual memory usage is 18880/64420 MB, and the memory allocation rate is 29298/64420 MB.
- Sample program
#! /Bin/bashIP = 'hostname-I 'hostname = 'hostname' MAX _ mem = 70MAX_swap = 70 total = 'free-m | grep Mem | awk' {print $2 }' 'memory = 'free-m | grep Mem | awk' {print $3} ''locatedmen = 'free | awk'/Mem/{print int ($3/$2*(100 )} ''mem = 'free-m | awk'/-/{print $3} ''usedtotal = 'awk' BEGIN {printf int ('$ Mem'/'$ total ') * 100)} ''usedswap = 'free | awk'/Swap/{print $3} ''if [$ UsedSwap-gt 0]; then SWAP = 'free | awk'/Swap/{print Int ($3/$2*100)} ''else SWAP = 0 fiMailTitle = "server memory alarm "; if [$ Usedtotal-gt $ MAX_mem-o $ SWAP-gt $ MAX_swap]; then 'ps auxw | head-1; ps auxw | sort-rn-k4 | head-10> memory.txt 'mailcontent = "Hi: <br> & nbsp server $ HostName ($ IP) memory usage, please pay attention to it in time. <Br> & nbsp & nbspmemory usage has exceeded $ Usedtotal %, and swap usage has exceeded $ SWAP %. <Br> & nbsp & nbspmem (buffer + cache) system allocation $ memory & nbspMB ($ LocatedMen %), actual use of $ Mem & nbspMB ($ Usedtotal %) <br>   memory usage top10input see the attached memory.txt. "; Php sendEmail. php $ MailTitle $ MailContentfi
How to monitor CPU
To be continued.
How to monitor network interfaces
To be continued.
How to monitor the motherboard
To be continued.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.