Monitoring Linux system CPU hard disk network IO and other resource scripts

Source: Internet
Author: User
Tags fpm

This script is to monitor all aspects of the system resources, need to change a little, if the network card is not correct, slightly modified, the mailbox to write their own 163 mailbox, the default is an hour to send an email to the mailbox, the contents of the monitoring can add their own changes, here is the CPU, memory, process, connection number, network card traffic, disk Script, the system is CentOS6.4 64 bits.

Send mail with mutt, so install first

Yum Install Mytt-y

Vim chakan.sh

#!/bin/bashwhile [1]doruntime=60waittime=3600rm-rf/root/check_log/*time= ' date + "%y-%m-%d%H:%M:%S" ' d= ' date +%m%d ' N = ' Ps-ef | grep Nginx | Grep-v grep | Wc-l ' q= ' ps-ef | grep php-fpm | Grep-v grep | Wc-l ' [-d/root/check_log/] | | mkdir/root/check_logip= ' Ifconfig eth0 | Sed-n ' 2 ' p | awk ' {print $} ' | Awk-f ': ' {print $} ' m= ' uptime | awk ' {print $8,$9,$10,$11,$12} ' o= ' ifconfig eth0 | Sed-n ' 8 ' p | awk ' {print $3,$4} ' p= ' ifconfig eth0 | Sed-n ' 8 ' p | awk ' {print $7,$8} ' #R = ' ifconfig eth1 | Sed-n ' 8 ' p | awk ' {print $3,$4} ' #S = ' ifconfig eth1 | Sed-n ' 8 ' p | awk ' {print $7,$8} ' a= ' top-bn1 | Sed-n ' 2 ' p | awk ' {print $} ' b= ' top-bn1 | Sed-n ' 2 ' p | awk ' {print $ $} ' echo ' IP: $IP ' >>/root/check_log/jiance.logecho ' system date: ' >>/root/check_log/ Jiance.logecho "$time" >>/root/check_log/jiance.logecho "-------------system load------------------" >> /root/check_log/jiance.logecho "System load:" >>/root/check_log/jiance.logecho $M >>/root/Check_log/jiance.logecho "-------------Full processes---------------" >>/root/check_log/jiance.logecho " Processes: ">>/root/check_log/jiance.logecho $A >>/root/check_log/jiance.logecho" Zombie: ">>/ Root/check_log/jiance.logecho $B >>/root/check_log/jiance.logecho "-----------Application Processes----------">>/root/check_log/jiance.logecho" Nginx processes: ">>/root/check_log/ Jiance.logecho $N >>/root/check_log/jiance.logecho "php-fpm processes" >>/root/check_log/jiance.logecho $Q >>/root/check_log/jiance.logecho "--------------TCP connect------------------" >>/root/check_log/ Jiance.lognetstat-n | awk '/^tcp/{++s[$NF]} END {for (a in S) print A,s[a]} ' >>/root/check_log/jiance.logecho '-----------interferce tra Ffic--------------">>/root/check_log/jiance.logecho" eth0 traffic: ">>/root/check_log/jiance.logecho" In: $O ">>/root/check_log/jiance.logecho" out: $P ">>/root/cHeck_log/jiance.log#echo "eth1 traffic:" >>/root/check_log/jiance.log#echo "in: $R" >>/root/check_log/ Jiance.log#echo "Out: $S" >>/root/check_log/jiance.logecho "-------------CPU load-----------------------" > >/root/check_log/jiance.logecho "CPU Load:" >>/root/check_log/jiance.logsar-u 5 3 | Grep-v Linux | Grep-v ^$ >>/root/check_log/jiance.logecho "-------------mem Load (/m)------------------" >>/root/check_ Log/jiance.logecho "Mem load:" >>/root/check_log/jiance.logmemtotal= ' free-m | grep Mem | Awk-f: ' {print $} ' | awk ' {print '} ' memfree= ' free-m | grep Cache | awk nr==2 | awk ' {print $4} ' memfreeb= ' awk ' begin{printf '%.2f%\n ', ' $MemFree/$MemTotal \*100 '} ' memfrees= ' awk ' begin{printf '%.f ' , ' $MemFree/$MemTotal \*100 '} ' echo ' Memtotal: $MemTotal memfree: $MemFree memfreeb: $MemFreeB memfrees: $MemFreeS ">& Gt /root/check_log/jiance.logecho "---------------disk use-----------------------" >>/root/check_log/jiance.Logecho "Disk use:" >>/root/check_log/jiance.logdf-h >>/root/check_log/jiance.logecho "-----------Check IO load-----------------------">>/root/check_log/jiance.logecho" io load: ">>/root/check_log/ Jiance.logiostat | Grep-v ^$ | Grep-v Linux | Grep-v DM | Grep-v hdc >>/root/check_log/jiance.logecho "------------------All information-----------------" >>/ Root/check_log/jiance.logecho "All Information" >>/root/check_log/jiance.logdstat 5 3 >>/root/check_log/ Jiance.logsleep $RUNTIMEcat "/root/check_log/jiance.log" |mutt-s "[Email protected]sleep $WAITTIMEdone
Sh./chakan &

Figures

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/27/0D/wKioL1NwgNnyobDSAAFS1pyD03w336.jpg "title=" Qq20140512160232.jpg "alt=" Wkiol1nwgnnyobdsaafs1pyd03w336.jpg "/>



This article is from "a Stone Bbotte blog" blog, please be sure to keep this source http://bbotte.blog.51cto.com/6205307/1409922

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.