C2B2 logo icon

An Introduction to Monitoring With RHQ


RHQ is a JMX-enabled monitoring solution which enables you to monitor java applications and gather historical data, configure alerts and notifications and perform basic operational tasks.
Any application which uses the JMX API can be monitored byRHQ. Without any configuration, it will just monitor JVM MBeans, but it is possible to write a very simple plugin just with XML to monitor application specific MBeans.

How does RHQ work?

The key components of an RHQ monitoring solution are:
  •  RHQ Server
  • RHQ Agent(s)
  • A supported database
  • JMX enabled resources to monitor
An example monitoring architecture with RHQ
Agents are usually installed one per machine and use pluginsto gather metrics from the resources you want them to monitor. Each agent thenreports back to the RHQ server, which does the grunt-work of collating all themetrics and saving them to the database as well as handling alerts andnotifications.

How do I set up an RHQ monitoring environment?

There are anumber of prerequisites for installing RHQ, including the correct versionof Java and a supporteddatabase. If you want to set up RHQ in production over multiple machines likein the diagram above, it’s crucial that the clocks of each machine aresynchronized and kept in sync.
For the purposes of this blog post, we’ll be following theKISS principle: Keep It Simple, Stupid.
Since RHQ provides very good documentation on the steps totake for installation, I won’t waste time reproducing them, so here is anoverview of the things you should have in place for basic RHQ monitoringenvironment. On the diagram above, we should end up with the main blue box onthe left; a simple, one machine system.

Basic high-level install process


This blog is about RHQ, not databases, so I’ll assume you haveeither Oracle orPostgresinstalled at this point. If not, now is an ideal time to go and do that!
Once your database is prepared for use with RHQ, the firststep is to download the RHQ server. Installation is as simple as extracting itto the directory you’ve chosen.  OnLinux, I usually create /opt/RHQ and extract my server there. At the endof installation, you should have two subdirectories there, one for the serverand another for the agent.
Navigate to <RHQ_HOME>/<server_dir>/bin and runrhq-server.sh start (Linux) or rhq-server.bat start (Windows). This will startthe server and should give you a console on localhost:7080.
Going to the console for the first time will present youwith the final stage for server installation: datasource configuration. Onceyou’ve entered all the right details, including the JDBC address for yourdatabase, your server is ready to start listening for agents!
To download the agent, go to the “Administration” tab andselect “Downloads” from the configuration section on the left. Follow theinstallation instructions, specifying the same <RHQ_HOME> directory fromearlier.
Start the agent in the same way as the server (but withoutsupplying the ‘start’ argument) by going to <RHQ_HOME>/<agent_dir>/binand executing ./rhq-agent.sh.
When you run the agent for the first time, you'll need to configure it to talk to the server and also make sure that it supplies the correct hostname or IP to the server so plugin installation works correctly.
During my configuration, I accepted the defaults. Make sure you don't do this in production!

Adding resources


We haven’t finished now that everything is installed, westill need to tell RHQ to start listening. In the console, the Inventory tabhas a “Discovery Queue” where the agent will report all the resources it canfind that aren’t yet being monitored. Adding these will move the resources intothe “All Resources” section. This section isn’t ideal to use unless you’ve onlyselected very few resources, so select the “Platforms” section to see a list ofmachines. Each machine will present its resources in a much more organised,easy to use way.

Installing plugins


The RHQ agent comes with a lot of plugins by default andshould be all you need for testing purposes but you may be running an uncommonjava application you’d like to monitor, or perhaps you’ve decided to use thesupported JBoss Operations Network, where the agent doesn’t come with pluginspreinstalled.
RHQ has a good community ofdevelopers writing plugins and provides a range of “base” plugins which canbe extended to meet your specific needs.
Assuming you have a plugin you want to install, it mustfirst be deployed to the server. So copy the plugin to the <RHQ_HOME>/<server_dir>/pluginsdirectory or use the console’s Administration tab to upload a new Agent plugin.
To update the agents with the newly deployed plugin, eitherrestart them or run “plugins update” in the agent console window.
RHQ is a great tool to support your business's Java infrastructure and flexible enough to be useful in the vast majority of scenarios. For more information, check out our Youtube channel for a webinar on JBoss Operations Network.