GitHub

Monarch Java Agent

Monarch is a powerful Java agent for method monitoring and analysis. It offers various features to track method execution time, print stack traces, log method arguments and return values, capture heap dumps, and gather JVM-related information.

“Arise, shadows of execution!”

Key Abilities

MonArgs

Argument Description
configFile Path to the configuration file specifying agent behavior [Mandatory].
agentLogFileDir Directory where initialization logs will be written.
agentLogLevel Log verbosity level (DEBUG, INFO, WARN, ERROR).
smtpProperties Path to SMTP configuration for sending alert emails.
agentJarPath Path to the MonarchJavaAgent jar [Mandatory for startup attach].

Summoning the Monarch

You can attach Monarch-Java-Agent either during startup or during runtime.

For startup:

  1. Download the latest agent JAR file from releases page.
  2. Start your Java application using the -javaagent option.
  3. Specify the configuration file and other options as needed.

Example command to attach the agent:

java -Xverify:none -Xbootclasspath/a:/path/to/monarch-java-agent.jar -javaagent:/path/to/monarch-java-agent.jar=configFile=/path/to/config.yaml,agentLogFileDir=/path/to/log/dir,agentLogLevel=DEBUG,smtpProperties=/path/to/smtpProperties.props YourMainClass

For Runtime:

  1. Download the latest agent JAR file from releases page.
  2. Start your application.
  3. Run “monarchAgentStart.bat”/”monarchAgentStart.sh” and provide the requested details.

Example command run:

C:\Users\ashut\monarch-java-agent\attachScript> .\monarchAgentStart.bat
Enter path to the agent JAR file: C:\Users\ashut\monarch-java-agent\target\monarch-java-agent-1.0-SNAPSHOT.jar
Enter path to the agent config file: C:\Users\ashut\monarch-java-agent\sampleConfig\mConfig.yaml
Enter arguments to pass to the agent: agentLogFileDir=C:\Users\ashut\manualTesting,agentLogLevel=DEBUG,smtpProperties=/path/to/smtpProperties.props
Enter PID of the target JVM (press Enter to use current JVM): 24300
Agent attached successfully to PID 24300

Commanding the Shadows

Below is a sample configuration YAML that you can use with Monarch-Java-Agent:

shouldInstrument: true
configRefreshInterval: 15
traceFileLocation: C:\\TraceFileDumps
agentRules:
  - ClassA::methodA@INGRESS::STACK
  - ClassA::methodA@INGRESS::ARGS
  - ClassA::methodA@EGRESS::RET
  - ClassA::methodB@INGRESS::ARGS
  - ClassA::methodB@INGRESS::STACK
  - ClassA::methodB@EGRESS::STACK
  - ClassA::methodB@EGRESS::RET
  - ClassB::methodC@PROFILE
  - ClassB::methodC@INGRESS::HEAP
  - ClassB::methodC@INGRESS::ADD::[System.out.println(20);]
  - ClassA::methodA@INGRESS::ADD::[System.out.println(this.getClass().getName());]
  - ClassA::methodA@CODEPOINT(11)::ADD::[System.out.println(499);]
  - ClassA::methodA@CODEPOINT(11)::ADD::[System.out.println(499 + "," + "Ashutosh Mishra");]
printClassLoaderTrace: true
printJVMSystemProperties: true
printEnvironmentVariables: true
printJVMHeapUsage: true
printJVMCpuUsage: true
maxHeapDumps: 3
sendAlertEmails: true
emailRecipientList:
  - abc@example.com
  - ashutosh@asm.com

The Monarch’s Decrees

The rule syntax for Monarch-Java-Agent follows the format:

<FQCN>::<MethodName>@<EVENT>::<ACTION>

Where:

Forging the Shadow

git https://github.com/AshutoshIWNL/MonarchJavaAgent.git
cd MonarchJavaAgent
mvn clean package

The Architect of Shadows

The Shadow’s Pact

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.