第 21 章 Monitoring your cluster using JMX
Collecting metrics is critical for understanding the health and performance of your Kafka deployment. By monitoring metrics, you can actively identify issues before they become critical and make informed decisions about resource allocation and capacity planning. Without metrics, you may be left with limited visibility into the behavior of your Kafka deployment, which can make troubleshooting more difficult and time-consuming. Setting up metrics can save you time and resources in the long run, and help ensure the reliability of your Kafka deployment.
Kafka components use Java Management Extensions (JMX) to share management information through metrics. These metrics are crucial for monitoring a Kafka cluster’s performance and overall health. Like many other Java applications, Kafka employs Managed Beans (MBeans) to supply metric data to monitoring tools and dashboards. JMX operates at the JVM level, allowing external tools to connect and retrieve management information from Kafka components. To connect to the JVM, these tools typically need to run on the same machine and with the same user privileges by default.
21.1. Enabling the JMX agent 复制链接链接已复制到粘贴板!
Enable JMX monitoring of Kafka components using JVM system properties. Use the KAFKA_JMX_OPTS environment variable to set the JMX system properties required for enabling JMX monitoring. The scripts that run the Kafka component use these properties.
Procedure
Set the
KAFKA_JMX_OPTSenvironment variable with the JMX properties for enabling JMX monitoring.export KAFKA_JMX_OPTS=-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=<port> -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=falseReplace <port> with the name of the port on which you want the Kafka component to listen for JMX connections.
Add
org.apache.kafka.common.metrics.JmxReportertometric.reportersin theserver.propertiesfile.metric.reporters=org.apache.kafka.common.metrics.JmxReporter-
Start the Kafka component using the appropriate script, such as
bin/kafka-server-start.shfor a broker orbin/connect-distributed.shfor Kafka Connect.
It is recommended that you configure authentication and SSL to secure a remote JMX connection. For more information about the system properties needed to do this, see the Oracle documentation.