Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Using RHQ (JON) to monitor Java apps

 

January 23, 2014
Romain Pelisse
Related topics:
Java
Related products:
Red Hat JBoss Enterprise Application Platform

Share:

    While there is not yet a RHQ plugin for Glassfish, it is already possible to monitor an instance of Glassfish (GF), using the existing JMX Server resource template. Let's see how this unfolds...

    Set up

    Foreword: While not difficult, setting this up on a laptop requires running a LOT of Java processes, on top of a database. As the latter needs to be a somewhat older version of PostgreSQL (8.4), you might even end up running it on VM using virt-manager. That is to say, at the end of the day, you do need a little bit of memory and CPU power...

    Here what do we need to run exactly:

    • RHQ 4.x (or JON 3.x)
    • PostgreSQL 8.4 (or Oracle)
    • RHQ Agent - downloaded from the server once running
    • Glassfish 3

    Once you have RHQ server running, with its agent and the appropriate DB, you'll need to start GF:

    
    $ cd ${GLASSFISH_HOME}
    $ ./bin/asadmin start-domain
    Waiting for domain1 to start ......
    Successfully started the domain : domain1
    domain  Location: /home/rpelisse/Products/glassfish3/glassfish/domains/domain1
    Log File: /home/rpelisse/Products/glassfish3/glassfish/domains/domain1/logs/server.log
    Admin Port: 4848
    Command start-domain executed successfully.
    

    Fortunately, you don't have to look for long to get the information you need, as GF kindly print out the information you need (JMX's URL) on its main log:

    
    $ grep -e jmx /home/rpelisse/Products/glassfish3/glassfish/domains/domain1/logs/server.log
    [#]
    

    To monitor this GF as a simple JMX Server, you just need to click on the platform hosting GF (ie "localhost") and select the folder JMX Servers. From there, you'll find an appropriate where to paste the JMX URL and the define the JVM used. Once this is done, you'll have to wait a little for the agent to connect to the server, and some other "RHQ magic" to happen.

    Once this is done, you'll have a new resource, called "Java VM", this is your GF:

    However, it does not really get better than this. This crude JMX integration only gave you the data above.

    Custom JMX MBeans

    It's a shame because if you look into GF's JMX Server using the JConsole, you'll quickly find a lot more information:

    Disclaimer: I'm (obviously) no GF's expert - however, while doing this research, I wanted to find an MBean with a somewhat "variable" attributes (database connection, number of session, ...), but I couldn't. I may have overlook something, but it looks like no "live" metrics seem to be exposed through JMX by GF...

    Fortunately, RHQ gives us a way to leverage all those extra MBeans. Indeed, before writing a full blown plugin, the project's documentation does mention this possibility. A sample project is provided within RHQ git repository (etc/samples/custom-jmx) and its content is reduce to the bare minimum:

    
    $ tree .
    .
    |-- pom.xml
    `-- src
    `-- main
    `-- resources
    `-- META-INF
    `-- rhq-plugin.xml
    

    ... So basically, two files, including one of the smallest pom ever:

    
    <?xml version="1.0"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0>"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.custom</groupId>
    <artifactId>custom-jmx-plugin</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>RHQ Custom JMX Plugin</name>
    <description>Plugin that monitors a set of custom MBeans</description>
    </project>
    

    The 'rhq-plugin.xml' descriptor is pretty straightforward and well documented:

    
    <?xml version="1.0" encoding="UTF-8" ?>
    <plugin name="GlassfishJmx"
            displayName="Glashfish JMX Plugin"
            version="1.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="urn:xmlns:rhq-plugin"
            xmlns:c="urn:xmlns:rhq-configuration">
    
       <depends plugin="JMX" useClasses="true"/>
       <service name="First Custom Service"
                description="Our first MBean custom service whose 'id' is static"
                discovery="org.rhq.plugins.jmx.MBeanResourceDiscoveryComponent"
                class="org.rhq.plugins.jmx.MBeanResourceComponent">
    
          <runs-inside>
             <parent-resource-type name="JMX Server" plugin="JMX"/>
          </runs-inside>
    
          <plugin-configuration>
             <c:simple-property name="objectName" readOnly="true" default="jmxapp:type=MyJmxObject,id=static"/>
          </plugin-configuration>
    
          <operation name="toUppercase"
                     displayName="String To Uppercase"
                     description="Converts the given string to all uppercase.">
             <parameters>
                <c:simple-property name="p1" type="string" required="true"/>
             </parameters>
             <results>
                <c:simple-property name="operationResult" type="string"/>
             </results>
          </operation>
    
          <metric property="RandomNumber"
                  displayName="Random Floating Point Number"
                  defaultOn="true"
                  displayType="summary"
                  defaultInterval="30000"
                  description="Emits a random number between 0.0 and 1.0"/>
       </service>
    </plugin>
    

    With this, you can turn any MBean from GF into a service which means:

    • RHQ can trigger any of the MBean's operation
    • RHQ can gather, as metrics, any of the MBean's attributes.

    Regarding the latter with GF, please remember my previous remarks on the lack of "dynamic" values in the GF's MBeans.

    Application deployment

    Based on the documentation (I didn't find the time to test this), it should be fairly easy with the RHQ Bundle system to deploy and un-deploy applications in GF. Once a new destination on the system (deploiement folder) is defined, a post install task can simply trigger the depoiement of the war now copied over to the host:

    
    ${GLASSFISH_HOME}/bin/asadmin deploy /path/to/war
    

    This will requires to wrap 'exec' task on the RHQ Bundle and will definitely not offer a nice error handling, but it should be enough to get started.

    A quick conclusion

    Overall, without a dedicated plugin for GF, one can already achieved a lot by customizing what is already available through JMX. However, to fully monitor GF, and the application deployed, the amount of custom JMX descriptors to produce might be discouraging. Unless the monitoring need on GF is rather simple, it does not look like a sane strategy to go this way. It would actually be probably easier to realize a dedicated plugin for GF (again IHMO).

    On the operation level, while customizing MBeans does provide access to the numerous operations of the already numerous GF's MBeans, crucial operations are missing: start/stop/restart. This means that if RHQ server gets notified that one instance of GF's is not available - i.e. that the JVM running it has crashed, there is nothing it can actually do. While there is probably hooks in the agent or RHQ to implement a simple "run-this-command-on-the-host-to-do-this-operation" on RHQ's agent, the fact remains this will be yet an other work to do, on top of the previous JMX integration.

    Another somewhat strong limitation is the small amount of information available on threads by applications deployed. While it may be possible to add one custom MBean by application run by GF, it is still unclear to me if one can easily retrieve such information as:

    • number of session per app, with their size
    • number of (web) threads per app
    • database connection pool usage per app.

    From my experience, those are very important metrics to monitor app servers in production.

    Down the road, all of this does NOT mean that GF cannot be monitored by RHQ, just that - as always, it mostly depends what you intend to actually to do. If just want RHQ to monitor GF's availability, and maybe check a couple of other things, you probably have enough here already. If you want RHQ to be the central deployment point in an environment featuring hundreds of GF's server, and you want to automatically recover from failed deployment bundled and server's crashes, it is probably a far more sound approach to start working on GF's plugin for JON, especially as it does not look that time consuming and difficult to implement...

    Last warning: This is the product of a quick investigation, done by one person, with decent knowledge of RHQ, but none of GF. There is no warranty here that my statements are definitive. I may have missed or overlooked something. Of course, if so, let me know I'll update this entry asap...

    Some links:

    • Manage and Administrate Glassfish 3 with AMX-JMX ;
    • RHQ's JMX Server ;
    • RHQ's writing plugins documentation.
    Last updated: May 31, 2023

    Recent Posts

    • Unleashing multimodal magic with RamaLama

    • Integrate Red Hat AI Inference Server & LangChain in agentic workflows

    • Streamline multi-cloud operations with Ansible and ServiceNow

    • Automate dynamic application security testing with RapiDAST

    • Assessing AI for OpenShift operations: Advanced configurations

    What’s up next?

     

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue