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

Java monitoring for custom targets with Cryostat

November 2, 2021
Andrew Azores Hareet Dhillon
Related topics:
JavaKubernetesOpen source
Related products:
Red Hat JBoss Enterprise Application PlatformRed Hat OpenShift

Share:

    By default, Cryostat automatically recognizes discoverable, valid targets with remote Java Management Extensions (JMX) and JMX-RMI-enabled connectivity. Discoverability is based on various mechanisms, including Kubernetes API-based service endpoints and the Java Discovery Protocol (JDP).

    With Cryostat 2.0, developers can now create connections by providing custom URLs for known potential Java application targets that are valid but not yet discoverable. You can save custom target definitions so they are available even after the Cryostat instance restarts. This feature is available on the Cryostat web front-end through the Create Target functionality introduced in this article.

    Cryostat 2.0 also introduces the new clientlib directory. By adding target application JARs to this directory, you can specify custom connection protocols for any custom targets you create. We'll show you how to add a custom target that uses one such connection protocol.

    Read all of the articles in this series:

    • Part 1: Get started with Cryostat 2.0
    • Part 2: Configuring Java applications to use Cryostat
    • Part 3: Java monitoring for custom targets with Cryostat
    • Part 4: Automating JDK Flight Recorder in containers
    • Part 5: Creating Custom JFR event templates with Cryostat 2.0

    Note: Cryostat is JDK Flight Recorder for Kubernetes or Red Hat OpenShift. The Red Hat build of Cryostat 2.0 is now widely available in technology preview. The Red Hat build includes the Cryostat Operator to simplify and automate Cryostat deployment on Red Hat OpenShift.

    Prerequisites and setup

    For this demonstration, we will connect to a custom target with a client-defined connection protocol. As a prerequisite, you must have Cryostat installed and running on a Red Hat OpenShift cluster via the Cryostat Operator. See Cryostat.io for installation details.

    We'll use a simple WildFly application for our target. First, we need to add the application to the same namespace where our Cryostat instance is running:

    
    oc new-app quay.io/andrewazores/wildfly-demo:v0.0.2 && oc expose svc wildfly-demo --port=8082
    
    

    Now that the application is running on the cluster, we'll see it alongside the cryostat-operator and the Cryostat instance when we enter oc status.

    Note: See the previous article in this series for instructions for configuring Java applications to use Cryostat. See the end of this article for more ways to learn about Cryostat.

    Adding the client-defined connection protocol

    The application listens on port 9990 using the JMX remote+http protocol, but not JMX-RMI, which is Cryostat's default connection protocol. For the Cryostat instance to recognize and communicate with our target application (that is, accept a custom connection protocol), we must supply it with additional JARs.

    Download the WildFly client JAR

    For a WildFly application, the JARs can be obtained by downloading the full WildFly release. The version chosen must correspond to the one used to create the application, which in this case is version 23.0.1.Final. So, we need to download the Jakarta EE Full & Web Distribution tarball for this version. Once downloaded, we'll extract the tarball as follows:

    
    tar -xvf ~/Downloads/wildfly-23.0.1.Final.tar.gz
    
    

    The required jboss-client.jar is located in the extracted wildfly-23.0.1.Final/bin/client/ directory.

    Add the client JAR to clientlib

    Now that we have the required JAR, we only need to add it to the clientlib directory in the persistent volume mounted to our Cryostat instance. First, we need to get the name of the pod that houses the instance:

    
    oc get pods -l app=cryostat-sample
    
    

    Now that we know the pod name, we can transfer the JARs using the oc cp command:

    
    oc cp ~/Downloads/wildfly-23.0.1.Final/bin/client/jboss-client.jar ${PROJECT_NAME}/${CRYOSTAT_POD_NAME}:/opt/cryostat.d/clientlib.d
    
    

    Note: The PROJECT_NAME is the name of the project (i.e., namespace) containing your cluster and CRYOSTAT_POD_NAME is your result from running the previous command.

    Restart your Cryostat instance

    Because we've added the JARs to the Cryostat classpath, we need to restart the Cryostat instance for the file to be loaded:

    
    oc rollout restart deployment/cryostat-sample -n ${PROJECT_NAME}
    
    

    Adding the custom target for Cryostat monitoring

    Once the pod is back up and running, we can add the WildFly application as a custom target for Cryostat to monitor. First, we need to get the IP address of the pod housing the application.

    Get the pod name and IP address

    Start by getting the pod name:

    
    oc get pods -l deployment=wildfly-demo
    
    

    Now, use the pod name to get the IP address:

    
    oc get pod ${WILDFLY_POD_NAME} -o jsonpath='{.status.podIP}' ; echo
    
    

    Note: WILDFLY_POD_NAME is your result from running the previous command.

    Add WildFly as a custom target

    Now that the IP address is known, we can go ahead and add the WildFly application as a custom target.

    To use Cryostat's web front-end, check oc status and follow the application URL for the cryostat-sample service. When prompted for an authorization token, provide your OpenShift account token, which you can retrieve using oc whoami -t. Figure 1 shows the Cryostat login page.

    Screenshot of the Cryostat web interface login page.
    Figure 1. The Cryostat login page.

    Press the + icon beside Target JVM to create the custom target. For your connection URL, enter service:jmx:remote+http://${IP_ADDRESS}:9990, where IP_ADDRESS is your address for the WildFly application pod. For the Alias, we’ll go with “WildFly," as shown in Figure 2.

    Screenshot of the Cryostat web interface for creating a custom target definition.
    Figure 2. Creating a custom target definition.

    The screen in Figure 3 confirms the target was created.

    Screenshot of the Cryostat web interface confirming target creation.
    Figure 3. Confirmation the target was created.

    Authenticating with the target JVM

    Once the WildFly target is created, we can select it and navigate to Recordings, as shown in Figure 4.

    Screenshot of the Cryostat web interface and selecting the newly-created target.
    Figure 4. Select the newly-created target.

    We will be prompted to authenticate with the target JVM (i.e., the WildFly application). The application is set up to use JMX authentication with the username “admin” and password “password." Figure 5 shows the authentication screen.

    Screenshot of the Cryostat web interface prompting for credentials to connect to the new target.
    Figure 5. Enter your credentials to connect to the new target.

    Once we’re all set up, we can create a new flight recording on the WildFly target application, as shown in Figure 6.

    Screenshot of the Cryostat web interface when starting a new recording on the target.
    Figure 6. Starting a new recording on the custom target.

    Figure 7 shows that we were successful.

    Screenshot of the Cryostat web interface displaying the recording running on the target.
    Figure 7. The recording running on the target.

    Conclusion

    In this article, you've learned how to define a custom target for Cryostat monitoring using a client-defined protocol. Once you have set up your custom target in Cryostat, you may interact with it in a variety of ways. Visit Cryostat.io and see the following articles for details:

    • Introduction to Cryostat: JDK Flight Recorder for containers
    • New features in Cryostat 2.0, plus tips for getting started
    • Tutorial: Configuring Java applications to use Cryostat
    Last updated: September 20, 2023

    Related Posts

    • Introduction to Cryostat: JDK Flight Recorder for containers

    • Announcing Cryostat 2.0: JDK Flight Recorder for containers

    • Configuring Java applications to use Cryostat

    Recent Posts

    • Our top 10 articles of 2025 (so far)

    • The benefits of auto-merging GitHub and GitLab repositories

    • Supercharging AI isolation: microVMs with RamaLama & libkrun

    • Simplify multi-VPC connectivity with amazon.aws 9.0.0

    • How HaProxy router settings affect middleware applications

    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
    © 2025 Red Hat

    Red Hat legal and privacy links

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

    Report a website issue