activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1355055 - in /activemq/trunk/assembly/src: main/descriptors/unix-bin.xml release/bin/diag
Date Thu, 28 Jun 2012 15:51:53 GMT
Author: gtully
Date: Thu Jun 28 15:51:52 2012
New Revision: 1355055

URL: http://svn.apache.org/viewvc?rev=1355055&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3881 - handy diag script to gather info about the
host machine and broker java process and combine into a compressed log, some users have found
it valuable in production

Added:
    activemq/trunk/assembly/src/release/bin/diag   (with props)
Modified:
    activemq/trunk/assembly/src/main/descriptors/unix-bin.xml

Modified: activemq/trunk/assembly/src/main/descriptors/unix-bin.xml
URL: http://svn.apache.org/viewvc/activemq/trunk/assembly/src/main/descriptors/unix-bin.xml?rev=1355055&r1=1355054&r2=1355055&view=diff
==============================================================================
--- activemq/trunk/assembly/src/main/descriptors/unix-bin.xml (original)
+++ activemq/trunk/assembly/src/main/descriptors/unix-bin.xml Thu Jun 28 15:51:52 2012
@@ -68,6 +68,7 @@
       <outputDirectory></outputDirectory>
       <includes>
         <include>bin/activemq</include>
+        <include>bin/diag</include>
         <include>bin/activemq-admin</include>
         <include>bin/macosx/activemq</include>
         <include>bin/linux-*/activemq</include>

Added: activemq/trunk/assembly/src/release/bin/diag
URL: http://svn.apache.org/viewvc/activemq/trunk/assembly/src/release/bin/diag?rev=1355055&view=auto
==============================================================================
--- activemq/trunk/assembly/src/release/bin/diag (added)
+++ activemq/trunk/assembly/src/release/bin/diag Thu Jun 28 15:51:52 2012
@@ -0,0 +1,220 @@
+#!/bin/sh
+#
+# diag.sh - a script to run diagnostic commands and save output to a log file
+# 
+# Author: Cal Lott <calvin.lott@ihg.com>
+#
+PATH=$PATH:$HOME/bin:/bin/:/usr/bin:/sbin:/usr/sbin
+
+# Set a script name string for later use.
+SCRIPT_NAME=`basename $0`
+ORIGINAL_COMMAND_LINE="$0 $*"
+LOCALHOST=`uname -n | awk -F. '{print $1}'`
+
+# Declare some functions.
+
+# Prints argument to stdout, prepended with "[YYYYMMDD-HH:MM:SS]".
+dateprint() {
+  echo "[`date +%Y%m%d-%H:%M:%S`] $*"
+}
+
+# Runs argument list as a single shell command.
+BAR_SEPARATOR='------------------------------------------------'
+run() {
+  echo
+  echo $BAR_SEPARATOR
+  dateprint "START: $*"
+  executable=`echo $* | awk '{print $1}'`
+  dateprint "path to executable: `which $executable 2>/dev/null`" 
+  $*
+  last_exit_code=$?
+  cumulative_exit_code=`expr $cumulative_exit_code + $last_exit_code`
+  dateprint "exit $last_exit_code"
+  dateprint "END: $*"
+  echo $BAR_SEPARATOR
+  echo
+}
+
+# Print usage information.
+usage() {
+  cat << EOF
+
+$SCRIPT_NAME - run a set of standard diagnostic commands
+
+Usage: $SCRIPT_NAME [-l logfile] [-jz] [-hv] <pid1> <pid2> ... <pidN>
+
+This script runs several diagnostic commands on the local system and saves the
+output to a gzipped log file. You may also specify an optional list of pids,
+which will cause additional diagnostic commands (lsoft, jstat, etc.) to be run
+against those specific processes only.
+
+The default path for the datestamped log file is as follows:
+
+  \$HOME/log/$SCRIPT_NAME.\$LOCALHOST.YYYYMMDD-HHMMSS.log
+
+You can override the default file name with the -l option. (See below.)
+
+
+Options:
+-j            Also process any pids listed in output of "jps" command.
+-l <logfile>  Use specified log file instead of default.
+-z            Do not gzip log file.
+
+Other Options:
+-h            Print this message and exit.
+
+EOF
+}
+
+# Print help information.
+help() {
+  usage
+}
+
+# Command line options processing.
+while getopts "hjl:vz" OPTION
+do
+  case $OPTION in
+    h)
+      help
+      exit 0
+    ;;
+    j)
+      USE_JPS='TRUE'
+    ;;
+    l)
+      LOGFILE=$OPTARG
+    ;;
+    z)
+      COMPRESSION_OPTION='DISABLED'
+    ;;
+    ?)
+      usage
+      exit 1
+    ;;
+  esac
+done
+shift `expr $OPTIND - 1` # remove processed arguments from $*
+PIDLIST=$*           # save list of remaining args as pidlist
+
+# If requested, use jps to get an additional list of java pids.
+if [ "$USE_JPS" = 'TRUE' ]
+then
+  # Save the current list of pids.
+  arg_pids=$PIDLIST
+  # Use jps to grab additional java pids, filtering the jps pid itself.
+  jps_pids=`jps 2>/dev/null | awk '$2 !~ /^Jps/ {print $1}'`
+  # Now obtain an unique sorted list of pids from both groups.
+  PIDLIST=`echo $arg_pids $jps_pids | sort | uniq`
+fi
+
+# Use the default logfile if the user did not specify one.
+if [ "$LOGFILE" = '' ]
+then
+  LOGFILE="$HOME/log/$SCRIPT_NAME.$LOCALHOST.`date +%Y%m%d-%H%M%S`.log"
+fi
+# Create log directory if it does not already exist
+mkdir `dirname $LOGFILE` >/dev/null 2>&1
+
+# Print start message to stdout.
+dateprint "BEGIN - running diagnostics for host: `uname -n`"
+
+# Complain and die if we cannot create the logfile.
+touch $LOGFILE >/dev/null 2>&1
+if [ $? -eq 0 ]
+then
+  dateprint "logfile created, running diagnostic commands . . ."
+else
+  dateprint "ERROR: cannot create $LOGFILE, exiting!"
+  exit 1
+fi
+
+# Save stdout and stderr descriptors and redirect output to logfile.
+exec 6>&1            # Link file descriptor 6 with stdout (saves stdout)
+exec 7>&2            # Link file descriptor 7 with stderr (saves stderr)
+exec >$LOGFILE 2>&1  # Redirect stdout and stdin to logfile
+
+##
+## Begin diagnostic output
+##
+dateprint "BEGIN DIAGNOSTIC OUTPUT"
+dateprint "running on host: `uname -n`"
+dateprint "unprocessed command line: \"$ORIGINAL_COMMAND_LINE\""
+dateprint "after options processing: \"$0 $PIDLIST > $LOGFILE\""
+
+# Each of the following shell commands will be run once.
+for cmd in \
+  "crontab -l" \
+  "id" \
+  "ifconfig -a" \
+  "df -kl" \
+  "env" \
+  "iostat -x" \
+  "jps -v" \
+  "netstat -anp" \
+  "netstat -r" \
+  "ps -ef" \
+  "sar -A" \
+  "ulimit -a" \
+  "uname -a" \
+  "uptime" \
+  "w" \
+; do
+  run $cmd
+done
+
+# As above, but these commands are customized for a specific flavor of Unix.
+OS=`uname -s`
+case $OS in
+  Linux)
+    for cmd in \
+      "swapon -s" \
+      "top -b -n1" \
+    ; do
+      run $cmd
+    done
+    ;;
+  SunOS)
+    for cmd in \
+      "swap -s" \
+      "top -b -d1" \
+    ; do
+      run $cmd
+    done
+  ;;
+  *)
+    dateprint "WARNING: OS \"$OS\" unknown - running no OS-specific commands"
+  ;;
+esac
+
+# Each of these commands are run once per each pid argument
+for pid in $PIDLIST
+do
+  for cmd in \
+    "lsof -p $pid" \
+    "jstat -gcutil $pid" \
+    "jstack -l $pid" \
+  ; do
+    run $cmd
+  done
+done
+
+dateprint "END DIAGNOSTIC OUTPUT"
+dateprint "cumulative exit code: $cumulative_exit_code"
+
+exec 1>&6 6>&-   # Restore stdout and close file descriptor 6.
+exec 2>&7 7>&-   # Restore stderr and close file descriptor 7.
+##
+## End diagnostic output
+##
+
+# Compress the logfile if requested and end script execution
+if [ "$COMPRESSION_OPTION" = 'DISABLED' ]
+then
+  dateprint "FINISH - output stored at: $LOGFILE"
+else
+  nohup gzip $LOGFILE >/dev/null 2>&1 &
+  dateprint "FINISH - output stored at: $LOGFILE.gz"
+fi
+
+exit $cumulative_exit_code

Propchange: activemq/trunk/assembly/src/release/bin/diag
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message