Linux Load Monitoring Scripts

Source: Internet
Author: User

#!/bin/bash

Date= ' echo $ (date +%y\-%m\-%d\%h:%m:%s) '
Hostname= ' HostName '
ip= ' Ifconfig eth0 | grep "inet addr" | Cut-f 2-d ":" | Cut-f 1-d "" '
serverinfo= ' echo-e '--------$Date--------\ n server: $HostName IP: $IP "'

#删除5天前的监控日志
Logpwd=/var/log/monitor
Logdate= ' echo $ (date-d -5day +%y%m%d) '
loggrep= ' ls $LOGPWD | Grep-c "$LOGDATE"
If [$LOGGREP-GT 0]
Then
RM-FR $LOGPWD/* $LOGDATE. Log
Fi

Echo-e "$ServerInfo \nuptime\n ' uptime ' \nfree-m\n ' free-m '" > $LOGPWD/monitor.log
#监控cpu负载
physicalcpu= ' grep ' physical id '/proc/cpuinfo | Sort-u | Wc-l '
corecpu= ' grep ' core ID '/proc/cpuinfo | Sort-u | Wc-l '
Count_cores= ' echo ' $PhysicalCpu * $CoreCpu | BC '
Count_uptime= ' Uptime |wc-w '
Averageload= ' Uptime | awk ' {print $ ' $count _uptime '} '
Averageint= ' echo $AverageLoad | Cut-f 1-d "." `
If [$AverageInt-gt $count _cores]
Then
Echo-e "$ServerInfo \n15 minutes of load for $averageload, core number $count_cores, more than CPU core number, please handle! >> $LOGPWD/cpu_status_$ (date +%y%m%d). log
ECHO-E "15 minutes of load of $averageload, core number $count_cores, more than the CPU core number, please handle! ">> $LOGPWD/monitor.log
Else
Echo-e "$ServerInfo \n15 min load of $averageload, core number $count_cores, load normal. >> $LOGPWD/cpu_status_$ (date +%y%m%d). log
ECHO-E "15 minutes of load is $averageload, core number $count_cores, load normal. ">> $LOGPWD/monitor.log
Fi
#监控内存使用率
Memtotal= ' Free-m | grep Mem | awk ' {print $} '
Memfree= ' Free-m | grep Mem | awk ' {print $4} '
Memrate= ' echo ' 100-$MemFree *100/$MemTotal "| BC '
If [$MemRate-GT 80]
Then
Echo-e "$ServerInfo \ n Memory utilization $memrate%, greater than 80%, please handle. >> $LOGPWD/mem_status_$ (date +%y%m%d). log
ECHO-E "Memory utilization $memrate%, greater than 80%, please handle. ">> $LOGPWD/monitor.log
Else
Echo-e "$ServerInfo \ n Memory utilization $memrate%, less than or equal to 80%, memory load is normal. >> $LOGPWD/mem_status_$ (date +%y%m%d). log
ECHO-E "Memory utilization $memrate%, less than or equal to 80%, memory load is normal. ">> $LOGPWD/monitor.log
Fi

If [$AverageInt-gt $count _cores]| | [$MemRate-GT 80]
Then
Cat $LOGPWD/monitor.log | Mail-s "$HostName Server load Monitoring alarm" [email protected]
Fi

Linux Load Monitoring Scripts

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.