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