Red Hat Wimplicit

Monitoring Red Hat AMQ 7

Red Hat AMQ 7 includes some tools for monitoring the Red Hat AMQ broker. These tools allow you to get metrics about the performance and behavior of the broker and its resources. Metrics are very important for measuring performance and for identifying issues that are causing poor performance.

The following components are included for monitoring the Red Hat AMQ 7 broker:

  • Management web console that is based on Hawtio: This console includes some perspectives and dashboards for monitoring the most important components of the broker.
  • A Jolokia REST-like API: This provides full access to JMX beans through HTTP requests.
  • Red Hat JBoss Operation Network: This is an enterprise, Java-based administration and management platform for developing, testing, deploying, and monitoring Red Hat JBoss Middleware applications.

These tools are incredible and fully integrated with the original product. However, there are cases where Red Hat AMQ 7 is deployed in environments where other tools are used to monitor the broker, for example, jmxtrans.

jmxtrans is a popular monitoring tool for Java-based applications. It connects to a JVM via JMX, collects metrics, and sends the data to the back end of your choice. Included in jmxtrans is an agent to be deployed inside the application that is to be monitored. This blog shows how to integrate the jmxtrans agent with Red Hat AMQ 7.

Set Up Red Hat AMQ 7

First, you need to get the latest stable version of the jmxtrans agent. It is possible to get it from the following places:

Copy the jmxtrans-agent JAR file into the $ARTEMIS_INSTANCE/lib folder.

To load the agent at bootstrap time, you need to modify the artemis file in the $ARTEMIS_INSTANCE/bin folder. It defines an environment variable (AMQ_JMSTRANS_AGENT) to update the startup command line of the broker. This environment variable allows you to configure when to use the jmxtrans agent:

# Add jmxtrans agent
if [ "$AMQ_JMXTRANX_AGENT" = "true" ]; then
  echo "Using jmxtrans agent to collect metrics. Configuration loaded from $ARTEMIS_INSTANCE/etc/jmxtrans-agent.xml"
  JMXTRANX_OPTS="-Xbootclasspath/p:$ARTEMIS_INSTANCE/etc -javaagent:$ARTEMIS_INSTANCE/lib/jmxtrans-agent.jar=$ARTEMIS_INSTANCE/etc/jmxtrans-agent.xml"
fi

Next, you should load this configuration with the startup command line defined in the artemis file, as follows:

exec "$JAVACMD" \
 $JAVA_ARGS \
 $JMXTRANX_OPTS -Xbootclasspath/a:"$LOG_MANAGER" \
 -Djava.security.auth.login.config="$ARTEMIS_INSTANCE/etc/login.config" \
 $ARTEMIS_CLUSTER_PROPS \
 -classpath "$CLASSPATH" \
 -Dartemis.home="$ARTEMIS_HOME" \
 -Dartemis.instance="$ARTEMIS_INSTANCE" \
 -Djava.library.path="$ARTEMIS_HOME/bin/lib/linux-$(uname -m)" \
 -Djava.io.tmpdir="$ARTEMIS_INSTANCE/tmp" \
 -Ddata.dir="$ARTEMIS_DATA_DIR" \
 -Djava.util.logging.manager="$ARTEMIS_LOG_MANAGER" \
 -Dlogging.configuration="$ARTEMIS_LOGGING_CONF" \
 $DEBUG_ARGS \
 org.apache.activemq.artemis.boot.Artemis "$@"

Defining Queries and Metrics

The jmstrans agent allows you to define different queries to collect metrics from JMX beans. These queries are defined in the jmxtrans-agent.xml file, which is located in the $ARTEMIS_INSTANCE/etc folder. The queries will define the JMX beans and the attributes to be collected. The following shows a sample to get metrics from addresses and queues.

<queries>
  <!-- Addresses -->
  <query objectName="org.apache.activemq.artemis:broker=*,component=addresses,address=*"
         attributes="MessageCount,NumberOfMessages,NumberOfPages,QueueNames"
         resultAlias="service=amq7,host=#hostname#,broker=%broker%,address=%address%,attribute.#attribute#"/>
 
  <!-- Queues -->
  <query objectName="org.apache.activemq.artemis:broker=*,component=addresses,address=*,subcomponent=queues,routing-type=*,queue=*"
         attributes="ConsumerCount,MaxConsumers,DeliveringCount,MessageCount,MessagesAcknowledged,MessagesAdded,MessagesExpired,MessagesKilled"
         resultAlias="service=amq7,host=#hostname#,broker=%broker%,address=%address%,queue=%queue%,artemis.addresses.#attribute#"/>
</queries>

Other queries to get other metrics in the JMX tree are also valid.

Getting Metrics from the Console

jmxtrans includes several output writers to send the collected metrics to external services, for example, as Graphite, CSV files, and InfluxDB. The output writers are defined in the jmxtrans-agent.xml file as follows:

 <!-- Output Writers -->
 <outputWriter class="org.jmxtrans.agent.ConsoleOutputWriter" />

This block defines the console output writer, so the metrics will be shown as messages in the server console log.

If you now start Red Hat AMQ 7, the output will be similar to this:

$ export AMQ_JMXTRANX_AGENT=true
$ ./bin/artemis run
Using jmxtrans agent to collect metrics. Configuration loaded from /opt/amq/brokers/broker01-master/etc/jmxtrans-agent.xml
2018-06-04 17:14:39.103 INFO [main] org.jmxtrans.agent.JmxTransAgent - Starting 'JMX metrics exporter agent: 1.2.8' with configuration '/opt/amq/brokers/broker01-master/etc/jmxtrans-agent.xml'...
2018-06-04 17:14:39.113 INFO [main] org.jmxtrans.agent.JmxTransAgent - PropertiesLoader: Empty Properties Loader
2018-06-04 17:14:39.445 INFO [main] org.jmxtrans.agent.JmxTransExporter - Configuration reload interval: 10secs
2018-06-04 17:14:39.445 INFO [main] org.jmxtrans.agent.JmxTransAgent - JmxTransAgent started with configuration '/opt/amq/brokers/broker01-master/etc/jmxtrans-agent.xml'
 __ __ ____ ____ _
 /\ | \/ |/ __ \ | _ \ | |
 / \ | \ / | | | | | |_) |_ __ ___ | | _____ _ __
 / /\ \ | |\/| | | | | | _ <| '__/ _ \| |/ / _ \ '__|
 / ____ \| | | | |__| | | |_) | | | (_) | < __/ |
 /_/ \_\_| |_|\___\_\ |____/|_| \___/|_|\_\___|_|

Red Hat JBoss AMQ 7.1.0.GA
2018-06-04 17:14:40,370 INFO [org.apache.activemq.artemis.integration.bootstrap] AMQ101000: Starting ActiveMQ Artemis Server
...

After some seconds, you can see that the jmxtrans agent is collecting metrics and exporting them to the console (using the ConsoleOutputWriter):

2018-06-04 17:14:43,740 INFO [org.apache.activemq.artemis] AMQ241001: HTTP Server started at http://localhost:8161
2018-06-04 17:14:43,740 INFO [org.apache.activemq.artemis] AMQ241002: Artemis Jolokia REST API available at http://localhost:8161/console/jolokia
2018-06-04 17:14:43,741 INFO [org.apache.activemq.artemis] AMQ241004: Artemis Console available at http://localhost:8161/console
service=amq7,host=localhost,broker=0_0_0_0,address=DLQ,attribute.MessageCount 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=DLQ,attribute.NumberOfMessages 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=DLQ,attribute.NumberOfPages 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=DLQ,attribute.QueueNames DLQ 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=ExpiryQueue,queue=ExpiryQueue,artemis.addresses.ConsumerCount 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=ExpiryQueue,queue=ExpiryQueue,artemis.addresses.MaxConsumers -1 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=ExpiryQueue,queue=ExpiryQueue,artemis.addresses.DeliveringCount 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=ExpiryQueue,queue=ExpiryQueue,artemis.addresses.MessageCount 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=ExpiryQueue,queue=ExpiryQueue,artemis.addresses.MessagesAcknowledged 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=ExpiryQueue,queue=ExpiryQueue,artemis.addresses.MessagesAdded 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=ExpiryQueue,queue=ExpiryQueue,artemis.addresses.MessagesExpired 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=ExpiryQueue,queue=ExpiryQueue,artemis.addresses.MessagesKilled 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=DLQ,queue=DLQ,artemis.addresses.ConsumerCount 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=DLQ,queue=DLQ,artemis.addresses.MaxConsumers -1 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=DLQ,queue=DLQ,artemis.addresses.DeliveringCount 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=DLQ,queue=DLQ,artemis.addresses.MessageCount 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=DLQ,queue=DLQ,artemis.addresses.MessagesAcknowledged 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=DLQ,queue=DLQ,artemis.addresses.MessagesAdded 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=DLQ,queue=DLQ,artemis.addresses.MessagesExpired 0 1528125286
service=amq7,host=localhost,broker=0_0_0_0,address=DLQ,queue=DLQ,artemis.addresses.MessagesKilled 0 1528125286

Sample jmxtrans-agent.xml File

The following shows a full sample file for the jmxtrans agent to be used with Red Hat AMQ 7:

<jmxtrans-agent>
  <queries>
    <!-- ActiveMQ Artemis -->
    <!-- Addresses -->
    <query objectName="org.apache.activemq.artemis:broker=*,component=addresses,address=*"
           attributes="MessageCount,NumberOfMessages,NumberOfPages,QueueNames"
           resultAlias="service=amq7,host=#hostname#,broker=%broker%,address=%address%,attribute.#attribute#"/>
 
    <!-- Queues -->
    <query objectName="org.apache.activemq.artemis:broker=*,component=addresses,address=*,subcomponent=queues,routing-type=*,queue=*"
           attributes="ConsumerCount,MaxConsumers,DeliveringCount,MessageCount,MessagesAcknowledged,MessagesAdded,MessagesExpired,MessagesKilled"
           resultAlias="service=amq7,host=#hostname#,broker=%broker%,address=%address%,queue=%queue%,artemis.addresses.#attribute#"/>
 
  </queries>

  <!-- Output Writers -->
  <outputWriter class="org.jmxtrans.agent.ConsoleOutputWriter" />
 
  <!-- Other Properties -->
  <collectIntervalInSeconds>5</collectIntervalInSeconds>
  <reloadConfigurationCheckIntervalInSeconds>60</reloadConfigurationCheckIntervalInSeconds>
</jmxtrans-agent>

References

More details about how to monitor Red Hat AMQ 7 using jmxtrans are available here:

Last updated: November 16, 2023