Independent ActiveMQ handbook · archive of the 2004–2007 project site
Independent guide. Not the Apache ActiveMQ project site and not affiliated with the Apache Software Foundation. ActiveMQ and Apache are trademarks of the ASF. Official documentation: activemq.apache.org.

activemq.org › Handbook › ActiveMQ monitoring with JMX, Jolokia and Prometheus

Handbook

ActiveMQ monitoring with JMX, Jolokia and Prometheus

Checked against ActiveMQ Classic 6.4.0, 6.3.3 and 5.19.12 and Apache Artemis 2.57.0 on . Independent guide; sources are listed at the end. Official documentation: activemq.apache.org and artemis.apache.org.

ActiveMQ is monitored through JMX: the broker, every queue and topic, and every connection is exposed as an MBean with counters such as queue size, consumer count and memory usage. You can read those MBeans with a JMX client such as JConsole, over HTTP through the Jolokia REST endpoint that ships with the broker at /api/jolokia, or by exporting them to Prometheus with the JMX exporter and charting them in Grafana.

This page covers ActiveMQ, often called ActiveMQ Classic. The official documentation is at activemq.apache.org, and the configuration details below come from the 6.4.0 release files listed under Sources. For Apache Artemis (formerly ActiveMQ Artemis), see ActiveMQ Classic vs Artemis.

Which ActiveMQ metrics should you watch?

The official JMX reference lists the MBeans and their attributes. A practical starting set:

MBean (object name)AttributeWhat to look for
Queue: type=Broker,brokerName=…,destinationType=Queue,destinationName=…QueueSizeMessages waiting in the queue. A number that keeps climbing means consumers are not keeping up.
Queue or topicConsumerCountZero on a queue that should be consumed usually means a consumer application is down.
Queue or topicEnqueueCount, DequeueCountCumulative counters; the change between two samples gives you a rate in and out.
Queue or topicExpiredCountMessages that expired before anyone consumed them.
Broker: type=Broker,brokerName=…MemoryPercentUsage, StorePercentUsageHow close the broker is to its configured memory and store limits (MemoryLimit, StoreLimit).
BrokerTotalConsumerCount, TotalMessageCount, TotalEnqueueCount, TotalDequeueCountBroker-wide totals for a dashboard overview.
Health: type=Broker,brokerName=…,service=HealthCurrentStatusThe broker's own health summary.

The full names start with org.apache.activemq:. The official examples use a broker called localhost, as in org.apache.activemq:type=Broker,brokerName=localhost; replace it with the brokerName set on the <broker> element of your activemq.xml.

JMX and JConsole

JMX is on by default (useJMX defaults to true). On the broker machine you can run jconsole, and the broker appears in the list of local connections. Remote JMX connections are not enabled by default, for security reasons.

To open a remote JMX port, use the commented-out lines in bin/setenv. From bin/setenv in ActiveMQ 6.4.0:

# ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.port=11099 "
# ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.password.file=${ACTIVEMQ_CONF}/jmx.password"
# ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.access.file=${ACTIVEMQ_CONF}/jmx.access"
# ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.ssl=false"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote"

Uncomment the port, password-file and access-file lines, set your own users in conf/jmx.password and conf/jmx.access, and think twice about the last commented line: ssl=false sends JMX traffic, including the login, unencrypted. A JMX client then connects with a URL of the form service:jmx:rmi:///jndi/rmi://<host>:<port>/jmxrmi and is asked to log in.

Jolokia: ActiveMQ's REST monitoring endpoint

Since ActiveMQ 5.8 the broker exposes its MBeans over HTTP through the Jolokia JMX-HTTP bridge, at http://localhost:8161/api/jolokia/. It is served on port 8161 alongside the web console and the official examples log in with the same admin account.

The REST page on activemq.apache.org shows plain GET requests, but the 6.4.0 Jolokia policy (conf/jolokia-access.xml) is stricter than that page:

  • POST only. HTTP methods are restricted to POST to block GET-based CSRF and SSRF.
  • Origin header required. Every request must carry an Origin (or Referer) header that matches an <allow-origin> entry. The defaults are the console's own loopback addresses, such as http://localhost:8161, and non-browser clients have to send one of them.
  • Read-only by default. The permitted commands are read, list, version and search; write and exec are refused except for the specific operations listed under <allow>.

Jolokia's POST format is a JSON object with a type, an mbean and, for reads, an attribute. An example request built from the REST page's MBean and the Jolokia protocol reference, reading the broker's consumer count on ActiveMQ 6.4.0:

curl -u admin:admin \
  -H "Origin: http://localhost:8161" \
  -H "Content-Type: application/json" \
  -d '{"type":"read","mbean":"org.apache.activemq:type=Broker,brokerName=localhost","attribute":"TotalConsumerCount"}' \
  http://localhost:8161/api/jolokia/

Jolokia answers with a JSON object for each request, and you can send several requests at once as a JSON array. That makes it a convenient source for scripts and health checks that do not speak JMX. If you open the console to other hosts, add their exact scheme://host:port to the <allow-origin> list, as the comments in jolokia-access.xml describe.

Prometheus and Grafana with the JMX exporter

To get ActiveMQ metrics into Prometheus, use the Prometheus project's JMX exporter (prometheus/jmx_exporter on GitHub), which reads MBean values and serves them on an HTTP /metrics endpoint for Prometheus to scrape. Its documentation calls the Java agent, which runs inside the target JVM, the recommended deployment mode for most users; it reads the broker's MBeans locally, so you do not need to open a remote JMX port.

  1. Download jmx_prometheus_javaagent-1.7.0.jar from the exporter's 1.7.0 release on GitHub.
  2. Write a rules file. The exporter repository ships an ActiveMQ example, examples/activemq.yml; an excerpt:
    lowercaseOutputName: true
    lowercaseOutputLabelNames: true
    ...
    - pattern: org.apache.activemq<type=Broker, brokerName=(\S*), destinationType=Queue, destinationName=(\S*)><>(\w+)
      name: activemq_queue_$3
      attrNameSnakeCase: true
      type: GAUGE
      labels:
        destination: $2
    It turns queue and topic attributes into activemq_queue_* and activemq_topic_* metrics labelled by destination, broker connections into activemq_connections, and the broker's *PercentUsage attributes into activemq_*_usage_ratio gauges scaled by 0.01.
  3. Add the agent to the broker's JVM options. bin/setenv builds ACTIVEMQ_OPTS and includes a commented example that appends to it (#ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS -Dorg.apache.activemq.audit=true"); add a line in the same style, adjusting the paths:
    ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS -javaagent:/opt/jmx_exporter/jmx_prometheus_javaagent-1.7.0.jar=9404:/opt/jmx_exporter/activemq.yml"
    The 9404:activemq.yml argument form listens on 0.0.0.0:9404; the <host>:<port>:<yaml> form binds a specific address instead.
  4. Restart the broker and open http://<broker-host>:9404/metrics to confirm the metrics appear.
  5. Add a Prometheus scrape job that targets the broker host on port 9404.
  6. In Grafana, the Prometheus data source is preinstalled: point it at your Prometheus server and build panels with PromQL, for example queue depth per destination.
The example rules match ActiveMQ Classic's org.apache.activemq MBean names. Before reusing a rules file for another broker, compare its patterns with the MBeans you see in JConsole or through Jolokia's list command.

Common problems

  • Jolokia returns an error for a GET request copied from an older guide. On 6.4.0 only POST is allowed; send the JSON body shown above.
  • Jolokia rejects a script that works in the browser. The script is probably not sending an Origin header that matches <allow-origin>.
  • JConsole cannot see the broker from another machine. Remote JMX is off by default; enable the port in bin/setenv as above, or monitor through Jolokia or the exporter instead.
  • Purge or other management operations fail over Jolokia. The 6.4.0 policy only allows read commands plus a short list of browsing and health operations, and explicitly denies operations such as purge. The comments in jolokia-access.xml explain how to open a single operation by adding it to <allow>; do that only for operations you need.

The JMX reference also mentions command-line utilities; the 2006 archive page on the command-line tools shows their original form.

Frequently asked questions

How do I monitor ActiveMQ?

Read the broker's JMX MBeans: with JConsole on the broker host, over HTTP through the bundled Jolokia endpoint at /api/jolokia, or with the Prometheus JMX exporter for Prometheus and Grafana dashboards.

What is the ActiveMQ Jolokia URL?

http://localhost:8161/api/jolokia/ on the broker host. In ActiveMQ 6.4.0 it accepts only POST requests with a JSON body and an Origin header that matches the allow-origin list in conf/jolokia-access.xml.

How do I get ActiveMQ metrics into Prometheus?

Run the Prometheus JMX exporter as a Java agent inside the broker's JVM (for example through ACTIVEMQ_OPTS in bin/setenv) with a rules file such as the exporter's examples/activemq.yml, then scrape its /metrics endpoint.

Which ActiveMQ metrics matter most?

Per queue: QueueSize, ConsumerCount, EnqueueCount, DequeueCount and ExpiredCount. Per broker: MemoryPercentUsage and StorePercentUsage, plus the Health MBean's CurrentStatus.

Is remote JMX enabled in ActiveMQ by default?

No. Remote JMX connections are not enabled by default; bin/setenv contains commented-out lines for a remote port, password file and access file.

Related guides

From the 2006 archive

The original ActiveMQ documentation on these topics, kept as it was published here in 2004–2007. It describes ActiveMQ 4.x and older.

Sources

  1. ActiveMQ Classic: JMX activemq.apache.org
  2. ActiveMQ Classic: REST (Jolokia management API) activemq.apache.org
  3. ActiveMQ 6.4.0 conf/jolokia-access.xml (GitHub) raw.githubusercontent.com
  4. Jolokia reference: Jolokia protocol jolokia.org
  5. ActiveMQ 6.4.0 bin/setenv (GitHub) raw.githubusercontent.com
  6. Prometheus JMX exporter 1.7.0: Java agent raw.githubusercontent.com
  7. Prometheus JMX exporter: examples/activemq.yml raw.githubusercontent.com
  8. Grafana documentation: Prometheus data source grafana.com