Menu
Grafana Cloud

JVM integration for Grafana Cloud

A Java Virtual Machine (JVM) provides a runtime environment that converts Java bytecode into machine language, allowing computers to run Java programs. This integration enables the agent to send metrics to Grafana Cloud from JVM apps instrumented with Prometheus JVM client, Micrometer library (Springboot), or with OpenTelemetry.

This integration includes 2 useful alerts and 1 pre-built dashboard to help monitor and visualize JVM metrics.

Before you begin

To instrument your JVM application with Prometheus client, please follow the official instrumentation guide client_java.

Install JVM integration for Grafana Cloud

  1. In your Grafana Cloud stack, click Connections in the left-hand menu.
  2. Find JVM and click its tile to open the integration.
  3. Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send JVM metrics to your Grafana Cloud instance.
  4. Click Install to add this integration’s pre-built dashboard and alerts to your Grafana Cloud instance, and you can start monitoring your JVM setup.

Configuration snippets for Grafana Alloy

Simple mode

These snippets are configured to scrape a single JVM instance running locally with default ports.

First, manually copy and append the following snippets into your alloy configuration file.

Metrics snippets

alloy
discovery.relabel "metrics_integrations_integrations_jvm" {
	targets = [{
		__address__ = "localhost:1234",
	}]

	rule {
		target_label = "instance"
		replacement  = constants.hostname
	}
}

prometheus.scrape "metrics_integrations_integrations_jvm" {
	targets    = discovery.relabel.metrics_integrations_integrations_jvm.output
	forward_to = [prometheus.remote_write.metrics_service.receiver]
	job_name   = "integrations/jvm"
}

Advanced mode

The following snippets provide examples to guide you through the configuration process.

To instruct Grafana Alloy to scrape your JVM instances, manually copy and append the snippets to your alloy configuration file, then follow subsequent instructions.

Advanced metrics snippets

alloy
discovery.relabel "metrics_integrations_integrations_jvm" {
	targets = [{
		__address__ = "localhost:1234",
	}]

	rule {
		target_label = "instance"
		replacement  = constants.hostname
	}
}

prometheus.scrape "metrics_integrations_integrations_jvm" {
	targets    = discovery.relabel.metrics_integrations_integrations_jvm.output
	forward_to = [prometheus.remote_write.metrics_service.receiver]
	job_name   = "integrations/jvm"
}

To monitor your JVM instance, you must use a discovery.relabel component to discover your JVM Prometheus endpoint and apply appropriate labels, followed by a prometheus.scrape component to scrape it.

Configure the following properties within each discovery.relabel component:

  • __address__: The address to your JVM Prometheus metrics endpoint.
  • instance label: constants.hostname sets the instance label to your Grafana Alloy server hostname. If that is not suitable, change it to a value uniquely identifies this JVM instance.

If you have multiple JVM servers to scrape, configure one discovery.relabel for each and scrape them by including each under targets within the prometheus.scrape component.

Grafana Agent static configuration (deprecated)

The following section shows configuration for running Grafana Agent in static mode which is deprecated. You should use Grafana Alloy for all new deployments.

Dashboards

The JVM integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.

  • JVM overview

JVM overview

JVM overview

Alerts

The JVM integration includes the following useful alerts:

AlertDescription
JvmMemoryFillingUpWarning: JVM heap memory filling up.
JvmThreadsDeadlockedCritical: JVM deadlock detected.

Metrics

The most important metrics provided by the JVM integration, which are used on the pre-built dashboard and Prometheus alerts, are as follows:

  • java_lang_classloading_loadedclasscount
  • java_lang_memory_heapmemoryusage_committed
  • java_lang_memory_heapmemoryusage_max
  • java_lang_memory_heapmemoryusage_used
  • java_lang_memory_nonheapmemoryusage_committed
  • java_lang_memory_nonheapmemoryusage_max
  • java_lang_memory_nonheapmemoryusage_used
  • java_lang_operatingsystem_cpuload
  • java_lang_operatingsystem_processcputime
  • java_lang_operatingsystem_systemloadaverage
  • java_lang_runtime_starttime
  • java_lang_runtime_uptime
  • java_lang_threading_daemonthreadcount
  • java_lang_threading_peakthreadcount
  • java_lang_threading_threadcount
  • jvm_buffer_memory_used_bytes
  • jvm_buffer_pool_capacity_bytes
  • jvm_buffer_pool_used_bytes
  • jvm_buffer_total_capacity_bytes
  • jvm_classes_loaded
  • jvm_classes_loaded_classes
  • jvm_gc_collection_seconds_count
  • jvm_gc_collection_seconds_sum
  • jvm_gc_memory_allocated_bytes_total
  • jvm_gc_memory_promoted_bytes_total
  • jvm_gc_pause_seconds_count
  • jvm_gc_pause_seconds_max
  • jvm_gc_pause_seconds_sum
  • jvm_memory_bytes_committed
  • jvm_memory_bytes_max
  • jvm_memory_bytes_used
  • jvm_memory_committed_bytes
  • jvm_memory_max_bytes
  • jvm_memory_pool_allocated_bytes_total
  • jvm_memory_pool_bytes_committed
  • jvm_memory_pool_bytes_max
  • jvm_memory_pool_bytes_used
  • jvm_memory_pool_committed_bytes
  • jvm_memory_pool_max_bytes
  • jvm_memory_pool_used_bytes
  • jvm_memory_used_bytes
  • jvm_threads_current
  • jvm_threads_daemon
  • jvm_threads_daemon_threads
  • jvm_threads_deadlocked
  • jvm_threads_live_threads
  • jvm_threads_peak
  • jvm_threads_peak_threads
  • jvm_threads_state
  • jvm_threads_states_threads
  • process_cpu_seconds_total
  • process_cpu_usage
  • process_files_max
  • process_files_max_files
  • process_files_open
  • process_files_open_files
  • process_max_fds
  • process_open_fds
  • process_resident_memory_bytes
  • process_runtime_jvm_buffer_limit
  • process_runtime_jvm_buffer_limit_bytes
  • process_runtime_jvm_buffer_usage
  • process_runtime_jvm_buffer_usage_bytes
  • process_runtime_jvm_classes_loaded
  • process_runtime_jvm_classes_loaded_total
  • process_runtime_jvm_cpu_utilization
  • process_runtime_jvm_cpu_utilization_ratio
  • process_runtime_jvm_gc_duration_bucket
  • process_runtime_jvm_gc_duration_count
  • process_runtime_jvm_gc_duration_seconds_bucket
  • process_runtime_jvm_gc_duration_seconds_count
  • process_runtime_jvm_memory_allocation_count
  • process_runtime_jvm_memory_committed
  • process_runtime_jvm_memory_committed_bytes
  • process_runtime_jvm_memory_limit
  • process_runtime_jvm_memory_limit_bytes
  • process_runtime_jvm_memory_usage
  • process_runtime_jvm_memory_usage_bytes
  • process_runtime_jvm_system_cpu_load_1m
  • process_runtime_jvm_system_cpu_utilization
  • process_runtime_jvm_system_cpu_utilization_ratio
  • process_runtime_jvm_threads_count
  • process_start_time
  • process_start_time_seconds
  • process_uptime
  • process_uptime_seconds
  • runtime_uptime_milliseconds_total
  • system_cpu_count
  • system_cpu_usage
  • system_load_average_1m
  • up

Changelog

md
# 2.1.0 - September 2024

* Add new additional source:
    - OpenTelemetry JVM process metrics (with suffixes (add_metric_suffixes=true))

# 2.0.0 - August 2024

* New mixin based on JVM observability lib:
  - Add support for universal dashboard and alerts supporting metrics from different sources at the same time:
    - Prometheus library (compatible with older naming schema)
    - JMX exporter (both http and agent modes)
    - JVM metrics from Spring boot (micrometer)
    - OpenTelemetry JVM process metrics
  - Add JvmThreadsDeadlocked alert

# 1.0.0 - May 2024

* Update mixin to accommodate exporter metric name changes

# 0.0.5 - September 2023

* Update Grafana Agent configuration snippets to include filtered metrics used in gauge panels

# 0.0.4 - September 2023

* New Filter Metrics option for configuring the Grafana Agent, which saves on metrics cost by dropping any metric not used by this integration. Beware that anything custom built using metrics that are not on the snippet will stop working.
* New hostname relabel option, which applies the instance name you write on the text box to the Grafana Agent configuration snippets, making it easier and less error prone to configure this mandatory label.

# 0.0.3 - September 2022

* Update dashboard panels descriptions.

# 0.0.2 - October 2021

* Update mixin to latest version:
  - Update the datasource template variable label to 'Data Source'
  - Update all rate queries to use `$__rate_interval` so they respect the default resolution

# 0.0.1 - October 2020

* Initial release

Cost

By connecting your JVM instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see Active series and dpm usage and Cloud tier pricing.