Shell scripts to monitor CPU, memory, and hard disk utilization

Source: Internet
Author: User

#!/bin/bash

#createdate: 2016-11-15

Date= ' date+%f ' "%h:%m"

ip= ' Ifconfigeth0 | awk '/inet addr/{print $} ' | Cut-d:-f2

`

Echo-e "\033[032mdate: $Date \nhost: $IP \n\033[0m"

echo-----------------CPU----------------

Cpu_us= ' Vmstat|awk ' {print $13} ' |sed-n ' $p '

Cpu_sy= ' Vmstat|awk ' {print $14} ' |sed-n ' $p '

Cpu_id= ' Vmstat|awk ' {print $} ' |sed-n ' $p '

Cpu_wa= ' Vmstat|awk ' {print $16} ' |sed-n ' $p '

cpu_sum=$ (($cpu _us+ $cpu _sy))

Cpu_info ()

{

Echo-e "\033[032mcpu_sum: $cpu _sum% (cpu_use:${cpu_us}%,cpu_system:${cpu_sy}%) \033[0m"

Echo-e "\033[032mcpu_idle:${cpu_id}\033[0m"

Echo-e "\033[032mcpu_wait:${cpu_wa}\033[0m"

}

Cpu_info;

If [$cpu _sum-ge];then

echo "CPU Utilization$cpu_sum" |mail-s "CPU Monitor" xxxxx.com

Fi

echo-----------------Mem-----------------

#Date = ' date+%f ' "%h:%m '

#IP = ' Ifconfigeth0 | awk '/inet addr/{print $} ' | cut-d:-f2 '

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

Use= ' Free-m|awk '/buffers\//{print $NF} '

free=$ (($Total-$Use))

#Total_cony = ' Echo-e | awk ' {print '} '

Echo-e "\033[032mtotal: ${total}m \nuse: ${use}m \nfree: ${free}m\033[0m"

echo-----------------IO------------------

Total= ' fdisk-l| grep "disk/dev/sd[a-z]" |awk ' {print $1$2$3 "GB"} '

Disk_use= ' Df-h|awk ' {print $ "=" $ $} ' | Sed ' 1d ' | Sed ' s/%/%/g '

Echo-e "\033[032mtotal: $Total \n$disk_use\n\033[0m"

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/8A/39/wKiom1gq283iJff-AAA4pCBx728433.png-wh_500x0-wm_3 -wmp_4-s_2914856051.png "title=" Qq20161115173054.png "alt=" Wkiom1gq283ijff-aaa4pcbx728433.png-wh_50 "/>

If you have any deficiencies, please put them in.

This article from "All Technical Blog" blog, reproduced please contact the author!

Shell scripts to monitor CPU, memory, and hard disk utilization

Related Article

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.