Backend Development 4 min read

Using Arthas watch command to monitor Java method calls (Part 1)

This article introduces the Arthas watch command, explains its four observation points and main parameters, and shows how to use OGNL expressions to monitor Java method invocations, including arguments, return values, and exceptions.

FunTester
FunTester
FunTester
Using Arthas watch command to monitor Java method calls (Part 1)

Arthas is an open‑source Java diagnostic tool. The watch command allows you to conveniently observe the invocation of a specified method, including its return value, thrown exception, and input parameters, by writing OGNL expressions to inspect the relevant variables.

Because the command involves many options and OGNL usage, the content is split into two parts; this part focuses on the official demo and the main parameters, while the next part will cover practical examples. Note that the documentation titles and the actual demo code have some inconsistencies, so the demo code should be used as the primary reference.

Main Parameters

Parameter Name

Parameter Description

class-pattern

Class name expression match

method-pattern

Method name expression match

express

Observation expression

condition-express

Condition expression

[b]

Observe before method invocation

[e]

Observe after method exception

[s]

Observe after method returns

[f]

Observe after method ends (normal or exception return)

[E]

Enable regex matching (default is wildcard)

[x:]

Set output property traversal depth, default is 1

Special Notes

The watch command defines four observation points: -b before method call, -e after exception, -s after return, and -f after method end. By default, -b , -e , and -s are disabled, while -f is enabled.

When an observation point is enabled, the specified expression is evaluated and printed at that point.

Be aware of the difference between method input parameters and output results; only the -b point can observe input parameters (via params ), while the other points observe output.

Since -b occurs before the method execution, return values or exceptions are not yet available at that point.

Disclaimer: This article is originally published by “FunTester”. Please follow the original source for sharing and contact [email protected] for collaborations.

DebuggingJavaBackend developmentOGNLArthasWatch Command
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.