Collect Java Management Extensions (JMX) metrics
You can use the CloudWatch agent to collect Java Management Extensions (JMX) metrics from your Java applications.
The CloudWatch agent supports collecting these metrics from the following versions:
JVM 8 and later
Kafka 0.8.2.x and later
Tomcat 9, 10.1, and 11 (beta)
To start collecting JMX metrics,
add a jmx
section inside the metrics_collected
section of the
CloudWatch agent configuration file. The jmx
section can
contain the following fields.
jvm
– Optional. Specifies that you want to retrieve Java Virtual Machine (JVM) metrics from the instance. For more information, see Collect JVM metrics.This section can include the following fields:
-
measurement
– Specifies the array of JVM metrics to be collected. For a list of the possible values to use here, see the Metric column in the table in Collect JVM metrics.Within the entry for each individual metric, you can optionally specify one or both of the following:
-
rename
– Specifies a different name for this metric. -
unit
– Specifies the unit to use for this metric, overriding the default unit for the metric. The unit that you specify must be a valid CloudWatch metric unit, as listed in theUnit
description in MetricDatum.
-
-
kafka
– Optional. Specifies that you want to retrieve Apache Kafka broker metrics from the instance. For more information, see Collect Kafka metrics.This section can include the following fields:
-
measurement
– Specifies the array of Kafka broker metrics to be collected. For a list of the possible values to use here, see the Metric column in the first table in Collect Kafka metrics.Within the entry for each individual metric, you can optionally specify one or both of the following:
-
rename
– Specifies a different name for this metric. -
unit
– Specifies the unit to use for this metric, overriding the default unit for the metric. The unit that you specify must be a valid CloudWatch metric unit, as listed in theUnit
description in MetricDatum.
-
-
kafka-consumer
– Optional. Specifies that you want to retrieve Apache Kafka consumer metrics from the instance. For more information, see Collect Kafka metrics.This section can include the following fields:
-
measurement
– Specifies the array of Kafka broker metrics to be collected. For a list of the possible values to use here, see the Metric column in the second metrics table in Collect Kafka metrics.Within the entry for each individual metric, you can optionally specify one or both of the following:
-
rename
– Specifies a different name for this metric. -
unit
– Specifies the unit to use for this metric, overriding the default unit for the metric. The unit that you specify must be a valid CloudWatch metric unit, as listed in theUnit
description in MetricDatum.
-
-
kafka-producer
– Optional. Specifies that you want to retrieve Apache Kafka producer metrics from the instance. For more information, see Collect Kafka metrics.This section can include the following fields:
-
measurement
– Specifies the array of Kafka broker metrics to be collected. For a list of the possible values to use here, see the Metric column in the third metrics table in Collect Kafka metrics.Within the entry for each individual metric, you can optionally specify one or both of the following:
-
rename
– Specifies a different name for this metric. -
unit
– Specifies the unit to use for this metric, overriding the default unit for the metric. The unit that you specify must be a valid CloudWatch metric unit, as listed in theUnit
description in MetricDatum.
-
-
tomcat
– Optional. Specifies that you want to retrieve Tomcat metrics from the instance. For more information, see Collect Tomcat metrics.This section can include the following fields:
-
measurement
– Specifies the array of Tomcat metrics to be collected. For a list of the possible values to use here, see the Metric column in the table in Collect Tomcat metrics.Within the entry for each individual metric, you can optionally specify one or both of the following:
-
rename
– Specifies a different name for this metric. -
unit
– Specifies the unit to use for this metric, overriding the default unit for the metric. The unit that you specify must be a valid CloudWatch metric unit, as listed in theUnit
description in MetricDatum.
-
-
The jmx
section can also include the optional append_dimensions
field:
-
append_dimensions
– Optional. Additional dimensions to use for only the process metrics. If you specify this field, it's used in addition to dimensions specified in theappend_dimensions
field that is used for all types of metrics collected by the agent.
The following fields are for Amazon EC2 only.
-
endpoint
– The address for the JMX client to connect to. The format isip:port
. If the endpoint is not the localhost, and password authentication and SSL must be enabled. -
metrics_collection_interval
– Optional. Specifies how often to collect the processes metrics, overriding the globalmetrics_collection_interval
specified in theagent
section of the configuration file.This value is specified in seconds. For example, specifying 10 causes metrics to be collected every 10 seconds, and setting it to 300 specifies metrics to be collected every 5 minutes.
If you set this value below 60 seconds, each metric is collected as a high-resolution metric. For more information, see High-resolution metrics.
If JMX was enabled with password authentication or SSL for remote access, you can use the following fields.
-
password_file
– Optional. Specifies a Java properties file of keys to passwords. The file must be read-only and restricted to the user running the CloudWatch agent. If password authentication is enabled, this requires the same username and password pair as the entry in the JMX password file provided in thecom.sun.management.jmxremote.password.file
property. If SSL is enabled, it requires entries forkeystore
andtruststore
and corresponds to thejavax.net.ssl.keyStorePassword
andjavax.net.ssl.trustStorePassword
respectively. -
username
– If password authentication is enabled, specify the username that matches the username in the provided password file. -
keystore_path
– If SSL is enabled, specify the full path to the Java keystore, which consists of a private key and a certificate to the public key. Corresponds to thejavax.net.ssl.keyStore
property. -
keystore_type
– If SSL is enabled, specify the type of keystore being used. Corresponds to thejavax.net.ssl.keyStoreType
property. -
truststore_path
– If SSL is enabled, specify the full path to the Java truststore, which must contain the remote JMX server's public certificate. Corresponds to thejavax.net.ssl.trustStore
property. -
truststore_type
– If SSL is enabled, specify the type of truststore being used. Corresponds to thejavax.net.ssl.trustStoreType
property. -
remote_profile
– Optional. Supported JMX remote profiles are TLS in combination with SASL profiles:SASL/PLAIN
,SASL/DIGEST-MD5
, andSASL/CRAM-MD5
. Should be one of:SASL/PLAIN
,SASL/DIGEST-MD5
,SASL/CRAM-MD5
,TLS SASL/PLAIN
,TLS SASL/DIGEST-MD5
, orTLS SASL/CRAM-MD5
-
realm
– Optional. The realm as required by the remote profileSASL/DIGEST-MD5
. -
registry_ssl_enabled
– If RMI registry authentication is enabled. Set to true if the JVM was configured withcom.sun.management.jmxremote.registry.ssl=true
. insecure
Set totrue
to opt out of the validation required if the agent is configured for a non-localhost endpoint.
The following is an example of the jmx
section of the CloudWatch agent configuration file.
{ "metrics": { "metrics_collected": { "jmx": [ { "endpoint": "remotehost:1314", "jvm": { "measurement": [ "jvm.memory.heap.init", "jvm.memory.nonheap.used" ] }, "kafka": { "measurement": [ "kafka.request.count", { "name": "kafka.message.count", "rename": "KAFKA_MESSAGE_COUNT", "unit": "Count" } ] }, "username": "cwagent", "keystore_path": "/path/to/keystore", "keystore_type": "PKCS12", "truststore_path": "/path/to/truststore", "truststore_type": "PKCS12" }, { "endpoint": "localhost:1315", "kafka-producer": { "measurement": [ "kafka.producer.request-rate" ] }, "append_dimensions": { "service.name": "kafka/1" } } ] } } }
Collect JVM metrics
You can use the CloudWatch agent to collect Java Virtual Machine (JVM) metrics. To set this up,
add a jvm
section inside the jmx
section of the
CloudWatch agent configuration file.
The following metrics can be collected.
Metric | Dimensions | Description |
---|---|---|
|
[DEFAULT] |
The total number of loaded classes. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The total number of garbage collections that have occurred. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The approximate accumulated garbage collection elapsed time. Unit: Milliseconds Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The initial amount of memory that the JVM requests from the operating system for the heap. Unit: Bytes Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The maximum amount of memory that can be used for the heap. Unit: Bytes Meaningful statistics: Maximum |
|
[DEFAULT] |
The current heap memory usage. Unit: Bytes Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The amount of memory that is guaranteed to be available for the heap. Unit: Bytes Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The initial amount of memory that the JVM requests from the operating system for non-heap purposes. Unit: Bytes Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The maximum amount of memory that can be used for non-heap purposes. Unit: Bytes Meaningful statistics: Maximum |
|
[DEFAULT] |
The current non-heap memory usage. Unit: Bytes Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The amount of memory that is guaranteed to be available for non-heap purposes. Unit: Bytes Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The initial amount of memory that the JVM requests from the operating system for the memory pool. Unit: Bytes Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The maximum amount of memory that can be used for the memory pool. Unit: Bytes Meaningful statistics: Maximum |
|
[DEFAULT], |
The current memory pool memory usage. Unit: Bytes Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The amount of memory that is guaranteed to be available for the memory pool. Unit: Bytes Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The current number of threads. Unit: None Meaningful statistics: Minimum, Maximum, Average |
The JVM metrics are collected with the following dimensions:
Dimension | Description |
---|---|
[DEFAULT] |
On Amazon EC2 by default, the host is also published as a dimension of metrics that are collected by the CloudWatch agent,
unless you are using the On Amazon EKS by default, k8s related context is also published as dimensions of metrics ( |
|
For For |
Collect Kafka metrics
You can use the CloudWatch agent to collect Apache Kafka metrics. To set this up,
add one or more of the following subsections inside the jmx
section of the
CloudWatch agent configuration file.
Use a
kafka
section to collect Kafka broker metrics.Use a
kafka-consumer
section to collect Kafka consumer metrics.Use a
kafka-producer
section to collect Kafka producer metrics.
Kafka broker metrics
The following metrics can be collected for Kafka brokers.
Metric | Dimensions | Description |
---|---|---|
|
[DEFAULT] |
The number of messages received by the Kafka broker. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The number of requests received by the Kafka broker. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The number of requests to the Kafka broker that resulted in a failure. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The total time that the Kafka broker has taken to service requests. Unit: Milliseconds Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The 50th percentile time that the Kafka broker has taken to service requests. Unit: Milliseconds Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The 99th percentile time that the Kafka broker has taken to service requests. Unit: Milliseconds Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The average time that the Kafka broker has taken to service requests. Unit: Milliseconds Meaningful statistics: Average |
|
[DEFAULT], |
The number of bytes received by or sent by the Kafka broker. Unit: Bytes Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The number of requests waiting in purgatory. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The number of partitions on the Kafka broker. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The number of partitions that are offline. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The number of under-replicated partitions. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The number of in-sync replica shrink and expand operations. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The maximum lag in messages between follower and leader replicas. Unit: None Meaningful statistics: Maximum |
|
[DEFAULT] |
The number of active controllers on the broker. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
Leader election rate. If this increases, it indicates broker failures. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
Unclean leader election rate. If this increases, it indicates broker failures. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The size of the request queue. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The logs flush count. Unit: Milliseconds Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The 50th percentile value of the logs flush count. Unit: Milliseconds Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT] |
The 99th percentile value of the logs flush count. Unit: Milliseconds Meaningful statistics: Minimum, Maximum, Average |
The Kafka broker metrics are collected with the following dimensions:
Dimension | Description |
---|---|
[DEFAULT] |
On Amazon EC2 by default, the host is also published as a dimension of metrics that are collected by the CloudWatch agent,
unless you are using the On Amazon EKS by default, k8s related context is also published as dimensions of metrics ( |
|
The request type. Possible values are |
|
The direction of network traffic. Possible values are |
|
The operation type for the in-sync replica. Possible values are |
Kafka consumer metrics
The following metrics can be collected for Kafka consumers.
Metric | Dimensions | Description |
---|---|---|
|
[DEFAULT], |
The number of fetch requests for all topics per second. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The number of messages that the consumer lags behind the producer. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The average number of bytes consumed for all topics per second. Unit: Bytes Meaningful statistics: Average |
|
[DEFAULT], |
The number of bytes fetched per request for all topics. Unit: Bytes Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The average number of records consumed for all topics per second. Unit: None Meaningful statistics: Average |
|
[DEFAULT], |
The average number of bytes consumed per second. Unit: Bytes Meaningful statistics: Average |
|
[DEFAULT], |
The number of bytes fetched per request. Unit: Bytes Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The average number of records consumed per second. Unit: None Meaningful statistics: Average |
The Kafka consumer metrics are collected with the following dimensions:
Dimension | Description |
---|---|
[DEFAULT] |
On Amazon EC2 by default, the host is also published as a dimension of metrics that are collected by the CloudWatch agent,
unless you are using the On Amazon EKS by default, k8s related context is also published as dimensions of metrics ( |
|
The ID of the client. |
|
The Kafka topic. |
Kafka producer metrics
The following metrics can be collected for Kafka producers.
Metric | Dimensions | Description |
---|---|---|
|
[DEFAULT], |
The average length of time the I/O thread spent waiting for a socket ready for reads or writes. Unit: None Meaningful statistics: Average |
|
[DEFAULT], |
The average number of outgoing bytes sent per second to all servers. Unit: Bytes Meaningful statistics: Average |
|
[DEFAULT], |
The average request latency. Unit: Milliseconds Meaningful statistics: Average |
|
[DEFAULT], |
The average number of requests sent per second. Unit: None Meaningful statistics: Average |
|
[DEFAULT], |
The number of responses received per second. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The average number of bytes sent per second for a topic. Unit: Bytes Meaningful statistics: Average |
|
[DEFAULT], |
The average compression rate of record batches for a topic. Unit: None Meaningful statistics: Average |
|
[DEFAULT], |
The average per-second number of record sends that resulted in errors for a topic. Unit: None Meaningful statistics: Average |
|
[DEFAULT], |
The average per-second number of retried record sends for a topic. Unit: None Meaningful statistics: Average |
|
[DEFAULT], |
The average number of records sent per second for a topic. Unit: None Meaningful statistics: Average |
Kafka producer metrics are collected with the following dimensions:
Dimension | Description |
---|---|
[DEFAULT] |
On Amazon EC2 by default, the host is also published as a dimension of metrics that are collected by the CloudWatch agent,
unless you are using the On Amazon EKS by default, k8s related context is also published as dimensions of metrics ( |
|
The ID of the client. |
|
The Kafka topic. |
Collect Tomcat metrics
You can use the CloudWatch agent to collect Apache Tomcat metrics. To set this up,
add a tomcat
section inside the metrics_collected
section of the
CloudWatch agent configuration file.
The following metrics can be collected.
Metric | Dimensions | Description |
---|---|---|
|
[DEFAULT] |
The number of active sessions. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The number of errors encountered. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The total processing time. Unit: Milliseconds Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The number of bytes received and sent. Unit: Bytes Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
The number of threads. Unit: None Meaningful statistics: Minimum, Maximum, Average |
|
[DEFAULT], |
Maximum time to process a request. Unit: Milliseconds Meaningful statistics: Maximum |
|
[DEFAULT], |
The total requests. Unit: None Meaningful statistics: Minimum, Maximum, Average |
Tomcat metrics are collected with the following dimensions:
Dimension | Description |
---|---|
[DEFAULT] |
On Amazon EC2 by default, the host is also published as a dimension of metrics that are collected by the CloudWatch agent,
unless you are using the On Amazon EKS by default, k8s related context is also published as dimensions of metrics ( |
|
The |
|
The traffic direction. Possible values are |