Get the shell script for disk IO and system load load

Source: Internet
Author: User
This section describes several shell scripts that can be used to extract I/O information from the disk, system load load information, and so on

1, extract the system load information

Copy Code code as follows:


#!/bin/sh


host=$ (hostname)


channel=$ (hostname | sed ' s/[0-9]//g ')


runday=$ (date +%y-%m-%d)


iphost=$ (/sbin/ifconfig | grep ' inet addr: ' | grep-v ' 127.0.0.1 ' | cut-d:-f2 | awk ' {print} ')


I=1


while [$i-le];d o


rundaytime=$ (date "+%y-%m-%d%h:%m:%s")


/bin/cat/proc/loadavg | Awk-f "" ' {print "'" $rundaytime "" "," $ "," $ "," $ "," $ "," $} ' >>/tmp/$ (hostname)-${runday}load.txt


/usr/bin/sar-u 1 1 | Grep-v Average | /bin/sed-n ' 4, $p ' | Awk-f "" ' {print "'" $rundaytime "" "," $ "," $ "," $ "," $} ">>/tmp/$ (hostname)-${runday}sar.txt


i=$ ((i+1))


Sleep 59


done


Awk-f "," ' {print ' ' $host ' ' ', ' ' ' ' $channel ' ', ' ' ' ' $IPhost ' ', ' ' ', ' ' ' ', ' ' ' ' ', ' $ ', ' $ ', ' $ ', ' $ ', ' $ '/tmp/$ (hostname)-${ Runday}sar.txt >/tmp/$ (hostname) ${runday}sar.txt


awk-f "," ' {print ' ' $host ' ' ', ' ' ' ' $channel ' ', ' ' ' ' $IPhost ' ', ' ' ', ' ' ' ', ' ' ' ', ' ' ' ', ' ' ' ' ' ' $ ', ' $ ', ' $ ', ' $ ', ' $} ' )-${runday}load.txt >/tmp/$ (hostname) ${runday}load.txt


rm-rf/tmp/$ (hostname)-${runday}sar.txt


rm-rf/tmp/$ (hostname)-${runday}load.txt

2, Code 2

Copy Code code as follows:


#!/bin/sh


Pdir=/monitor/nagios/shell/sarlog


runday=$ (date +%y-%m-%d)


tmpdir=/monitor/nagios/tmp


for I in '/bin/cat/monitor/nagios/shell/sarlog/machine.lst '


do


/usr/bin/scp ${pdir}/sarlog.sh ${i}:/root &&/usr/bin/rsh ${i}/root/sarlog.sh &


done

3, Code 3

Copy Code code as follows:


#!/bin/sh
Pdir=/monitor/nagios/shell/sarlog
runday=$ (date +%y-%m-%d)
tmpdir=/monitor/nagios/ Shell/sarlog/log
Machinelst=/monitor/nagios/shell/sarlog/machine.lst
for i in '/bin/cat/monitor/nagios/ Shell/sarlog/machine.lst '
do
  /usr/bin/scp ${i}:/tmp/*${runday}sar.txt ${tmpdir}
   /USR/BIN/SCP ${i}:/tmp/*${runday}load.txt ${tmpdir}
Done
/bin/cat ${tmpdir}/*${runday}sar.txt >> ${tmpdir}/tmp${runday}.txt
/bin/cat ${tmpdir}/*${runday}load.txt >> ${tmpdir}/${runday}loadresult.txt
Count=1
line=$ (cat ${tmpdir}/tmp${runday}.txt |wc-l)
>${tmpdir}/result${runday}.txt
While ["$ Count "-le" $Line]
do
        idle=$ (sed-n "${count}p" ${tmpdir}/tmp${ Runday}.txt | Awk-f "," ' {print $} ')
        busy= ' echo "scale=2;100-$Idle ' |BC '
 & nbsp;      sed-n "${count}p" ${tmpdir}/tmp${runDay}.txt | sed  "s/$/, $Busy/g" >> ${tmpdir}/${runday}sarresult.txt
        Let count=count+1
Done
/usr/local/mysql/bin/mysql-u root-d nagios-pbj7n48dm  <<eof
    Load Data infile ' ${tmpdir}/${runday}sarresult.txt ' into table t_daily_stats FIELDS terminated ', ';
   Load Data infile ' ${tmpdir}/${runday}loadresult.txt ' into table t_daily_load FIELDS terminated by  ',';
EOF
Rm-rf ${tmpdir}/*${runday}sar.txt
rm-rf ${tmpdir}/*${runday}load.txt
Rm-rf rm-rf ${TmpDir}/*${run Day}.txt

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.