BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

CRaSH: An Extensible Command Line Shell For Monitoring A Running JVM

| by Kostis Kapelonis Follow 0 Followers on Jun 27, 2012. Estimated reading time: 2 minutes |

CRaSH (Common ReusAble SHell) is a utility which can provide a command line for interacting with a existing live Java process. It connects to a running JVM and can inspect its internals. It is not  just a shell written in Java (like BeanShell).  It essentially offers remote management and monitoring of a running JVM application in a similar way to Java Management Extensions (JMX).

JMX support must be explicitly developed in a Java application. A Java installation includes by default graphical tools such as JConsole and more recently VisualVM that can attach to a running Java application and retrieve several statistics such as memory usage, thread information, JVM properties etc.

JMX also allows developers or system administrators to change some settings of the application on the fly while the application is running. This functionality is only offered for features already exposed by the developers as MBean interfaces. Since Java 6 however, it is possible to use the Attach API programmatically in order to develop custom monitoring applications that attach directly on a running JVM. As an example, jtop is a command line application that monitors CPU thread utilization. This API is specific to the Hotspot VM implementation.

CRaSH takes this concept even further. It takes advantage of the Attach API and provides a command line shell (full with internal commands, history and autocompletion). The shell is attached to a running JVM and then can be used for loading and running Groovy scripts that are executed against this JVM. This essentially gives an interactive access to the internals of a running JVM allowing for more detailed monitoring.

CRaSH already has built-in support for:

  • inspecting/changing VM properties, running the garbage collector
  • SQL access to JDBC resources
  • access via telnet/SSH (JMX uses Java RMI which can be problematic for firewalls)
  • retrieving memory statistics
  • managing of JVM threads
  • loading external Groovy scripts
  • accessing JCR repositories (e.g. Jackrabbit)
  • logging commands 

The core functionality of CRaSH is best shown in a video that demonstrates running Groovy scripts against a running JVM. A more realistic example is shown in another video where CRaSH is attached to an application server, and executes SQL commands on a datasource using the integrated JDBC commands. CRaSH is essentially just a thin layer between a running JVM and the custom Groovy scripts created by the developer in the form of monitoring "recipes".

Some possible use cases for CRaSH are: 

  • Monitoring a running JVM application (for system administrators, like JMX)
  • Fine-tuning a running JVM application on the fly (for developers).
  • Debugging/Logging a running JVM application (possibly after a specific event)
  • Adding a command line interface to an existing JVM application (targeted to advanced users)
  • Offering an easy way to load "plugins" on the fly for a running application
  • Mocking some parts of a running JVM application or intercepting its I/O
  • Orchestrating different resources/services from a central point
  • Bridging Java and Groovy code together

CRaSH released version 1.0 earlier this year and has lately introduced an online demo showcasing its basic capabilities. For more information see the documentation, Javadoc and the Google user group.The source code is hosted on GitHub.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

HouseMD - Invocation tracing tool by john allen

Re: HouseMD - Invocation tracing tool by Abhay Bakshi

Ok. Thank you. This article is about CRaSH.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

2 Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT