码迷,mamicode.com
首页 > 其他好文 > 详细

21.dubbo脚本之dump.sh

时间:2016-07-01 23:13:10      阅读:895      评论:0      收藏:0      [点我收藏+]

标签:dubbo sh

#!/bin/bash

cd `dirname $0`

BIN_DIR=`pwd`

cd ..

DEPLOY_DIR=`pwd`

CONF_DIR=$DEPLOY_DIR/conf


SERVER_NAME=`sed ‘/dubbo.application.name/!d;s/.*=//‘ conf/dubbo.properties | tr -d ‘\r‘`

LOGS_FILE=`sed ‘/dubbo.log4j.file/!d;s/.*=//‘ conf/dubbo.properties | tr -d ‘\r‘`


if [ -z "$SERVER_NAME" ]; then

SERVER_NAME=`hostname`

fi


PIDS=`ps -f | grep java | grep "$CONF_DIR" |awk ‘{print $2}‘`

if [ -z "$PIDS" ]; then

    echo "ERROR: The $SERVER_NAME does not started!"

    exit 1

fi


LOGS_DIR=""

if [ -n "$LOGS_FILE" ]; then

LOGS_DIR=`dirname $LOGS_FILE`

else

LOGS_DIR=$DEPLOY_DIR/logs

fi

if [ ! -d $LOGS_DIR ]; then

mkdir $LOGS_DIR

fi

DUMP_DIR=$LOGS_DIR/dump

if [ ! -d $DUMP_DIR ]; then

mkdir $DUMP_DIR

fi

DUMP_DATE=`date +%Y%m%d%H%M%S`

DATE_DIR=$DUMP_DIR/$DUMP_DATE

if [ ! -d $DATE_DIR ]; then

mkdir $DATE_DIR

fi


echo -e "Dumping the $SERVER_NAME ...\c"

for PID in $PIDS ; do

jstack $PID > $DATE_DIR/jstack-$PID.dump 2>&1

echo -e ".\c"

jinfo $PID > $DATE_DIR/jinfo-$PID.dump 2>&1

echo -e ".\c"

jstat -gcutil $PID > $DATE_DIR/jstat-gcutil-$PID.dump 2>&1

echo -e ".\c"

jstat -gccapacity $PID > $DATE_DIR/jstat-gccapacity-$PID.dump 2>&1

echo -e ".\c"

jmap $PID > $DATE_DIR/jmap-$PID.dump 2>&1

echo -e ".\c"

jmap -heap $PID > $DATE_DIR/jmap-heap-$PID.dump 2>&1

echo -e ".\c"

jmap -histo $PID > $DATE_DIR/jmap-histo-$PID.dump 2>&1

echo -e ".\c"

if [ -r /usr/sbin/lsof ]; then

/usr/sbin/lsof -p $PID > $DATE_DIR/lsof-$PID.dump

echo -e ".\c"

fi

done


if [ -r /bin/netstat ]; then

/bin/netstat -an > $DATE_DIR/netstat.dump 2>&1

echo -e ".\c"

fi

if [ -r /usr/bin/iostat ]; then

/usr/bin/iostat > $DATE_DIR/iostat.dump 2>&1

echo -e ".\c"

fi

if [ -r /usr/bin/mpstat ]; then

/usr/bin/mpstat > $DATE_DIR/mpstat.dump 2>&1

echo -e ".\c"

fi

if [ -r /usr/bin/vmstat ]; then

/usr/bin/vmstat > $DATE_DIR/vmstat.dump 2>&1

echo -e ".\c"

fi

if [ -r /usr/bin/free ]; then

/usr/bin/free -t > $DATE_DIR/free.dump 2>&1

echo -e ".\c"

fi

if [ -r /usr/bin/sar ]; then

/usr/bin/sar > $DATE_DIR/sar.dump 2>&1

echo -e ".\c"

fi

if [ -r /usr/bin/uptime ]; then

/usr/bin/uptime > $DATE_DIR/uptime.dump 2>&1

echo -e ".\c"

fi


echo "OK!"

echo "DUMP: $DATE_DIR"


本文出自 “8159085” 博客,请务必保留此出处http://8169085.blog.51cto.com/8159085/1794995

21.dubbo脚本之dump.sh

标签:dubbo sh

原文地址:http://8169085.blog.51cto.com/8159085/1794995

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!