January 4, 2021
Estimated Post Reading Time ~

Thread Dumps Analysis in AEM

REFERENCE LINKS:
https://blog.fastthread.io/2016/10/27/thread-dump-analysis-api/

SYNOPSIS:
A customized powershell script to download/generate the thread dumps
Using fastthread to analyze the dumps
Using fastthread API to get the response in JSON format
Extracting the thread dump report URL from the JSON and access the report
Use the Thread Dump Collection & Analysis tool [jstack] to take thread dumps from a running CQ instance for troubleshooting the following:
  • Performance
  • Lock contention.
  • Deadlock
  • other thread-related issues
ASSUMPTION:
  • Assuming that service name is AEM
  • cURL is already installed and configured on windows
  • Has Administrator access
  • Already have API access to fastthread, if not register at FastThread API
GUIDE:
Powershell Script to generate thread dumps, upload to fastthread using cURL or API endpoint, and get JSON response.

Following is the report generated on Fast Thread

# stopping the job if it encounters error
$ErrorActionPreference = 'Stop'
$WarningPreference = 'SilentlyContinue'

# Parameters
$AEMSRC = (get-wmiobject win32_service | ?{$_.Name -eq 'AEM'})
$AEMPID = $AEMSRC.ProcessID
$CURLEXE = "C:\tools\curl76\bin\curl.exe"
$FILENAME = "tdaem64.txt"

# Generating ThreadDumps
cmd.exe /c "jstack -l $AEMPID > $FILENAME"
# Fastthread API
$REPURL = "http://api.fastthread.io/fastthread-api?apiKey={xxxx-xxxx-xxxx-xxxxxx-xxxxxxxxxx}"
# ThreadDumps output file
$DATA = "@$FILENAME"
# Generating threaddumps Report in JSON format
$REPDATA = cmd.exe /c "curl -X POST --data-binary @./$FILENAME $REPURL --header Content-Type:text" | ConvertFrom-Json
# Extracting the ThreadDump report URL from JSON output
$REPORTURL = $REPDATA.graphURL

# Email the Report URL
Write-Host "Emailing the ThreadDump Report"
Send-MailMessage -SmtpServer smtp.gmail.com -Port 587 
-Credential $cred -UseSsl 
-From 'xxxxxx@gmail.com' -To 'xxxx.xxxx@email.com' 
-Subject "ThreadDump Report" `
-Body "The ThreadDump Report can be viewed at $REPORTURL"
Write-Host "Email Sent."

# Clean Up
Remove-Item -Path $FILENAME

# Open the ThreadDump Report in Chrome Browser
Start-Process "chrome.exe" $REPORTURL








By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.