Examining the Pluggability of VisualVM Beta
The first beta release of VisualVM was announced on Friday. In an article last month, we celebrated the Milestone 3 release by introducing the Java troubleshooting, monitoring, and management features offered by VisualVM. This time, to celebrate the Beta release, we will explore VisualVM from a different angle—that of vendors wanting to integrate their own Java troubleshooting, monitoring, and management tools into VisualVM.
Integrating tools into VisualVM is done by means of the VisualVM APIs. Why would you want to integrate tools into VisualVM in the first place? Well, by bundling all of the JDK's small monitoring tools (from JConsole to JHat and about 10 others) into one comprehensive modern-looking tool with enhanced profiling features, VisualVM is positioned to be the tool of choice when it comes to covering the Java community's monitoring, management, and troubleshooting needs. On top of that, it is free and open source. Who would not want to be part of that action?
Secondly, maybe you have some special kind of application that has special monitoring, management, and troubleshooting needs. A good example is the GlassFish application server. With the beta release of VisualVM, a special VisualVM plugin for GlassFish is available. The plugin provides functionality that lets the user expand the GlassFish node in the VisualVM explorer window, exposing all the applications deployed to the GlassFish instance. Then you can see graphs and other info specific to the deployed apps. You can even drill down further and see data specific to servlets that make up the apps in question:
In other words, if your application has specific needs, such as specific artifacts that are not common to other applications, you can create a plugin specifically for that app, to provide specific features to aid the user in monitoring, managing, or troubleshooting that particular app, all in the same VisualVM where they're already doing the same kind of work with their other running applications.
But... how would you make a plugin that works with VisualVM? What are the APIs and how do they work? Here is a useful diagram, showing you the main entry points into VisualVM Beta (click to enlarge):
In short, you can create new tabs, subtabs, and menu items in VisualVM Beta. And, those entry points are themselves, at least potentially, also extendable. So, I could add a new tab that shows something or other, and then YOU could come along and add a new subtab to MY tab. I think that is pretty cool and a key element of the power of VisualVM.
Note: It is very important to realize, however, that the VisualVM APIs are still evolving. Changes will definitely happen, even incompatible ones, in the coming months. However, this is an ideal time to try out the APIs and give feedback to the API designers behind VisualVM.
Here are some very useful resources that should get you up and running very quickly:
- VisualVM API Quick Start. The document Getting Started Extending VisualVM should see to all your needs, in terms of setting up your development environment, understanding the API entry points, and building a simple Hello World scenario.
- VisualVM Javadoc. Get these from the "Beta API Docs" link on the https://visualvm.dev.java.net/ page.
- VisualVM Developer FAQ. A complete list of typical questions that can be asked in relation to the VisualVM APIs, together with many code samples that answer them.
- VisualVM Sources. If you read the VisualVM sources, you will be able to answer several of your API implementation questions. For example, you can find several pluggable views in the sources that you can learn from when creating your own pluggable views.
- VisualVM Plugins. When you download the VisualVM
sources, you will find that you have also downloaded the sources
of a set of plugins. You can inspect these plugins and learn
from them. Treat them as samples. At the time of writing, the plugins bundled
with the sources are as follows:
- GlassFish. This plugin provides a new application type for the GlassFish server. A new application type node is created for each running GlassFish instance. All deployed applications are represented by subnodes, with further subnodes for each servlet in the application. Furthermore, tabs specific to each server instance, application, and servlet are also provided.
- MBeans. This plugin provides a new tab for all applications that have JMX enabled. The information provided in the tab is exactly the same as the information provided by the MBeans tab in the JDK's JConsole application.
- JConsole. This plugin makes VisualVM receptive to JConsole plugins, so that investment in JConsole plugins is not lost when you transfer from JConsole to VisualVM.
- Blog entries. As
the technical writer responsible for documenting the VisualVM APIs, I've written a series of blog
entries about the VisualVM APIs. Note that the Beta release of the VisualVM APIs may not compile against the sources in my blog entries, because there have been some changes. I will update the blog entries whenever I find API incompatibilities of this kind. The relevant
blog entries are as follows:
- Getting Started Extending VisualVM (Part 1). Here you create your first tab extension. You discover that VisualVM tabs are broken down into master views, master view configurations, and detail views. That blog entry is reproduced in the "Hello World" section of the Getting Started Extending VisualVM document.
- Getting Started Extending VisualVM (Part 2). Here you create an application type extension, with a subtab extension within the Overview tab and a menu extension, both specifically for the application type.
- Getting Started Extending VisualVM (Part 3). Here you are introduced to application type subnodes and you are referred to the GlassFish plugin for related source code.
- Getting Started Extending VisualVM (Part 4). Here the extendability of the "Overview" tab, "Monitor" tab, and "Threads" tab are highlighted. In addition, you are shown how to make your own tabs extendable.
- Getting Started Extending VisualVM (Part 5). Here the extendability of the "Host" data source is discussed. Code is provided for adding a tab to the Localhost view and a subtab to its Overview tab.
- Getting Started Extending VisualVM (Part 6). Here you learn a lot about the primary actors of VisualVM—data sources. In addition, you are shown all the code that you need for creating your own data source.
- Getting Started Extending VisualVM (Part 7). Here you find out how to create a tab for comparing data from multiple instances of the same data source type. In this case, the tab contains the system properties (or JVM arguments) of all the running Java applications, at the same time.
Any feedback on these resources, or on the APIs themselves, can be left here or on the VisualVM mailing list.