activemq.org › Handbook › ActiveMQ monitoring with JMX, Jolokia and Prometheus
HandbookActiveMQ monitoring with JMX, Jolokia and Prometheus
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) | Attribute | What to look for |
|---|---|---|
Queue: type=Broker,brokerName=…,destinationType=Queue,destinationName=… | QueueSize | Messages waiting in the queue. A number that keeps climbing means consumers are not keeping up. |
| Queue or topic | ConsumerCount | Zero on a queue that should be consumed usually means a consumer application is down. |
| Queue or topic | EnqueueCount, DequeueCount | Cumulative counters; the change between two samples gives you a rate in and out. |
| Queue or topic | ExpiredCount | Messages that expired before anyone consumed them. |
Broker: type=Broker,brokerName=… | MemoryPercentUsage, StorePercentUsage | How close the broker is to its configured memory and store limits (MemoryLimit, StoreLimit). |
| Broker | TotalConsumerCount, TotalMessageCount, TotalEnqueueCount, TotalDequeueCount | Broker-wide totals for a dashboard overview. |
Health: type=Broker,brokerName=…,service=Health | CurrentStatus | The 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(orReferer) header that matches an<allow-origin>entry. The defaults are the console's own loopback addresses, such ashttp://localhost:8161, and non-browser clients have to send one of them. - Read-only by default. The permitted commands are
read,list,versionandsearch; 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.
- Download
jmx_prometheus_javaagent-1.7.0.jarfrom the exporter's 1.7.0 release on GitHub. - Write a rules file. The exporter repository ships an ActiveMQ example,
examples/activemq.yml; an excerpt:
It turns queue and topic attributes intolowercaseOutputName: 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: $2activemq_queue_*andactivemq_topic_*metrics labelled by destination, broker connections intoactivemq_connections, and the broker's*PercentUsageattributes intoactivemq_*_usage_ratiogauges scaled by 0.01. - Add the agent to the broker's JVM options.
bin/setenvbuildsACTIVEMQ_OPTSand 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:
TheACTIVEMQ_OPTS="$ACTIVEMQ_OPTS -javaagent:/opt/jmx_exporter/jmx_prometheus_javaagent-1.7.0.jar=9404:/opt/jmx_exporter/activemq.yml"9404:activemq.ymlargument form listens on0.0.0.0:9404; the<host>:<port>:<yaml>form binds a specific address instead. - Restart the broker and open
http://<broker-host>:9404/metricsto confirm the metrics appear. - Add a Prometheus scrape job that targets the broker host on port 9404.
- 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.
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
Originheader that matches<allow-origin>. - JConsole cannot see the broker from another machine. Remote JMX is off by default; enable the port in
bin/setenvas 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 injolokia-access.xmlexplain 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
- ActiveMQ web console: URL, login and password
- ActiveMQ ports: defaults and how to change them
- Dead letter queue (DLQ): how ActiveMQ handles messages it cannot deliver
- ActiveMQ Artemis vs ActiveMQ Classic: differences and migration
- All handbook 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
- ActiveMQ Classic: JMX activemq.apache.org
- ActiveMQ Classic: REST (Jolokia management API) activemq.apache.org
- ActiveMQ 6.4.0 conf/jolokia-access.xml (GitHub) raw.githubusercontent.com
- Jolokia reference: Jolokia protocol jolokia.org
- ActiveMQ 6.4.0 bin/setenv (GitHub) raw.githubusercontent.com
- Prometheus JMX exporter 1.7.0: Java agent raw.githubusercontent.com
- Prometheus JMX exporter: examples/activemq.yml raw.githubusercontent.com
- Grafana documentation: Prometheus data source grafana.com