Last active
August 29, 2015 14:14
-
-
Save jayankandathil/21e9b6962c7418fa20ea to your computer and use it in GitHub Desktop.
Bash Script to Trigger JVM Heap Dump Using JMX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Bash script to trigger CQ/AEM heap dump using curl via JMX | |
# Author : Jayan Kandathil | |
# Version : 0.1 | |
# Last updated : January 27, 2015 | |
# Instructions : Copy to CQ/AEM Linux instance's /tmp folder, make necessary changes, enable the execute bit and run | |
# Echo on (for debugging purposes) | |
# set -x verbose | |
# Host that CQ runs on | |
HOST=localhost | |
# TCP port CQ listens on | |
PORT=4502 | |
# CQ Admin user ID | |
CQ_USER=admin | |
# CQ Admin user password | |
CQ_USER_PASSWORD=admin | |
# Source Folder where CQ is backed up (no trailing forward slash) | |
CQ_HEAPDUMP_FOLDER=/tmp | |
DATE_TIME=$(date "+%Y.%m.%d-%H.%M.%S") | |
# CQ Backup in progress file (CQ creates it automatically on Backup start, and deletes it when Backup finishes) | |
HEAPDUMP_FILE=$CQ_HEAPDUMP_FOLDER/$DATE_TIME-heap.dump.hprof | |
# rsync log file | |
LOG_FILE=$CQ_HEAPDUMP_FOLDER/heapdump.log | |
# ------------------------------------------------ | |
# Do not configure below this point | |
# ------------------------------------------------ | |
# Log timestamp | |
date | tee -a $LOG_FILE | |
# Initiate CQ heap dump using curl, p1=true means only live objects will be dumped | |
curl -u $CQ_USER:$CQ_USER_PASSWORD -X POST --data "p0=$HEAPDUMP_FILE&p1=true" http://$HOST:$PORT/system/console/jmx/com.sun.management%3Atype%3DHotSpotDiagnostic/op/dumpHeap/java.lang.String%2Cboolean | tee -a $LOG_FILE | |
echo "Finished dumping the CQ/AEM JVM's heap to "$HEAPDUMP_FILE | tee -a $LOG_FILE | |
# Log timestamp | |
date | tee -a $LOG_FILE | |
echo $'\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment