系统指标检查

#!/bin/bash

localPath=$(cd "$(dirname "$0")"; pwd)
todayStr=`date "+%Y%m%d"`
outputfile=$localPath/statics.$todayStr
touch $outputfile
echo "" > $outputfile

javaContainerPid=`ps axu|grep jetty|grep gc|awk '{print $2}'`
localIp=`ifconfig|grep "Mask:255.255.255"|awk '{print $2}'|sed 's/.*://g'|head -n 1`
memery=`free -m|awk '{print "使用:"$3"M","剩余:"$4"M"}'|head -n 3|tail -n 1`
dev=`df -lh|awk 'match($1,"dev")'|awk 'match($2,"G")'`
loadAverage=`uptime|awk -F"," '{print $4,$5,$6}'`
javaOpenFile=`lsof|awk '$2="'"$javaContainerPid"'"'|wc -l`
networkStat=`netstat -nat|awk '{print $NF}'|sort|uniq -c|grep -e ESTABLISHED -e TIME_WAIT`
errorLogMessage=`find /data/log/jetty/ -type f -mtime -7|grep error|xargs cat|awk '{print $5,substr($7,0,5)}'|sort|uniq -c|sort -nr -k1|grep "com"|sed 's/$/\n/g'`
accessArvgInDay=`find /data/log/nginx/ -type f -mtime -7|xargs cat|wc -l|awk '{print $0/7}'|sed 's/$/\n/g'`
javaGcStat=`jstat -gcutil $javaContainerPid`
javaHeapStat=`jmap -heap $javaContainerPid`


      
echo  "机器IP:"  >> $outputfile
ifconfig|grep "Mask:255.255.255"|awk '{print $2}'|sed 's/.*://g'|head -n 1  >> $outputfile
echo  "内存:" >> $outputfile
free -m|awk '{print "使用:"$3"M","剩余:"$4"M"}'|head -n 3|tail -n 1 >> $outputfile
echo  "硬盘:" >> $outputfile
df -lh|awk 'match($1,"dev")'|awk 'match($2,"G")' >> $outputfile
echo  "负载:" >> $outputfile
uptime|awk -F"," '{print $4,$5,$6}' >> $outputfile
echo  "JAVA打开文件数:" >> $outputfile
lsof|awk '$2="'"$javaContainerPid"'"'|wc -l >> $outputfile
echo  "网络连接:" >> $outputfile
netstat -nat|awk '{print $NF}'|sort|uniq -c|grep -e ESTABLISHED -e TIME_WAIT >> $outputfile
echo  "错误日志分析:" >> $outputfile
find /data/log/jetty/ -type f -mtime -7|grep error|xargs cat|awk '{print $5,substr($7,0,5)}'|sort|uniq -c|sort -nr -k1|grep "com"|sed 's/$/\n/g' >> $outputfile
echo "平均日访问量:" >> $outputfile
find /data/log/nginx/ -type f -mtime -7|xargs cat|wc -l|awk '{print $0/7}'|sed 's/$/\n/g' >> $outputfile
echo "GC信息:" >> $outputfile
jstat -gcutil $javaContainerPid >> $outputfile
echo "java堆信息:" >> $outputfile
jmap -heap $javaContainerPid  >> $outputfile

猜你喜欢

转载自gelongmei.iteye.com/blog/1998846