Apache ActiveMQ integration for Grafana Cloud
Apache ActiveMQ is an open-source message broker software that facilitates the communication between different applications or components using messaging patterns. Message brokers like ActiveMQ play a crucial role in distributed systems by enabling asynchronous communication and decoupling producers and consumers of messages. They serve as intermediaries that receive, store, and route messages between different components, applications, or services. The integration with Grafana Cloud enables users to oversee an ActiveMQ environment using five distinct dashboards. These dashboards display metrics and logs for ActiveMQ clusters, instances, topics, and queue components.
This integration supports Apache ActiveMQ version 5.x+
This integration supports the JMX exporter 0.17.0+
This integration includes 4 useful alerts and 5 pre-built dashboards to help monitor and visualize Apache ActiveMQ metrics and logs.
Before you begin
In order for the integration to properly work, you must set up the JMX Exporter for Prometheus on each instance in your cluster.
Setup JMX Exporter
To expose the JMX remotely, it needs to be enabled for the instances being monitored. A configuration option enables JMX, which exists in a env
file located in the <apache-activemq-installation-dir>/bin/env
directory. Within the env
file, the following lines should be added:
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.port=11099"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.authenticate=false"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.ssl=false"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote"
Change the jmxremote.port
on the first command above for each instance you run, then save the configuration files. For more details, refer to the official documentation.
Connect JMX to the Prometheus Exporter
In order to connect JMX to the Prometheus Exporter, a collector is configured in a config file. This config.yaml file can be placed anywhere and named anything. The contents of this file will be the following
lowercaseOutputLabelNames: true
lowercaseOutputName: true
rules:
- pattern: org.apache.activemq<type=Broker, brokerName=(\S*), destinationType=Queue, destinationName=(\S*)><>(\w+)
name: activemq_queue_$3
attrNameSnakeCase: true
labels:
destination: $2
- pattern: org.apache.activemq<type=Broker, brokerName=(\S*), destinationType=Topic, destinationName=(\S*)><>(\w+)
name: activemq_topic_$3
attrNameSnakeCase: true
labels:
destination: $2
- pattern: org.apache.activemq<type=Broker, brokerName=(\S*)><>CurrentConnectionsCount
name: activemq_connections
type: GAUGE
- pattern: org.apache.activemq<type=Broker, brokerName=(\S*)><>Total(.*)Count
name: activemq_$2_total
type: COUNTER
- pattern: org.apache.activemq<type=Broker, brokerName=(\S*)><>(.*)PercentUsage
name: activemq_$2_usage_ratio
type: GAUGE
valueFactor: 0.01
- pattern: 'java.lang<name=([^>]+), type=GarbageCollector><LastGcInfo>duration: (\d+)'
name: jvm_gc_duration_seconds
value: $2
labels:
name: $1
type: GAUGE
# Convert ms to s
valueFactor: 0.001
- pattern: 'java.lang<name=([^>]+), type=GarbageCollector><>CollectionCount: (\d+)'
name: jvm_gc_collection_count
value: $2
labels:
name: $1
type: GAUGE
Run the Prometheus Exporter
To run the JMX to Prometheus Exporter, the Java agent is used. The command requires two arguments: a <CONFIG>.yaml
file that was created above, and the <JMX_EXPORTER_PORT>
that exposes the metrics.
The following command runs the JMX to Prometheus Exporter as a Java agent:
java -javaagent:./jmx_prometheus_javaagent-0.19.0.jar=<JMX_EXPORTER_PORT>:/path/to/config/<CONFIG>.yaml -jar yourJar.jar
To validate that the JMX Exporter is setup correctly, the Prometheus metrics should be available locally via curl:
curl http://localhost:<JMX_EXPORTER_PORT>/metrics
Install Apache ActiveMQ integration for Grafana Cloud
- In your Grafana Cloud stack, click Connections in the left-hand menu.
- Find Apache ActiveMQ and click its tile to open the integration.
- Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send Apache ActiveMQ metrics and logs to your Grafana Cloud instance.
- Click Install to add this integration’s pre-built dashboards and alerts to your Grafana Cloud instance, and you can start monitoring your Apache ActiveMQ setup.
Configuration snippets for Grafana Alloy
Advanced mode
The following snippets provide examples to guide you through the configuration process.
To instruct Grafana Alloy to scrape your Apache ActiveMQ instances, manually copy and append the snippets to your alloy configuration file, then follow subsequent instructions.
Advanced metrics snippets
prometheus.scrape "metrics_integrations_integrations_apache_activemq" {
targets = [{
__address__ = "<instance-name>:<instance-port>",
activemq_cluster = "<activemq-cluster-name>",
}]
forward_to = [prometheus.remote_write.metrics_service.receiver]
job_name = "integrations/apache-activemq"
}
To monitor your Apache ActiveMQ instance, you must use a discovery.relabel component to discover your Apache ActiveMQ Prometheus endpoint and apply appropriate labels, followed by a prometheus.scrape component to scrape it.
Configure the following properties within each discovery.relabel
component:
__address__
: The address to your Apache ActiveMQ Prometheus metrics endpoint.instance
label:constants.hostname
sets theinstance
label to your Grafana Alloy server hostname. If that is not suitable, change it to a value uniquely identifies this Apache ActiveMQ instance. Make sure this label value is the same for all telemetry data collected for this instance.activemq_cluster
: Theactivemq_cluster
label to group your ActiveMQ instances within a cluster. Set the same value for all nodes within your cluster.
If you have multiple Apache ActiveMQ servers to scrape, configure one discovery.relabel
for each and scrape them by including each under targets
within the prometheus.scrape
component.
Advanced logs snippets
darwin
local.file_match "logs_integrations_integrations_apache_activemq" {
path_targets = [{
__address__ = "localhost",
__path__ = "<activemq_install_dir>/data/activemq.log",
activemq_cluster = "<activemq-cluster-name>",
instance = "<instance-name>:<instance-port>",
job = "integrations/apache-activemq",
}]
}
loki.process "logs_integrations_integrations_apache_activemq" {
forward_to = [loki.write.grafana_cloud_loki.receiver]
stage.multiline {
firstline = "(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)"
max_lines = 0
max_wait_time = "3s"
}
stage.regex {
expression = "(?P<level>TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\\s*[\\|:]\\s*(?P<message>.+)"
}
stage.labels {
values = {
level = null,
}
}
}
loki.source.file "logs_integrations_integrations_apache_activemq" {
targets = local.file_match.logs_integrations_integrations_apache_activemq.targets
forward_to = [loki.process.logs_integrations_integrations_apache_activemq.receiver]
}
To monitor your Apache ActiveMQ instance logs, you will use a combination of the following components:
local.file_match defines where to find the log file to be scraped. Change the following properties according to your environment:
__address__
: The Apache ActiveMQ instance address__path__
: The path to the log file, which is typically in thedata
file within the Apache ActiveMQ installation directory. An example log location looks like/apache-activemq-5.18.2/data/activemq.log
on Unix based systems and likeC:\apache-activemq-x.x.x\data\activemq.log
on Windows.instance
label:constants.hostname
sets theinstance
label to your Grafana Alloy server hostname. If that is not suitable, change it to a value uniquely identifies this Apache ActiveMQ instance. Make sure this label value is the same for all telemetry data collected for this instance.activemq_cluster
: Theactivemq_cluster
label to group your ActiveMQ instances within a cluster. Set the same value for all nodes within your cluster.
loki.process defines how to process logs before sending it to Loki.
loki.source.file sends logs to Loki.
linux
local.file_match "logs_integrations_integrations_apache_activemq" {
path_targets = [{
__address__ = "localhost",
__path__ = "<activemq_install_dir>/data/activemq.log",
activemq_cluster = "<activemq-cluster-name>",
instance = "<instance-name>:<instance-port>",
job = "integrations/apache-activemq",
}]
}
loki.process "logs_integrations_integrations_apache_activemq" {
forward_to = [loki.write.grafana_cloud_loki.receiver]
stage.multiline {
firstline = "(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)"
max_lines = 0
max_wait_time = "3s"
}
stage.regex {
expression = "(?P<level>TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\\s*[\\|:]\\s*(?P<message>.+)"
}
stage.labels {
values = {
level = null,
}
}
}
loki.source.file "logs_integrations_integrations_apache_activemq" {
targets = local.file_match.logs_integrations_integrations_apache_activemq.targets
forward_to = [loki.process.logs_integrations_integrations_apache_activemq.receiver]
}
To monitor your Apache ActiveMQ instance logs, you will use a combination of the following components:
local.file_match defines where to find the log file to be scraped. Change the following properties according to your environment:
__address__
: The Apache ActiveMQ instance address__path__
: The path to the log file, which is typically in thedata
file within the Apache ActiveMQ installation directory. An example log location looks like/apache-activemq-5.18.2/data/activemq.log
on Unix based systems and likeC:\apache-activemq-x.x.x\data\activemq.log
on Windows.instance
label:constants.hostname
sets theinstance
label to your Grafana Alloy server hostname. If that is not suitable, change it to a value uniquely identifies this Apache ActiveMQ instance. Make sure this label value is the same for all telemetry data collected for this instance.activemq_cluster
: Theactivemq_cluster
label to group your ActiveMQ instances within a cluster. Set the same value for all nodes within your cluster.
loki.process defines how to process logs before sending it to Loki.
loki.source.file sends logs to Loki.
windows
local.file_match "logs_integrations_integrations_apache_activemq" {
path_targets = [{
__address__ = "localhost",
__path__ = "<activemq_install_dir>/data/activemq.log",
activemq_cluster = "<activemq-cluster-name>",
instance = "<instance-name>:<instance-port>",
job = "integrations/apache-activemq",
}]
}
loki.process "logs_integrations_integrations_apache_activemq" {
forward_to = [loki.write.grafana_cloud_loki.receiver]
stage.multiline {
firstline = "(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)"
max_lines = 0
max_wait_time = "3s"
}
stage.regex {
expression = "(?P<level>TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\\s*[\\|:]\\s*(?P<message>.+)"
}
stage.labels {
values = {
level = null,
}
}
}
loki.source.file "logs_integrations_integrations_apache_activemq" {
targets = local.file_match.logs_integrations_integrations_apache_activemq.targets
forward_to = [loki.process.logs_integrations_integrations_apache_activemq.receiver]
}
To monitor your Apache ActiveMQ instance logs, you will use a combination of the following components:
local.file_match defines where to find the log file to be scraped. Change the following properties according to your environment:
__address__
: The Apache ActiveMQ instance address__path__
: The path to the log file, which is typically in thedata
file within the Apache ActiveMQ installation directory. An example log location looks like/apache-activemq-5.18.2/data/activemq.log
on Unix based systems and likeC:\apache-activemq-x.x.x\data\activemq.log
on Windows.instance
label:constants.hostname
sets theinstance
label to your Grafana Alloy server hostname. If that is not suitable, change it to a value uniquely identifies this Apache ActiveMQ instance. Make sure this label value is the same for all telemetry data collected for this instance.activemq_cluster
: Theactivemq_cluster
label to group your ActiveMQ instances within a cluster. Set the same value for all nodes within your cluster.
loki.process defines how to process logs before sending it to Loki.
loki.source.file sends logs to Loki.
Grafana Agent static configuration (deprecated)
The following section shows configuration for running Grafana Agent in static mode which is deprecated. You should use Grafana Alloy for all new deployments.
Before you begin
In order for the integration to properly work, you must set up the JMX Exporter for Prometheus on each instance in your cluster.
Setup JMX Exporter
To expose the JMX remotely, it needs to be enabled for the instances being monitored. A configuration option enables JMX, which exists in a env
file located in the <apache-activemq-installation-dir>/bin/env
directory. Within the env
file, the following lines should be added:
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.port=11099"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.authenticate=false"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.ssl=false"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote"
Change the jmxremote.port
on the first command above for each instance you run, then save the configuration files. For more details, refer to the official documentation.
Connect JMX to the Prometheus Exporter
In order to connect JMX to the Prometheus Exporter, a collector is configured in a config file. This config.yaml file can be placed anywhere and named anything. The contents of this file will be the following
lowercaseOutputLabelNames: true
lowercaseOutputName: true
rules:
- pattern: org.apache.activemq<type=Broker, brokerName=(\S*), destinationType=Queue, destinationName=(\S*)><>(\w+)
name: activemq_queue_$3
attrNameSnakeCase: true
labels:
destination: $2
- pattern: org.apache.activemq<type=Broker, brokerName=(\S*), destinationType=Topic, destinationName=(\S*)><>(\w+)
name: activemq_topic_$3
attrNameSnakeCase: true
labels:
destination: $2
- pattern: org.apache.activemq<type=Broker, brokerName=(\S*)><>CurrentConnectionsCount
name: activemq_connections
type: GAUGE
- pattern: org.apache.activemq<type=Broker, brokerName=(\S*)><>Total(.*)Count
name: activemq_$2_total
type: COUNTER
- pattern: org.apache.activemq<type=Broker, brokerName=(\S*)><>(.*)PercentUsage
name: activemq_$2_usage_ratio
type: GAUGE
valueFactor: 0.01
- pattern: 'java.lang<name=([^>]+), type=GarbageCollector><LastGcInfo>duration: (\d+)'
name: jvm_gc_duration_seconds
value: $2
labels:
name: $1
type: GAUGE
# Convert ms to s
valueFactor: 0.001
- pattern: 'java.lang<name=([^>]+), type=GarbageCollector><>CollectionCount: (\d+)'
name: jvm_gc_collection_count
value: $2
labels:
name: $1
type: GAUGE
Run the Prometheus Exporter
To run the JMX to Prometheus Exporter, the Java agent is used. The command requires two arguments: a <CONFIG>.yaml
file that was created above, and the <JMX_EXPORTER_PORT>
that exposes the metrics.
The following command runs the JMX to Prometheus Exporter as a Java agent:
java -javaagent:./jmx_prometheus_javaagent-0.19.0.jar=<JMX_EXPORTER_PORT>:/path/to/config/<CONFIG>.yaml -jar yourJar.jar
To validate that the JMX Exporter is setup correctly, the Prometheus metrics should be available locally via curl:
curl http://localhost:<JMX_EXPORTER_PORT>/metrics
Install Apache ActiveMQ integration for Grafana Cloud
- In your Grafana Cloud stack, click Connections in the left-hand menu.
- Find Apache ActiveMQ and click its tile to open the integration.
- Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send Apache ActiveMQ metrics and logs to your Grafana Cloud instance.
- Click Install to add this integration’s pre-built dashboards and alerts to your Grafana Cloud instance, and you can start monitoring your Apache ActiveMQ setup.
Post-install configuration for the Apache ActiveMQ integration
After enabling the metrics generation, instruct the Grafana Agent to scrape the ActiveMQ’s metrics that have been created by the JMX exporter. The Grafana Agent config is stored in /etc/grafana-agent.yaml
.
Enable the integration by adding the suggested snippets to your agent configuration file.
If you want to show logs and metrics signals correlated in your dashboards as a single pane of glass, ensure the following:
job
andinstance
label values must match for the Apache ActiveMQ integration and logs scrape config in your agent configuration file.job
must be set tointegrations/active-activemq
(already configured in the snippets).instance
must be set to a value that uniquely identifies your ActiveMQ instance.activemq_cluster
must be the value that identifies the ActiveMQ cluster this instance belongs to.__path__
is the log location, which is typically in thedata
file within the Apache ActiveMQ installation directory. An example log location looks like/apache-activemq-5.18.2/data/activemq.log
on Unix based systems and likeC:\apache-activemq-x.x.x\data\activemq.log
on Windows.
Make sure to change targets
in the snippet according to your host name and JMX_EXPORTER_PORT
.
Configuration snippets for Grafana Agent
Below metrics.configs.scrape_configs
, insert the following lines and change the URLs according to your environment:
- job_name: integrations/apache-activemq
metrics_path: /metrics
static_configs:
- targets: ["<instance-name>:<instance-port>"]
labels:
activemq_cluster: '<activemq-cluster-name>'
Below logs.configs.scrape_configs
, insert the following lines according to your environment.
- job_name: integrations/apache-activemq
static_configs:
- targets: [localhost]
labels:
job: integrations/apache-activemq
activemq_cluster: '<activemq-cluster-name>'
instance: '<instance-name>:<instance-port>'
__path__: <activemq_install_dir>/data/activemq.log
pipeline_stages:
- multiline:
firstline: '(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)'
- regex:
expression: '(?P<level>TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\s*[\|:]\s*(?P<message>.+)'
- labels:
level:
Full example configuration for Grafana Agent
Refer to the following Grafana Agent configuration for a complete example that contains all the snippets used for the Apache ActiveMQ integration. This example also includes metrics that are sent to monitor your Grafana Agent instance.
integrations:
prometheus_remote_write:
- basic_auth:
password: <your_prom_pass>
username: <your_prom_user>
url: <your_prom_url>
agent:
enabled: true
relabel_configs:
- action: replace
source_labels:
- agent_hostname
target_label: instance
- action: replace
target_label: job
replacement: "integrations/agent-check"
metric_relabel_configs:
- action: keep
regex: (prometheus_target_sync_length_seconds_sum|prometheus_target_scrapes_.*|prometheus_target_interval.*|prometheus_sd_discovered_targets|agent_build.*|agent_wal_samples_appended_total|process_start_time_seconds)
source_labels:
- __name__
# Add here any snippet that belongs to the `integrations` section.
# For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
logs:
configs:
- clients:
- basic_auth:
password: <your_loki_pass>
username: <your_loki_user>
url: <your_loki_url>
name: integrations
positions:
filename: /tmp/positions.yaml
scrape_configs:
# Add here any snippet that belongs to the `logs.configs.scrape_configs` section.
# For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
- job_name: integrations/apache-activemq
static_configs:
- targets: [localhost]
labels:
job: integrations/apache-activemq
activemq_cluster: '<activemq-cluster-name>'
instance: '<instance-name>:<instance-port>'
__path__: <activemq_install_dir>/data/activemq.log
pipeline_stages:
- multiline:
firstline: '(TRACE|DEBUG|INFO|WARN|ERROR|FATAL)'
- regex:
expression: '(?P<level>TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\s*[\|:]\s*(?P<message>.+)'
- labels:
level:
metrics:
configs:
- name: integrations
remote_write:
- basic_auth:
password: <your_prom_pass>
username: <your_prom_user>
url: <your_prom_url>
scrape_configs:
# Add here any snippet that belongs to the `metrics.configs.scrape_configs` section.
# For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
- job_name: integrations/apache-activemq
metrics_path: /metrics
static_configs:
- targets: ["<instance-name>:<instance-port>"]
labels:
activemq_cluster: '<activemq-cluster-name>'
global:
scrape_interval: 60s
wal_directory: /tmp/grafana-agent-wal
Dashboards
The Apache ActiveMQ integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.
- Apache ActiveMQ cluster overview
- Apache ActiveMQ instance overview
- Apache ActiveMQ logs
- Apache ActiveMQ queue overview
- Apache ActiveMQ topic overview
Apache ActiveMQ cluster overview
Apache ActiveMQ instance overview
Apache ActiveMQ instance overview (jvm)
Alerts
The Apache ActiveMQ integration includes the following useful alerts:
Alert | Description |
---|---|
ApacheActiveMQHighTopicMemoryUsage | Warning: Topic destination memory usage is high, which may result in a reduction of the rate at which producers send messages. |
ApacheActiveMQHighQueueMemoryUsage | Warning: Queue destination memory usage is high, which may result in a reduction of the rate at which producers send messages. |
ApacheActiveMQHighStoreMemoryUsage | Warning: Store memory usage is high, which may result in producers unable to send messages. |
ApacheActiveMQHighTemporaryMemoryUsage | Warning: Temporary memory usage is high, which may result in saturation of messaging throughput. |
Metrics
The most important metrics provided by the Apache ActiveMQ integration, which are used on the pre-built dashboards and Prometheus alerts, are as follows:
- activemq_memory_usage_ratio
- activemq_message_total
- activemq_queue_average_enqueue_time
- activemq_queue_average_message_size
- activemq_queue_consumer_count
- activemq_queue_dequeue_count
- activemq_queue_enqueue_count
- activemq_queue_expired_count
- activemq_queue_memory_percent_usage
- activemq_queue_producer_count
- activemq_queue_queue_size
- activemq_store_usage_ratio
- activemq_temp_usage_ratio
- activemq_topic_average_enqueue_time
- activemq_topic_average_message_size
- activemq_topic_consumer_count
- activemq_topic_dequeue_count
- activemq_topic_enqueue_count
- activemq_topic_expired_count
- activemq_topic_memory_percent_usage
- activemq_topic_producer_count
- activemq_topic_queue_size
- jvm_gc_collection_count
- jvm_gc_duration_seconds
- up
Changelog
# 1.0.1 - November 2024
- Update status panel check queries
# 1.0.0 - October 2023
- Initial release
Cost
By connecting your Apache ActiveMQ instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see Active series and dpm usage and Cloud tier pricing.