Get disk IO vs. system load load shell script _linux shell

Source: Internet
Author: User

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" "", "$", "$", "$", "$", "$", "$}"/tmp/$ (hostname)-${ 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 '
Todo
/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 '
Todo
/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"]
Todo
idle=$ (sed-n "${count}p" ${tmpdir}/tmp${runday}.txt | awk-f "," ' {print $} ')
Busy= ' echo ' scale=2;100-$Idle "|BC"
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 the table t_daily_stats FIELDS terminated by ', ';
Load data infile ' ${tmpdir}/${runday}loadresult.txt ' into the 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}/*${runday}.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.