{"id":2257,"date":"2022-04-22T09:09:17","date_gmt":"2022-04-22T09:09:17","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=2257"},"modified":"2022-04-22T09:12:29","modified_gmt":"2022-04-22T09:12:29","slug":"jmx-monitoring-and-managing-kafka","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2022\/04\/22\/jmx-monitoring-and-managing-kafka\/","title":{"rendered":"JMX: Monitoring and Managing Kafka"},"content":{"rendered":"\n<div class=\"wp-block-snow-monkey-blocks-balloon smb-balloon wp-block-snow-monkey-blocks-balloon-is-layout-constrained\"><div class=\"smb-balloon__person\"><div class=\"smb-balloon__figure\"><img fetchpriority=\"high\" decoding=\"async\" width=\"2118\" height=\"2560\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/01\/D398E4B3-D57D-403A-8B41-5665E5A21FC1-scaled.jpeg\" alt=\"\" class=\"wp-image-1928\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/01\/D398E4B3-D57D-403A-8B41-5665E5A21FC1-scaled.jpeg 2118w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/01\/D398E4B3-D57D-403A-8B41-5665E5A21FC1-248x300.jpeg 248w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/01\/D398E4B3-D57D-403A-8B41-5665E5A21FC1-248x300@2x.jpeg 496w\" sizes=\"(max-width: 2118px) 100vw, 2118px\" \/><\/div><div class=\"smb-balloon__name\">Oracle<\/div><\/div><div class=\"smb-balloon__body is-layout-constrained wp-block-balloon-is-layout-constrained\"><p>The Java virtual machine (Java VM) has built-in instrumentation that enables you to monitor and manage it using the Java Management Extensions (JMX) technology.&nbsp;<\/p><\/div><\/div>\n\n\n\n<p>To enable and configure monitoring of Java VM for any java-application using the ready-to-use JMX agent, you must set certain system properties when you start the Java VM.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-Doptions1=value1<\/code><\/pre>\n\n\n\n<p>The default location for the configuration file is&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>jre_home\/lib\/management\/management.properties<\/code><\/pre>\n\n\n\n<p>Or you can set using <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-Dcom.sun.management.config.file=&lt;location&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example: On my OSX<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/local\/Cellar\/openjdk@11\/11.0.14.1\/libexec\/openjdk.jdk\/Contents\/Home\/conf\/management<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-pullquote\" style=\"border-radius:3px;font-style:normal;font-weight:600\"><blockquote><p>You can set ready-to-use monitoring and management properties in a configuration file or on the command line. Properties are defined <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/11\/management\/monitoring-and-management-using-jmx-technology.html#GUID-2C1922AD-4BA0-4397-A3FE-7823F42A94A3\" target=\"_blank\">here<\/a>.<\/p><cite>Oracle Documentation<\/cite><\/blockquote><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Monitoring: Kafka<\/h2>\n\n\n\n<p>Now let&#8217;s configure JMX monitoring specifically for monitoring Kafka Broker. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configuration Assumptions<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Kafka SSL configuration is enabled (keystore and truststore)<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Configured as a Service<\/h3>\n\n\n\n<p>If your kafka broker is configured as service you need two basic things as environment<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-background-color has-background\"><code>Environment=\"JMX_PORT=10167\"\nEnvironment=\"KAFKA_JMX_OPTS=-Dcom.sun.management.config.file=\/opt\/kafka\/config\/jmx.kafka\"<\/code><\/pre>\n\n\n\n<p>You might recognize the <code>com.sun.management.config.file<\/code>. This is the same parameter that defines the options for the JMX configuration file location.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><code>jmx.kafka<\/code><\/h4>\n\n\n\n<p>In this file the contents identify the specific settings enabled for the JMX monitoring (explained below)<\/p>\n\n\n\n<pre class=\"wp-block-code has-light-green-cyan-background-color has-background\"><code>com.sun.management.jmxremote=true\ncom.sun.management.jmxremote.port=10167\ncom.sun.management.jmxremote.rmi.port=10168\njava.rmi.server.hostname=broker1.test\ncom.sun.management.jmxremote.password.toHashes=true\njava.net.preferIPv4Stack=true\ncom.sun.management.jmxremote.ssl.config.file=\/opt\/kafka\/config\/jmxremote.ssl\ncom.sun.management.jmxremote.ssl=true\ncom.sun.management.jmxremote.registry.ssl=true\ncom.sun.management.jmxremote.authenticate=true\ncom.sun.management.jmxremote.ssl.need.client.auth=true\ncom.sun.management.jmxremote.password.file=\/opt\/kafka\/config\/jmxremote.password\ncom.sun.management.jmxremote.access.file=\/opt\/kafka\/config\/jmxremote.access<\/code><\/pre>\n\n\n\n<p>Let&#8217;s look in some detail<\/p>\n\n\n\n<div class=\"wp-block-group has-pale-pink-background-color has-background\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<div class=\"wp-block-columns are-vertically-aligned-center is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<div class=\"wp-block-snow-monkey-blocks-information smb-information is-style-border\" data-sm-split-column=\"true\" data-label-align=\"left\" data-label-vertical-align=\"middle\"><div class=\"smb-information__body\">\n<div class=\"wp-block-snow-monkey-blocks-information-item smb-information__item\"><div class=\"c-row\"><div class=\"c-row__col c-row__col--1-3\"><div class=\"smb-information__item__label\">com.sun.management.jmxremote<\/div><\/div><div class=\"c-row__col c-row__col--2-3\"><div class=\"smb-information__item__body is-layout-constrained wp-block-snow-monkey-blocks-information-item-is-layout-constrained\">\n<p class=\"has-small-font-size\">In the current Java SE platform, it is no longer necessary to set this system property.<\/p>\n<\/div><\/div><\/div><\/div>\n\n\n\n<div class=\"wp-block-snow-monkey-blocks-information-item smb-information__item\"><div class=\"c-row\"><div class=\"c-row__col c-row__col--1-3\"><div class=\"smb-information__item__label\">com.sun.management.jmxremote.port<\/div><\/div><div class=\"c-row__col c-row__col--2-3\"><div class=\"smb-information__item__body is-layout-constrained wp-block-snow-monkey-blocks-information-item-is-layout-constrained\">\n<ul class=\"has-small-font-size wp-block-list\"><li>To enable monitoring and management from remote systems define the <code>jmremote.port<\/code><\/li><li>Remote monitoring and management requires security to ensure that unauthorized persons cannot control or monitor your application. Password authentication over the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) is enabled by default. <\/li><\/ul>\n<\/div><\/div><\/div><\/div>\n\n\n\n<div class=\"wp-block-snow-monkey-blocks-information-item smb-information__item\"><div class=\"c-row\"><div class=\"c-row__col c-row__col--1-3\"><div class=\"smb-information__item__label\">com.sun.management.jmxremote.rmi.port<\/div><\/div><div class=\"c-row__col c-row__col--2-3\"><div class=\"smb-information__item__body is-layout-constrained wp-block-snow-monkey-blocks-information-item-is-layout-constrained\">\n<ul class=\"has-small-font-size wp-block-list\"><li>Port number to enable JMX RMI connection.<\/li><li>In addition to publishing an RMI connector for local access, setting this property publishes an additional RMI connector in a private read-only registry at the specified port using the name,&nbsp;<code>jmxrmi<\/code>.&nbsp;<\/li><\/ul>\n<\/div><\/div><\/div><\/div>\n\n\n\n<div class=\"wp-block-snow-monkey-blocks-information-item smb-information__item\"><div class=\"c-row\"><div class=\"c-row__col c-row__col--1-3\"><div class=\"smb-information__item__label\">java.rmi.server.hostname<\/div><\/div><div class=\"c-row__col c-row__col--2-3\"><div class=\"smb-information__item__body is-layout-constrained wp-block-snow-monkey-blocks-information-item-is-layout-constrained\">\n<ul class=\"has-small-font-size wp-block-list\"><li>For remote stubs to be associated with a specific interface address, the&nbsp;<code>java.rmi.server.hostname<\/code>&nbsp;system property must be set.<\/li><li>Our example uses a vagrant host <code>broker1.test<\/code><\/li><\/ul>\n<\/div><\/div><\/div><\/div>\n\n\n\n<div class=\"wp-block-snow-monkey-blocks-information-item smb-information__item\"><div class=\"c-row\"><div class=\"c-row__col c-row__col--1-3\"><div class=\"smb-information__item__label\">com.sun.management.jmxremote.password.toHashes<\/div><\/div><div class=\"c-row__col c-row__col--2-3\"><div class=\"smb-information__item__body is-layout-constrained wp-block-snow-monkey-blocks-information-item-is-layout-constrained\">\n<p class=\"has-small-font-size\">If passwords are in clear, they will be overwritten by their hash <\/p>\n<\/div><\/div><\/div><\/div>\n\n\n\n<div class=\"wp-block-snow-monkey-blocks-information-item smb-information__item\"><div class=\"c-row\"><div class=\"c-row__col c-row__col--1-3\"><div class=\"smb-information__item__label\">com.sun.management.jmxremote.ssl.config.file<\/div><\/div><div class=\"c-row__col c-row__col--2-3\"><div class=\"smb-information__item__body is-layout-constrained wp-block-snow-monkey-blocks-information-item-is-layout-constrained\">\n<p class=\"has-small-font-size\">Specifies the location of the SSL configuration file.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Contents<\/h4>\n\n\n\n<pre class=\"wp-block-code has-light-green-cyan-background-color has-background\"><code>javax.net.ssl.keyStore=\/opt\/kafka\/ssl\/kafka.broker.keystore.jks\njavax.net.ssl.keyStorePassword=changeit\njavax.net.ssl.trustStore=\/opt\/kafka\/ssl\/kafka.broker.truststore.jks\njavax.net.ssl.trustStorePassword=changeit<\/code><\/pre>\n<\/div><\/div><\/div><\/div>\n\n\n\n<div class=\"wp-block-snow-monkey-blocks-information-item smb-information__item\"><div class=\"c-row\"><div class=\"c-row__col c-row__col--1-3\"><div class=\"smb-information__item__label\">com.sun.management.jmxremote.ssl<\/div><\/div><div class=\"c-row__col c-row__col--2-3\"><div class=\"smb-information__item__body is-layout-constrained wp-block-snow-monkey-blocks-information-item-is-layout-constrained\">\n<ul class=\"has-small-font-size wp-block-list\"><li>Default value is <code>true<\/code><\/li><li>Enables secure monitoring using SSL.<\/li><\/ul>\n<\/div><\/div><\/div><\/div>\n\n\n\n<div class=\"wp-block-snow-monkey-blocks-information-item smb-information__item\"><div class=\"c-row\"><div class=\"c-row__col c-row__col--1-3\"><div class=\"smb-information__item__label\">com.sun.management.jmxremote.registry.ssl<\/div><\/div><div class=\"c-row__col c-row__col--2-3\"><div class=\"smb-information__item__body is-layout-constrained wp-block-snow-monkey-blocks-information-item-is-layout-constrained\">\n<ul class=\"has-small-font-size wp-block-list\"><li>Binds the RMI connector stub to an RMI registry that is protected by SSL.<\/li><\/ul>\n<\/div><\/div><\/div><\/div>\n\n\n\n<div class=\"wp-block-snow-monkey-blocks-information-item smb-information__item\"><div class=\"c-row\"><div class=\"c-row__col c-row__col--1-3\"><div class=\"smb-information__item__label\">com.sun.management.jmxremote.authenticate<\/div><\/div><div class=\"c-row__col c-row__col--2-3\"><div class=\"smb-information__item__body is-layout-constrained wp-block-snow-monkey-blocks-information-item-is-layout-constrained\">\n<ul class=\"has-small-font-size wp-block-list\"><li>Enables or disables password authentication for JMX.<\/li><\/ul>\n<\/div><\/div><\/div><\/div>\n\n\n\n<div class=\"wp-block-snow-monkey-blocks-information-item smb-information__item\"><div class=\"c-row\"><div class=\"c-row__col c-row__col--1-3\"><div class=\"smb-information__item__label\">com.sun.management.jmxremote.ssl.need.client.auth<\/div><\/div><div class=\"c-row__col c-row__col--2-3\"><div class=\"smb-information__item__body is-layout-constrained wp-block-snow-monkey-blocks-information-item-is-layout-constrained\">\n<ul class=\"has-small-font-size wp-block-list\"><li>Performs client authentication if this property is&nbsp;<code>true<\/code>&nbsp;and the property&nbsp;<code>com.sun.management.jmxremote.ssl<\/code>&nbsp;is also&nbsp;<code>true<\/code>.<\/li><\/ul>\n<\/div><\/div><\/div><\/div>\n\n\n\n<div class=\"wp-block-snow-monkey-blocks-information-item smb-information__item\"><div class=\"c-row\"><div class=\"c-row__col c-row__col--1-3\"><div class=\"smb-information__item__label\">com.sun.management.jmxremote.password.file<\/div><\/div><div class=\"c-row__col c-row__col--2-3\"><div class=\"smb-information__item__body is-layout-constrained wp-block-snow-monkey-blocks-information-item-is-layout-constrained\">\n<ul class=\"has-small-font-size wp-block-list\"><li>Specifies the location for the password file.<\/li><li>If&nbsp;<code>com.sun.management.jmxremote.authenticate<\/code>&nbsp;is&nbsp;<code>false<\/code>, then this property, and the password and access files are ignored. Otherwise, the password file must exist and be in the valid format. <\/li><li>If the password file is empty or nonexistent, then no access is allowed.<\/li><\/ul>\n<\/div><\/div><\/div><\/div>\n\n\n\n<div class=\"wp-block-snow-monkey-blocks-information-item smb-information__item\"><div class=\"c-row\"><div class=\"c-row__col c-row__col--1-3\"><div class=\"smb-information__item__label\">com.sun.management.jmxremote.access.file<\/div><\/div><div class=\"c-row__col c-row__col--2-3\"><div class=\"smb-information__item__body is-layout-constrained wp-block-snow-monkey-blocks-information-item-is-layout-constrained\">\n<ul class=\"has-small-font-size wp-block-list\"><li>Specifies the location for the access file. If&nbsp;<code>com.sun.management.jmxremote.authenticate<\/code>&nbsp;is <code>false<\/code>, then this property, and the password and access files, are ignored. Otherwise, the access file must exist and be in the valid format. <\/li><li>If the access file is empty or nonexistent, then no access is allowed.<\/li><\/ul>\n<\/div><\/div><\/div><\/div>\n<\/div><\/div>\n<\/div>\n<\/div>\n<\/div><\/div>\n\n\n\n<p>Once all the configuration is supplied and the service is running you can run JConsole and try and connect to the JMX port. <\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-pink-background-color has-background has-small-font-size\"><code><strong>jconsole<\/strong> -debug -J-Djavax.net.ssl.trustStore=kafka.broker.truststore.jks -J-Djavax.net.ssl.trustStorePassword=changeit -J-Djavax.net.ssl.keyStore=kafka.broker.keystore.jks -J-Djavax.net.ssl.keyStorePassword=changeit<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-medium\"><img decoding=\"async\" width=\"300\" height=\"300\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/04\/Screenshot-2022-04-19-at-3.04.19-PM-300x300.png\" alt=\"\" class=\"wp-image-2261\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/04\/Screenshot-2022-04-19-at-3.04.19-PM-150x150@2x.png 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/04\/Screenshot-2022-04-19-at-3.04.19-PM-150x150.png 150w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/04\/Screenshot-2022-04-19-at-3.04.19-PM.png 850w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/04\/Screenshot-2022-04-19-at-3.04.19-PM-300x300@2x.png 600w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><figcaption>JConsole to connect and view<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"787\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/04\/Screenshot-2022-04-19-at-3.04.41-PM-1024x787.png\" alt=\"\" class=\"wp-image-2262\" srcset=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/04\/Screenshot-2022-04-19-at-3.04.41-PM-1024x787.png 1024w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/04\/Screenshot-2022-04-19-at-3.04.41-PM-300x231.png 300w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/04\/Screenshot-2022-04-19-at-3.04.41-PM-1536x1181.png 1536w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/04\/Screenshot-2022-04-19-at-3.04.41-PM.png 1740w, https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/04\/Screenshot-2022-04-19-at-3.04.41-PM-300x231@2x.png 600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Oracle The Java virtual machine (Java VM) has built-in instrumentation that enables you to monitor and manage it using the Java Management Extensions (JMX) technology.&nbsp; To enable and configure monitoring of Java VM for any java-application using the ready-to-use JMX agent, you must set certain system properties when you start the Java VM. The default [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2261,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[34],"tags":[255,256],"class_list":["post-2257","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-technical","tag-jmx","tag-monitoring","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=2257"}],"version-history":[{"count":7,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2257\/revisions"}],"predecessor-version":[{"id":2267,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2257\/revisions\/2267"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/2261"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=2257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=2257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=2257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}