DEV Community

Cover image for Monitoring Hazelcast Metrics using JMX exporter
Nirjas Jakilim
Nirjas Jakilim

Posted on

Monitoring Hazelcast Metrics using JMX exporter

As distributed systems become more complex, monitoring becomes crucial for maintaining application performance and reliability. If you're using Hazelcast as your in-memory data grid, you'll want to keep a close eye on its performance metrics. Today, I'll walk you through setting up JMX exporter to monitor Hazelcast metrics effectively.

Why Monitor Hazelcast Metrics?

Before diving into the setup, let's understand why monitoring Hazelcast is essential. Hazelcast provides valuable insights into:

  • Memory usage and distribution
  • Network communication patterns
  • Cache hit/miss ratios
  • Queue sizes and processing times
  • Connection health and latency

These metrics help you optimize performance, troubleshoot issues, and make informed scaling decisions.

Prerequisites

Before we start, make sure you have:

  • Hazelcast instance (embedded or standalone)
  • JMX Prometheus Exporter JAR file
  • Basic understanding of JVM options and YAML configuration

Step 1: Enabling JMX API

The first step is enabling JMX (Java Management Extensions) on your Hazelcast instance. The process differs slightly between embedded and standalone deployments.

For Embedded Hazelcast

When running Hazelcast embedded within your application, add these JVM arguments to your application's startup command:

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=<portNo> -Dcom.sun.management.jmxremote.authenticate=false -Dhazelcast.jmx=true -javaagent:path_to_jmx_exporter_jar_file=<port>:/path_to_jmx_exporter_config/config.yaml 
Enter fullscreen mode Exit fullscreen mode

Important Security Note: Set -Dcom.sun.management.jmxremote.authenticate=true in production environments and configure proper authentication.

For Standalone Hazelcast

For standalone Hazelcast instances, navigate to your Hazelcast installation directory and edit the config/jvm.options file:

cd $HAZELCAST_HOME vim config/jvm.options 
Enter fullscreen mode Exit fullscreen mode

Add the same JVM arguments mentioned above to this file.

Step 2: Configuring JMX Exporter

Create a configuration file (typically named config.yaml) for the JMX exporter. This file defines how JMX metrics are transformed into Prometheus format:

#--- attrNameSnakeCase: true lowercaseOutputName: true lowercaseOutputLabelNames: true whitelistObjectNames: - "com.hazelcast:type=Metrics,*" rules: - pattern: "^com.hazelcast<type=Metrics, instance=(.*), prefix=(.*), tag([0-9]+)=(.*)><>(.+):" name: hazelcast_$5 attrNameSnakeCase: true labels: instance: $1 prefix: $2 tag$3: $4 - pattern: "^com.hazelcast<type=Metrics, instance=(.*), prefix=(.*)><>(.+):" name: hazelcast_$3 attrNameSnakeCase: true labels: instance: $1 prefix: $2 
Enter fullscreen mode Exit fullscreen mode

Let me break down this configuration:

  • attrNameSnakeCase: Converts attribute names to snake_case format
  • lowercaseOutputName: Ensures metric names are lowercase
  • whitelistObjectNames: Filters JMX objects to include only Hazelcast metrics
  • rules: Define patterns for transforming JMX metric names into Prometheus format

Step 3: Restart and Verify

After configuring everything, restart your Java application or Hazelcast instance. The metrics should become available at:

http://<server_ip>:<jmx_exporter_port>/metrics 
Enter fullscreen mode Exit fullscreen mode

Understanding the Metrics Format

Once everything is running, you'll see metrics in Prometheus format. Here are some examples of what to expect:

hazelcast_total_max_get_latency{instance="hz-instance",prefix="map",tag0="name=request-cache"} 1.0 hazelcast_priority_queue_size{instance="hz-instance",prefix="operation"} 0.0 hazelcast_connection_type{instance="hazelcastInstance",prefix="tcp.connection",tag0="endpoint=[localhost]:5000",tag1="bindAddress=[testserver]:5000"} 1.0 
Enter fullscreen mode Exit fullscreen mode

Each metric includes:

  • Metric name: Descriptive name of what's being measured
  • Labels: Key-value pairs providing context (instance, prefix, tags)
  • Value: The actual measurement

Common Troubleshooting Tips

Based on my experience implementing this setup, here are some issues you might encounter:

Port Conflicts: Ensure your JMX and exporter ports don't conflict with other services.

Configuration Path Issues: Double-check that the path to your config.yaml file is absolute and accessible.

Firewall Restrictions: Make sure the specified ports are open and accessible from your monitoring systems.

Memory Overhead: JMX monitoring adds some overhead, so monitor your application's memory usage after enabling it.

Best Practices

  1. Security First: Always enable authentication in production environments
  2. Resource Monitoring: Keep an eye on the additional memory and CPU overhead
  3. Selective Metrics: Use whitelist patterns to export only the metrics you need
  4. Regular Updates: Keep your JMX exporter version updated for better performance and security

Integration with Monitoring Stack

Once you have metrics exposed, you can integrate them with your existing monitoring stack:

  • Prometheus: Configure Prometheus to scrape the metrics endpoint
  • Grafana: Create dashboards to visualize Hazelcast performance
  • AlertManager: Set up alerts for critical thresholds

Conclusion

Monitoring Hazelcast with JMX exporter provides valuable insights into your distributed cache performance. While the initial setup requires some configuration, the visibility you gain into your system's behavior is invaluable for maintaining robust applications.

The key is starting simple and gradually expanding your monitoring scope as you understand which metrics matter most for your specific use case. Remember to balance comprehensive monitoring with system performance, and always prioritize security in production environments.

If you have already implemented this on your environment then I’d love to hear about your experiences and any additional tips you’ve discovered along the way! Thanks for your time!

Top comments (0)