#!/bin/ksh -p # COPYRIGHT: Copyright (c) 2008 Stefan Parvu. # CDDL HEADER START # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"). You may not use this file except in compliance # with the License. # You can obtain a copy of the license at Docs/cddl1.txt # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # CDDL HEADER END # # VERSION: 0.63 # # HISTORY # 2007-10-16 Stefan Parvu - Initial Author # 2008-08-28 added get_jvm, print_gc_data - sp # 2009-02-04 handle better zones - sp # ######### # # FUNCTIONS # # ######### # usage() { print "Usage: ${0##*/} [-f weblogic] secs" exit 1 } print_gc_data() { # $1 zone: global 0, local 1 # $2 print mode: 1 name included, 0 name skipped # $3 pid if (( $1 == 0 )) then if (( $2 == 1 )) then ${JSTAT} -gcutil $3 2>/dev/null | tail +2 |\ perl -wnla -e ' ($s0,$s1,$e,$o,$p,$ygc,$ygct,$fgc,$fgct,$gct) = @F; print "$ENV{z}.$ENV{name}.$ENV{lpid}:" . time . ":$s0:$s1:$e:$o:$p:$ygc:$ygct:$fgc:$fgct:$gct";' else ${JSTAT} -gcutil $3 2>/dev/null | tail +2 |\ perl -wnla -e ' ($s0,$s1,$e,$o,$p,$ygc,$ygct,$fgc,$fgct,$gct) = @F; print "$ENV{z}.$ENV{lpid}:" . time . ":$s0:$s1:$e:$o:$p:$ygc:$ygct:$fgc:$fgct:$gct";' fi else if (( $2 == 1 )) then zlogin -S $z \ ${JSTAT} -gcutil $3 2>/dev/null | tail +2 |\ perl -wnla -e ' ($s0,$s1,$e,$o,$p,$ygc,$ygct,$fgc,$fgct,$gct) = @F; print "$ENV{z}.$ENV{name}.$ENV{lpid}:" . time . ":$s0:$s1:$e:$o:$p:$ygc:$ygct:$fgc:$fgct:$gct";' else zlogin -S $z \ ${JSTAT} -gcutil $3 2>/dev/null | tail +2 |\ perl -wnla -e ' ($s0,$s1,$e,$o,$p,$ygc,$ygct,$fgc,$fgct,$gct) = @F; print "$ENV{z}.$ENV{lpid}:" . time . ":$s0:$s1:$e:$o:$p:$ygc:$ygct:$fgc:$fgct:$gct";' fi fi } get_jvm() { lpid=$1 if (( $# > 1 )) then # we have search string on lsearch="$2" pargs 2>/dev/null $lpid | grep "$lsearch" > /dev/null 2>&1 if (( $? != 0)) then continue else pargs -c $lpid 2>/dev/null | grep "$lsearch" |\ sed 's/^.*\=//;s/\D//' | read name export z name lpid # DEBUG # print "\n$z.$name $pid" # get the jstat from each zone if [[ $z == "global" ]] then print_gc_data 0 1 $lpid else print_gc_data 1 1 $lpid fi fi else export z lpid if [[ $z == "global" ]] then print_gc_data 0 0 $lpid else print_gc_data 1 0 $lpid fi fi } get_pids() { for pid in `pgrep -x java -z $1` do if (( weblogic_sem == 1 )) then get_jvm $pid "\: \-Dweblogic.Name\=" else get_jvm $pid fi done } # ######### # # MAIN BODY # # ######### # # Source Global SDR Settings PWD=$(dirname $0) . ${PWD}/setenv if [[ ${OS_NAME} != "SunOS" ]] then print "Error: cannot run on this OS: $(uname -s)" print "This collector requires Solaris 10 x86, sparc" exit 1 fi if [[ ! -f /usr/java/bin/jstat ]] then if [[ -f /usr/jdk/latest/bin/jstat ]] then JSTAT=/usr/jdk/latest/bin/jstat else print "Error: cannot find a valid jstat utility" exit 1 fi else JSTAT=/usr/java/bin/jstat fi weblogic_sem=0 while getopts ":f:h" arg do case "${arg}" in f) format=$OPTARG case "$format" in weblogic) weblogic_sem=1 ;; *) print "Not supported format !" usage ;; esac ;; h) usage ;; esac done shift $(($OPTIND - 1)) # check arguments if (( $# < 1 || $# > 1 )) then usage fi # check root if (( USER_ID != 0 )) then print "Error: ${0##*/} requires root privileges" exit 1 fi pgrep -x java | wc -l | read no_jvms if (( no_jvms == 0 )) then print "Error: no JVM target found" exit 0 fi while true do if [[ ! -f /usr/sbin/zoneadm ]] then z=global get_pids $z else for z in `zoneadm list` do get_pids $z done fi sleep $1 done