This topic describes how to deploy and configure a Kafka JMX agent.
Limit
You can deploy a Kafka JMX agent only in a Prometheus instance for Container Service or aPrometheus instance for ECS.
Step 1: Deploy a Kafka JMX agent
- Download the kafka JMX-Agent package to the pod or ECS instance where Kafka resides.
- Add
-javaagent:/{jmx-agent directory}/kafka-jmx_prometheus_javaagent-1.18.1.jar={jmx listening port}
to the Java Virtual Machine (JVM) startup parameters of Kafka Producer, Broker, and Consumer.- jmx-agent directory: Replace the value with the actual directory where the Kafka JMX agent is stored.
- jmx listening port: Replace the value with the actual JMX listening port.
- Restart Kafka Producer, Broker, and Consumer.
- Check whether the Kafka JMX agent is running as expected on Kafka Producer, Broker, and Consumer. Run the
curl localhost:{jmx listening port}/metrics
command on each pod or ECS instance to check whether normal metric data is returned. If normal metric data is returned, the Kafka JMX agent is running as expected on Kafka Producer, Broker, and Consumer.jmx listening port: Replace the value with the actual JMX listening port.
(Optional) Step 2: Configure containerPort
If you deploy a Kafka JMX agent in a Prometheus instance for Container Service, you also need to configure containerPort. This way, Managed Service for Prometheus can capture the data of the Kafka JMX agent. If you deploy a Kafka JMX agent in a Prometheus instance for ECS, skip this step.
- Log on to the ACK console.
- In the left-side navigation pane of the ACK console, click Clusters.
- On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.
- In the left-side navigation pane of the details page, choose Port section of the kafka tab, configure the port name, container port number, and protocol. . Then, click a workload name. In the
- Port name: the port name of the Kafka JMX agent. Example: app1-kafka-jmx.
- Container port number: the JMX listening port defined in Step 1: Deploy a Kafka JMX agent.
- Protocol: Select TCP.
Step 3: Attach tags to Kafka pods or ECS instances
Managed Service for Prometheus can use tags to identify pods or ECS instances to implement service discovery. Therefore, you need to attach tags to Kafka pods or ECS instances.Managed Service for Prometheus If you have attached tags to Kafka pods or ECS instances, you can skip this step.
Configure a tag for a Prometheus instance for Container Service
Configure a tag in the format of {custom tag key}:{ custom tag value}
for the pods of Kafka Producer, Broker, and Consumer. Example: arms-kafka-exporter:my-kafka1
. Perform the following steps to configure the tag:
- Log on to the ACK console.
- In the left-side navigation pane of the ACK console, click Clusters.
- On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.
- In the left-side navigation pane, choose Edit. In the dialog box that appears, add a tag and click Update. . On the Pods page, click the name of the workload. On the pod details page, click
Configure a tag for a Prometheus instance for ECS
Configure a tag in the format of {Custom tag key}:{ Custom tag value}
for the ECS instances of Kafka Producers, Brokers, and Consumers. Example: arms-kafka-exporter:my-kafka1
. For more information about how to create tags for ECS instances, see Create or add a tag.
What to do next
After the Kafka JMX agent is configured, you can configure the agent to view monitoring data in the Prometheus console. For more information, see Use Alibaba Cloud Managed Service for Prometheus to monitor self-managed Kafka clusters and Message Queue for Apache Kafka instances.