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!”
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]. |
You can attach Monarch-Java-Agent either during startup or during runtime.
For startup:
-javaagent
option.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:
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
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 rule syntax for Monarch-Java-Agent follows the format:
<FQCN>::<MethodName>@<EVENT>::<ACTION>
Where:
<FQCN>
: Fully Qualified Class Name.<MethodName>
: Name of the method.<EVENT>
: Event at which the action should be performed. Possible values are:
<ACTION>
: Action to be performed. Possible values are:
git https://github.com/AshutoshIWNL/MonarchJavaAgent.git
cd MonarchJavaAgent
mvn clean package
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.