Site icon Voina Blog (a tech warrior's blog)

Monitor and control #ActiveMq using Jolokia #API

Advertisements

Apache ActiveMQ® is the most popular open source, multi-protocol, Java-based message broker. It is widely used in a lot of multi service application environments where we need to pass messages between services.

All this type of environments (kubernets, docker swarm etc. ) are used to be able to monitor and control the component services using APIs.

Lucky for us ActiveMQ comes bundled with Jolokia which provides a RESTful interface to ActiveMQ’s JMX capabilities.

Once you discover how to make calls to this API ACtiveMQ becomes much more powerful and easier to integrate in environments where monitoring and control using API calls are essential.

The Jolokia API is basically executing operations or interrogating parameters on ActiveMQ MBean objects. ActiveMQ exposes the following MBeans with some attributes and operations that can be executed on them. A very confusing table is available in the official documentation. Click the image for the original source manual page.

So how do we make a call to the API to get the value of an attribute or to execute an operation on a Mbean.

First of all we use as example curl which is easy to integrate in bash scripts but this calls should work from any Internet browser or from any other type of http client implemented in Java or Go or any other language.

Structure of a Jolokia API call:

$baseURL/$callType/org.apache.activemq:$MBeanTypePropertiesOrObjectName/$AttributeOrOperation

Where:

So now looking at the above let us give two practical examples.

EXAMPLE 1: Return the size of the DLQ. The Jolokia API call will look like:

http://localhost:8161/api/jolokia/read/type=Broker,brokerName=localhost,destinationType=Queue,destinationName=ActiveMQ.DLQ/QueueSize

EXAMPLE 2: Purge the DLQ to empty it. The Jolokia API call will look like:

http://localhost:8161/api/jolokia/exec/type=Broker,brokerName=localhost,destinationType=Queue,destinationName=ActiveMQ.DLQ/purge

EXAMPLE 3: Return the current health status of ActiveMQ. The Jolokia API call will look like:

http://localhost:8161/api/jolokia/read/type=Broker,brokerName=localhost,Service=Health/CurrentStatus

So now if we want to call this from command line using curl for EXAMPLE 1 the call becomes:

curl -XGET --user admin:admin --header "Origin: http://localhost" http://localhost:8161/api/jolokia/read/type=Broker,brokerName=localhost,destinationType=Queue,destinationName=ActiveMQ.DLQ/QueueSize

Note that we need to specify the user/password pair and also the Origin header to have access to the API call.

The above curl call can be easy integrated in any monitoring and control tool of our environment to read attributes and perform some operations if needed.

Exit mobile version