danillosl
danillosl

Reputation: 519

How does jconsole get all the information he needs?

I want to make a system to gather some data of the JVM and notify me at certain levels, jconsole have this data, but I have no idea how it collects such data. Does someone know a way to gather this data programatically with java?

Upvotes: 0

Views: 92

Answers (1)

ssube
ssube

Reputation: 48247

As described in the docs for JConsole, it "is a monitoring tool that complies to the Java Management Extensions (JMX) specification" and "uses the extensive instrumentation of the Java Virtual Machine" to gather datta.

In other words, it uses the Java Management Extensions (JMX).

JMX provides a ton of data from various sources within the JVM, and new data sources can be defined by libraries. These are advertised using managed beans (JMX MBeans), which use a particular set of defs or annotations to indicate that they provide data or operations, what, and how.

with the JMX 2.0 spec, you can use a set of annotations to mark your beans, making it fairly easy to provide data. Depending on your container, adding new beans may be trivial. JMX can act as both a data source and allow methods to be called from the console or other client, actually allowing you to perform (supported) operations on the VM being watched.

Various containers (such as Tomcat) and libraries (such as C3P0) provide additional metrics, in addition to the slew of beans the JVM provides. These expose such things as memory usage (one of the more popular).

These beans are exposed by the JVM over a pair of ports using a domain: key-property-list naming convention. Each bean and property exposes some relevant information, which clients like JConsole can use to build the tree of available beans and each screen with counters and buttons.

Upvotes: 1

Related Questions