#!/usr/bin/perl -w use warnings; use strict; $| = 1; my $SAMPLE_INTERVAL = 2; my @SAMPLE_PROCESS = ('domain=ecssApp','domain=ecssWeb'); my @SAMPLE_PORT = (7001,8016); my @USER=('weblogic', 'weblogic'); my @PASSWORD=('xx', 'xx'); my $THRESH_HOLD = 100; my $WLST="/export/home/wls10/bea/wlserver_10.3/common/bin/wlst.sh"; my $SCRIPT="/mboss/home/crmgz/bin/dumpthread.py"; while(1){ sleep $SAMPLE_INTERVAL; for(my $i=0; $i<@SAMPLE_PROCESS; $i++){ open(PROC, "ps -eo'pid,pcpu,args'|grep java | grep -v grep |grep $SAMPLE_PROCESS[$i]|"); my $xx = <PROC>; $xx =~ s/^\s+//; my $pos1=index($xx, ' ', 0); my $pos2=index($xx, ' ', $pos1); my $pid = substr($xx, 0, $pos1); my $cpu = substr($xx, $pos1+1, $pos2); print("pid: " . $pid . " cpu: " . $cpu . "\n"); if($cpu>$THRESH_HOLD){ print("i will dump server: " . $pid . "\n"); `$WLST $SCRIPT 127.0.0.1:$SAMPLE_PORT[$i] $USER[$i] $PASSWORD[$i]`; } close(PROC); } }
wlst脚本:
import sys serverName = 'AdminServer' counter = 0 sleepTime = 4000 dateFormat = java.text.SimpleDateFormat("yyyyMMddHHmmssSSS") connect (sys.argv[2],sys.argv[3],sys.argv[1]) for counter in range(3): java.lang.Thread.sleep(sleepTime) fileName = 'dump_' + serverName + '_' + dateFormat.format(java.util.Date()) + '.dmp' threadDump('true', fileName, serverName)