Linux monitoring CPU Memory disk Process script

Source: Internet
Author: User
Tags cpu usage

#!/bin/bash

#

#This is a monitor system CPU Memory process disk IO disk zone Statistixs scripts.

#

#

# #CPU Usage Rate

/bin/date>>/mnt/system_info.log



Echo-e "\ n" >>/mnt/system_info.log



# #CPU Usage Rate

Echo-e "\033[31MCPU usage rate:\033[0m" >>/mnt/system_info.log

/usr/bin/top-n 2 | grep "Cpu (s)" >>/mnt/system_info.log



Echo-e "\ n" >>/mnt/system_info.log



# #memory Usage Rate

Echo-e "\033[31mmemory usage rate:\033[0m" >>/mnt/system_info.log

Total= ' Free-m | grep "Mem" | awk ' {print $} '

Used= ' Free-m | grep "Mem" | awk ' {print $} '

Usage_rate= ' awk ' begin{printf '%.2f%\n ', (' $used '/' $total ') *100} '

echo "Memory usage rate is $usage _rate" >>/mnt/system_info.log



Echo-e "\ n" >>/mnt/system_info.log



# #memory error (Memory use exceed 80%)

Echo-e "\033[31mmemory error state:\033[0m" >>/mnt/system_info.log

Memory_rate= ' echo ' ${usage_rate%.*} "'

If [$memory _rate-gt];then

echo "Error,memory use rate was $usage _rate,memory more than 80%,please Handle" >>/mnt/system_info.log

Else

echo "System Memory is Normal." >>/mnt/system_info.log

Fi



Echo-e "\ n" >>/mnt/system_info.log



# #process Statistics

Echo-e "\033[31mprocess Statistics: \033[0m" >>/mnt/system_info.log

process= '/bin/ps aux | Wc-l '

echo "System process numbers is $process" >>/mnt/system_info.log



Echo-e "\ n" >>/mnt/system_info.log



# #disk IO Statistics

Echo-e "\033[31mio Statistics: \033[0m" >>/mnt/system_info.log

/usr/bin/iostat-d-K 1 4 >>/mnt/system_info.log



Echo-e "\ n" >>/mnt/system_info.log



# #disk Space Use

ECHO-E "\033[31mdisk space use: \033[0m" >>/mnt/system_info.log

/bin/df-h >>/mnt/system_info.log



Echo-e "\ n" >>/mnt/system_info.log



# #disk Partition Statistics

ECHO-E "\033[31mdisk partition rate: \033[0m" >>/mnt/system_info.log

Partition_rate= ' Df-k | Grep-v Filesystem | awk ' {print int ($)} '

For number_rate in $partition _rate

Do

If [$number _rate-ge];then

echo "Error,disk partition zone more than 80%,please Handle" >>/mnt/system_info.log

Else

echo "Disk partition zone Normal" >>/mnt/system_info.log

Fi

Done


The great God of cattle break can comment casually

This article is from the "experience-based staff" blog, please be sure to keep this source http://zhangjianxin.blog.51cto.com/10134758/1689559

Linux monitoring CPU Memory disk Process script

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.