Java application monitoring with the Prometheus JMX exporter

The official JMX exporter turns MBean values from Java applications into Prometheus metrics. This page explains how to choose between agent and standalone mode, write rule files and keep cardinality under control.

On this page

How the Prometheus JMX exporter exposes Java MBean metrics

Many teams running Tomcat, Kafka clients or legacy middleware already have a rich source of runtime data: the JVM exposes its internals and application components through JMX MBeans, but Prometheus cannot read those directly. The official JMX Exporter, an Apache-2.0 licensed collector maintained in the Prometheus project's repository, closes that gap. It connects to the JVM's MBeans, reads their values, converts them into Prometheus metrics and serves them over HTTP so Prometheus can scrape them like any other target. The Prometheus exporters and integrations page lists the exporter for a wide range of JVM-based applications, with Kafka as a named example. The work is configuration and rule files, not changes to application code, which matters when the application belongs to a vendor or a team that cannot rebuild it.

The exporter runs in one of two modes, and the choice shapes everything that follows. In the Java agent mode, the exporter loads inside the application's JVM as a -javaagent argument, so it reads MBeans in-process and avoids a network hop to a remote JMX port. In standalone mode, the exporter runs as its own process and connects to the application's JMX remote port over the network. Agent mode is usually simpler to keep close to the application, but it adds a library to the JVM startup line and must be tested against the Java version in use. Standalone mode keeps the exporter out of the application process, but it requires the JMX endpoint to be reachable and secured, which is a security decision in its own right. Confirm the exporter release you plan to use against its repository, since supported Java versions and configuration options change between releases.

Java agent or standalone mode: which fits your estate

In agent mode, the JMX exporter runs inside the same JVM as the application. You attach it at JVM start with a -javaagent argument pointing to the exporter JAR, plus a configuration file that defines which MBeans to export and how to name them. The exporter then serves a Prometheus endpoint from the application process, so Prometheus scrapes each JVM directly. This suits estates where each application team controls its own startup script or container image and can add a flag and a restart as part of a normal release.

  • Startup change: the agent flag and config path must be in the JVM start command, so every change to metric rules means a restart of the application.
  • Network surface: the exporter opens its own HTTP port inside the application host or pod, and no remote JMX port needs to be opened.
  • Ownership: application teams usually own the flag and the rule file, which keeps metric decisions close to the code that emits them.
  • Failure isolation: a fault in the exporter runs in the application process, so a bad rule or memory pressure from scraping can affect the application.

Confirm the current flags, supported Java versions and agent behavior in the JMX Exporter repository before you write a startup standard.

Setup sequence for JMX exporter rollout

This sequence takes a Java application from an unknown set of MBeans to a verified Prometheus scrape target, with each step closed by a check that shows the metrics are flowing. It keeps the mode decision, the allowlist and the scrape configuration in deliberate order so that cardinality problems are caught before they reach dashboards.

  1. Inventory applications and MBeans in scope

    Start by listing each Java application, its JVM version, how it starts and who owns it. For each one, connect with a JMX client such as JConsole or VisualVM and record the MBean domains and attributes that matter for the service, such as heap, thread pools, connection pools, request processors or consumer lag. Note which MBeans produce high-cardinality names, such as per-session or per-queue objects. The output is a short register per application that the team signs off before any configuration is written.

  2. Choose agent or standalone mode per application

    Decide, application by application, whether the exporter runs as a Java agent inside the JVM or as a standalone HTTP process that connects to a remote JMX port. The agent is usually simpler where you control the JVM startup flags and want metrics to share the process lifecycle. Standalone fits applications you cannot restart easily or where you want to keep the monitoring process separate from the application. Record the choice and the reason. Check that the team can name the JMX endpoint or the startup change that the chosen mode requires.

  3. Obtain the exporter jar from the official release

    Download the jmx_exporter jar from the official project repository on GitHub, using the release that your team has tested against your Java version. Verify the checksum published with the release and store the artifact in your internal artifact repository so every host runs the same file. Record the version in your configuration management. Check that the jar runs with a help or version command on a test host before it goes near production.

  4. Write the YAML rule file with an allowlist

    Create the rule file with an explicit allowlist of MBean patterns taken from the inventory, rather than a catch-all pattern that exports everything. Define name rewriting so metric names follow Prometheus naming conventions, and restrict labels to the few dimensions you need. Keep one rule file per application type and version it in Git. Check the file by running the exporter against a test instance and confirming that the output contains only the expected metric families and that the series count is within the limit your team set during the inventory.

  5. Wire the exporter into the JVM or process

    For agent mode, add the javaagent argument with the port and the rule file path to the JVM startup options, then restart a non-production instance. For standalone mode, start the exporter as a separate service with its configuration pointed at the application's JMX remote port, and make sure the JMX endpoint is reachable only from the exporter host. Check that the exporter's metrics endpoint responds locally and returns series that match the allowlist, and that the application still starts and serves its normal traffic.

  6. Add the scrape job to Prometheus

    Add a scrape job to the Prometheus configuration that targets the exporter port on each instance, using service discovery or a static list depending on how the estate is managed. Set a job label that matches the application inventory, and keep the scrape interval consistent with other jobs unless there is a documented reason to change it. Reload or restart Prometheus through your normal change process. Check the Prometheus targets page and confirm that each exporter target shows as up, and that a simple query for one of the new metrics returns a value.

  7. Validate metrics, cardinality and alerting

    Run a validation pass after the first full scrape cycle. Confirm that the number of active series per application matches the expected count from the inventory, that no label has unbounded values, and that the metrics answer the questions the inventory set out. Check that the rule file is in version control and that the team can reproduce a deployment from it. Then add alert rules only for metrics that have been verified. The output is a sign-off record listing targets, series counts, owners and the change history for the rule file.

Writing JMX rule files that map MBeans to clean metric names

Start every JMX rule file with a narrow allowlist of the MBeans you can name and explain, then widen it only when a dashboard or alert needs more. A rule file in the JMX exporter selects MBean attributes by object name pattern, renames them into Prometheus metric names through a pattern and a name template, and can move parts of the MBean key properties into labels. Each of those three steps is a place where a broad rule quietly multiplies series. A catch-all rule that matches every domain in a Tomcat or Kafka client JVM can produce thousands of gauges, many of them per-thread or per-connection, and most of them will never appear on a dashboard. Keep the first version to the attributes your runbooks already reference, such as heap usage, request processing counts or consumer lag, and record why each one exists.

Be deliberate about labels, because MBean key properties often carry values that change over time. Properties such as a session identifier, a thread name or a dynamically created connector name become label values, and each new value is a new series. Map only the properties with a small, stable set of values, such as a pool name or a request processor type, and drop the rest. Check the rule syntax, including how the pattern, name, type and labels fields interact, against the documentation in the JMX Exporter repository rather than copying examples from blog posts, since older examples often use patterns that match far more than intended. Confirm which exporter version your JVM and agent expect before you rely on any example.

Test rules against the live MBean tree before rollout. Connect a JMX client such as the one bundled with your JDK to a non-production instance, list the domains and attributes, and compare them with what the exporter's output shows on its metrics endpoint. Count the series produced by each rule and look for names that collide or change between restarts. Then run the same rule file in a staging Prometheus and check the active series count before and after the change. Treat any rule that produces a series count you cannot explain as unfinished. Document the final rule file in version control with a short note per block, so the team that inherits it can tell which metrics are required and which were added for a one-off investigation.

Keeping JMX cardinality down before it reaches Prometheus

JMX exposes a very large number of MBeans, and each distinct label combination becomes its own time series in Prometheus. The controls below work at three points: what the exporter is allowed to read, which labels it may attach, and how the resulting series are reviewed after rollout.

Drop unused MBean domains

Most JVMs expose far more MBeans than any dashboard uses, including container, thread pool and vendor-specific domains. Use the whitelistObjectNames or blacklistObjectNames settings in the exporter configuration to keep only the domains your alert rules and dashboards need. Before you finalize the list, run the exporter once and count the series it returns for each domain, so you can see which domains account for most of the volume.

JMX Exporter repository

Keep identifiers out of labels

Session IDs, request IDs, user names and query strings create a new series for every value, and they grow without bound on a busy application. Rules that copy MBean key properties into labels should map only fixed, bounded values such as pool names or cache names. Check the scraped output for any label whose value set keeps growing, because one such label can outweigh every other metric in the job.

Limit per-instance labels

Each JVM instance adds its own copy of every series, so labels such as process IDs, container hostnames or ephemeral ports multiply the count across the fleet. Keep the instance identity to the one label Prometheus already sets for the scrape target, and remove extra identity labels in relabeling. Ask the team that owns the application which identity labels they actually query, and drop the rest.

Review series counts after rollout

Series counts often jump after the first deployment of a new rule file, and the jump is easy to miss when no one is watching. Record the number of active series per job before and after the change, and compare them again after a full day of traffic, when more MBean attributes have appeared. A rule file that doubles the count without a clear dashboard or alert reason should go back for review before it stays in production.

Set scrape limits on the job

Prometheus scrape configuration accepts limits on the number of samples and labels a target can return in one scrape. These limits stop a misconfigured rule file from flooding the server when an application starts exposing new MBeans. Set the limit from the measured series count plus a margin you agree with the application team, and alert on targets that hit the limit so a change is noticed rather than silently truncated.

Prometheus storage docs

Retire metrics nobody reads

Dashboards and alert rules show which JMX series are actually used. Once a quarter, list the JMX metric names that no dashboard panel, alert rule or recording rule references, and remove them from the exporter configuration after the owning team agrees. Storage holds each series for the configured retention window, so removing unused series reduces disk and memory use for the whole retention period rather than only for new data.

Default retention
15 days

How JMX metrics flow from JVM to Prometheus alerts

The flow starts with MBeans inside the JVM, which the JMX exporter reads either as a Java agent in the same process or as a standalone process that connects to the JMX port. The exporter serves a metrics HTTP endpoint, and the Prometheus scrape job pulls from it into local storage, where alert rules send firing alerts to Alertmanager. Check the two trust boundaries: the JMX port, which should stay private, and the metrics endpoint, which should be reachable only by Prometheus.

Metric path from MBeans through the exporter, Prometheus and Alertmanager, with trust boundaries marked.

Mapping MBean domains to Prometheus metrics and labels

This table compares common JVM and application sources, the MBean patterns they typically live under, the metric name style the JMX exporter produces, and the labels worth keeping. Every example is illustrative, so confirm exact MBean names in your own JVM with a JMX console before writing rules. The main takeaway is that the MBean domain and key properties decide both the metric name and the label cardinality.

SourceExample MBean pattern (illustrative)Resulting metric style and label choices
JVM memoryjava.lang:type=Memory, heap and non-heap usage attributesGauge names under the jvm prefix with area or pool labels; keep labels to memory area only
Garbage collectionjava.lang:type=GarbageCollector,name=* collection count and timeCounters per collector name; use the collector name as a label and avoid per-run identifiers
Thread poolsCatalina or application executor MBeans with name and pool attributesGauges for active, pool size and queue depth; label by pool name, not by thread ID
Tomcat request processingCatalina:type=GlobalRequestProcessor,name="http-nio-8080" request and error countersCounters for requests, errors and bytes; label by connector, never by request URI
Kafka client metricskafka.producer or kafka.consumer domains with client-id and topic keysPer-client gauges and counters; topic labels can explode in count, so restrict which topics are exported
Legacy middleware beansVendor-defined domains with custom attributes, often with many instance keysDepends on the vendor; expect rename rules to be needed and confirm attribute types before mapping
Session and cache countsApplication MBeans exposing session or cache sizes per user or keyHigh risk: unbounded keys create one series per value, so exclude these or aggregate in the bean

Securing JMX endpoints and metrics endpoints

A JMX port or exporter endpoint gives access to far more than metrics, so the monitoring setup needs the same access control as any management interface. The cards below cover the JMX risk, how the metrics endpoint should be reached, the Prometheus settings that protect it, and the segmentation and checks that keep both out of reach of other networks.

Remote JMX is a management interface

A remote JMX port that accepts connections without authentication or TLS can expose management operations, not only read-only attribute values. Anyone who can reach it may be able to invoke MBean operations on the running JVM. Before go-live, confirm which remote JMX options the application starts with, whether authentication and SSL are required, and whether the port appears in any listener you have not reviewed. Treat remote JMX as admin access, not as a metrics feed.

Scrape the exporter, not JMX

The JMX exporter can run as a Java agent inside the process or as a standalone process that connects to JMX remotely. Both designs put an HTTP metrics endpoint in front of the data, so Prometheus should scrape that endpoint and never open a JMX connection itself. Keep the JMX listener bound to localhost or the exporter host where the design allows it. Confirm this choice in the rollout plan so the security review covers the exact listener that exists.

JMX Exporter repository

Restrict who can scrape the endpoint

The metrics endpoint should accept scrapes only from the Prometheus server, enforced by firewall rules or security groups that allow the exporter port from that host alone. Give the exporter port its own rule rather than relying on the application port range. Test the rule from a host outside the allowed source to confirm it is refused. Record the allowed source address in the change ticket so that a future Prometheus move updates the rule as well.

Protect the scrape path with TLS

Prometheus supports TLS and client certificate authentication, with TLS 1.2 as the minimum version. Use this for scrapes that cross a network boundary, and decide whether the exporter side will present a certificate or whether a reverse proxy will terminate TLS in front of it. HTTP basic authentication is also supported, but it should only run over TLS, because without TLS the credentials travel in cleartext. Confirm with your security team which certificate authority and rotation process apply to these scrape certificates.

Prometheus security model

Keep Prometheus admin functions off

Prometheus disables its admin HTTP APIs by default. The --web.enable-admin-api flag enables destructive operations, and --web.enable-lifecycle enables reload and shutdown endpoints. Leave both disabled on production servers unless a specific runbook needs them, and if they are needed, restrict them to an administrative network. Also check that the Prometheus web UI is reachable only by the teams who need it, since Prometheus has no built-in single sign-on and an authenticating reverse proxy is usually placed in front.

Check exporter targets and exposure

Confirm that no JMX exporter port is reachable from the public internet, from user networks, or from other tenants' segments. Scan the host from an outside network after each change to the firewall or load balancer configuration. Review the Prometheus target list to make sure every JVM endpoint is intended and that no unexpected host is being scraped. Where exporter abuse matters, note that the Prometheus security model warns that some exporters take targets from URL parameters, so keep the JMX exporter's own endpoint out of any shared proxy.

Common JMX exporter failures and how to fix them

This table maps the failures teams most often hit with the JMX exporter to their likely causes, the check to run and the direction of the fix. Use it as a triage list, then confirm each cause against the exporter repository documentation and your own JVM startup flags and configuration.

FailureLikely causeCheck and fix direction
Empty output from the rule fileRules do not match any MBean, the object name or attribute pattern is wrong, or the file is not loadedLoad the exporter endpoint and compare the MBean names from a JMX console with your rule patterns. Correct the patterns and confirm the config file path in the agent or standalone arguments.
Scrape target marked downExporter port not listening, a firewall or network policy blocks the scrape, or the scrape path or port in Prometheus differs from the exporterRequest the metrics endpoint directly from the Prometheus host. Align the port and path in the scrape job and open the port in the host or network policy.
JMX port refusedRemote JMX not enabled, bound to the wrong interface, or the agent and standalone mode point at different hostsCheck the JVM remote JMX flags and the target host and port used by standalone mode. Enable only the interface you need, and confirm the process was restarted after the change.
Metric explosion after rolloutRules capture high-cardinality labels such as session, request or client IDs, or wildcard patterns match every MBeanCount series per job before and after the change and inspect label values. Narrow the object name patterns, drop unused MBeans and keep labels to bounded values.
Renamed metrics breaking dashboardsA rule change altered the generated metric name, or the exporter version changed its naming behaviorDiff the exported metric names between the old and new configuration and versions. Pin the exporter version and restore names with explicit rule names, then update dashboards and alert rules in the same change.
Metrics stale or missing after JVM restartExporter is not started with the JVM, or the MBean only exists after the application initializesConfirm the agent argument is present on the running process. Check that the target MBean is registered at scrape time and adjust the scrape interval or startup order if needed.
Exporter error or high scrape durationToo many MBeans scanned, rules with expensive regular expressions, or a remote JMX connection with high latencyTime the scrape and review the rule count and patterns. Reduce scanned MBeans and simplify expressions, and move the exporter closer to the JVM where possible.

Questions teams ask before monitoring Java apps with JMX

What drives the cost of a JMX exporter rollout?

The main cost is people time, not software. The JMX Exporter is an official, Apache-2.0 licensed collector, and Prometheus itself has no paid enterprise edition, so the spend comes from engineering effort to identify the MBeans that matter, write and test rule files, wire up scraping and dashboards, and run the result. Costs rise with the number of applications, the number of JVM instances per application, how much custom rule logic each application needs, and how many teams must review changes. Infrastructure and storage are recurring costs that grow with the number of series you keep. Ask any quote to itemize the discovery, rule authoring, testing, handover and any retainer for ongoing upgrades separately.

How long does a JMX monitoring rollout take?

No duration is given here. The time depends mainly on how many Java applications are in scope, how many instances each one runs, how complex the rule files need to be, and how quickly application owners can review metric names and labels. A small set of applications with standard MBeans is a very different job from a fleet of legacy middleware with custom MBeans. A fixed-scope quote follows the written scope, and the timeline is agreed in writing before work starts.

What does the application team need to provide?

The application team is needed for decisions that only they can make. Expect to provide the list of applications and their JVM versions, the way each one is started, and whether the JVM can be restarted during a change window. They should also name the MBeans and business-relevant metrics they care about, confirm which metrics are safe to expose, and review the metric names and labels before they reach dashboards. Access to a non-production environment for testing the agent or standalone configuration is also needed.

Can our in-house team implement JMX monitoring alone?

Often yes, if the team already runs Prometheus and understands Java runtime behavior. The work is well defined: choose between the Java agent and standalone mode, write a rule file, check which MBeans produce series, and add scrape configuration. The harder parts are usually keeping label cardinality under control, handling legacy middleware with unusual MBean naming, and tuning the rule file so it does not expose sensitive or noisy attributes. A partner is most useful when the team lacks Java operations experience or when the rollout must be finished on a fixed date.

How are JMX exporter upgrades handled?

Upgrades are a planned task, not an afterthought. The exporter is maintained in its own repository, so the team should track its releases, read the change notes, and test any new version against the same rule files in a non-production environment before rollout. Agent-based deployments tie the exporter version to the application's startup configuration, so each upgrade needs a restart. Rule files also need regression checks, because a renamed MBean attribute can silently remove a series from dashboards and alerts. Ask whether a quote includes the upgrade cycle, or whether it is covered by a retainer for ongoing support.

Does Prometheus licensing add any cost to this work?

Prometheus is licensed under Apache-2.0 according to its GitHub repository, and there is no paid enterprise edition of the project itself. That means the license does not create a per-server or per-instance fee for the monitoring software. The cost comes from infrastructure to run Prometheus, storage for retained series, implementation work, and the people who operate the setup. Check the license terms of any separately deployed components, such as dashboards or long-term storage, because those are distinct projects with their own terms.

How much does JMX monitoring increase storage and infrastructure cost?

Storage grows with the number of active series, the scrape interval and the retention period. JMX exporters can produce many series per JVM, so an unfiltered rule file can increase memory and disk use quickly. Prometheus stores data in a local time series database with a default retention of 15 days, configurable by time or size, and local storage is not clustered or replicated. Ask for an estimate of series count per application before deciding retention, and confirm which environment will hold the data, because that determines the recurring infrastructure bill.

How DeployOpen scopes and runs JMX monitoring rollouts

DeployOpen plans, builds, documents and supports self-hosted open-source platforms inside your own infrastructure, and that includes Prometheus JMX exporter rollouts for Java applications. We start from the written scope, keep the exporter configuration under version control, and hand over the rules, runbooks and dashboards your team needs to operate the setup.

How we scope

  • Inventory the Java applications, middleware and Kafka clients that expose JMX, and record their JVM versions and deployment models.
  • Agree in writing whether the exporter runs as a Java agent or standalone, and which MBeans are in and out of scope.
  • Set a cardinality budget and the alert scenarios the rollout must cover before any rule files are written.

How we build

  • Write and version-control the JMX exporter rule files, with allowlists that limit MBean selection to the agreed metrics.
  • Test each rule file against a non-production JVM and confirm the scraped series count stays within the agreed budget.
  • Wire the scrape jobs and alert rules into your Prometheus setup and check that alerts fire and resolve as designed.

How we hand over

  • Deliver the configuration, rule files, alert definitions and a runbook for each exporter, stored in your own repository.
  • Walk your platform and application teams through how to add a new MBean rule and review its label impact.
  • Document the verification steps and any open items to confirm with your application owners before go-live.

How we support

  • Offer ongoing support, upgrades and continuous testing for the exporter and its rules as a retainer, if you want it.
  • Review new JVM, middleware or exporter releases against your rule files and report any changes that affect metric names.
  • Provide the fixed-scope engagement terms in writing, so changes to scope are agreed before extra work starts.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.