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