Monitoring with metrics

Three kinds of metrics are available to monitor your Open Liberty applications: OpenTelemetry metrics from MicroProfile Telemetry, REST endpoint-style metrics from MicroProfile Metrics, and Java Management Extensions (JMX) metrics. MicroProfile Metrics and JMX metrics can be used separately or in conjunction to improve the observability of your application systems.

MicroProfile Telemetry 2.0 and later exports metrics to OTLP or another configured OpenTelemetry metrics exporter. You might prefer this option if you also use MicroProfile Telemetry to manage your logs and traces. MicroProfile Metrics can be accessed by monitoring tools, such as Prometheus, or by any client that can make REST requests. JMX metrics are suitable for use by Java-based monitoring tools that can communicate with JMX servers, or by custom JMX clients.

Collect and export metrics with MicroProfile Telemetry

When you enable the MicroProfile Telemetry feature version 2.0 and later, you can manage your logs, metrics, and traces in a standardized way with the OpenTelemetry protocol. For more information, see Enable observability with MicroProfile Telemetry.

MicroProfile Metrics and the metrics endpoint

Open Liberty uses MicroProfile Metrics to expose metrics that describe the internal state of many Open Liberty components. Developers can also use the MicroProfile Metrics API to expose metrics from their applications. For more information about adding these metrics to your applications, see Adding metrics to your applications and the Providing metrics from a microservice guide. For a list of all REST endpoint-style metrics that are available for Open Liberty, see the Metrics reference list.

The MicroProfile Metrics feature provides a /metrics REST interface that conforms to the MicroProfile Metrics specification. You can access MicroProfile Metrics with Open Liberty by enabling the MicroProfile Metrics feature. Real-time values of all metrics are available by calling the /metrics endpoint, which provides formatted metric data that can be consumed as time-series data by external monitoring tools.

When an application is running, you can view metric data from any browser by accessing the /metrics endpoint, for example, https://localhost:9443/metrics, where 9443 is the port number for your application. You can narrow the scope of the metrics by using the scope query parameter with the /metrics endpoint to specify the metric registry scope. For example, to view the metric data for the base metric registry, use the /metrics?scope=base endpoint. This pattern is used to access all runtime-provided scopes (base, application, and vendor) and any user-defined metric registry scopes. For MicroProfile Metrics 4.0 and earlier, only runtime-provided scopes are available and path parameters are used to narrow down metric data. The endpoints are /metrics/base, /metrics/application, and /metrics/vendor.

By default, MicroProfile Metrics provides metrics data in Prometheus format. Prometheus format is a representation of the metrics that is compatible with the Prometheus monitoring tool, which is an open source metrics scraper, data store, and basic visualization tool. In MicroProfile metrics 4.0 and earlier, JSON format is also available.

The format that each response uses depends on the HTTP accept header of the corresponding request. Prometheus format is returned for requests with a text/plain accept header. In MicroProfile metrics 4.0 and earlier, JSON format is returned for requests with an application/json accept header.

Metrics endpoints differ in syntax and output between MicroProfile Metrics 5.0 and MicroProfile Metrics 4.0 and earlier. MicroProfile Metrics 5.0 also uses embedded Micrometer metrics technology to enable third-party monitoring systems. For more information, see Differences between MicroProfile Metrics 5.0 and 4.0.

Metrics endpoints in MicroProfile Metrics 5.0

MicroProfile Metrics 5.0 does not support JSON-formatted output. Furthermore, syntax for the endpoints URLs uses query string parameters for the scope and metric name values.

The following table displays the different endpoints that can be accessed with a GET request in MicroProfile Metrics 5.0 to provide metrics in Prometheus format.

Metrics endpoints that are accessible by GET request
EndpointRequest typeSupported formatsDescription

/metrics

GET

Prometheus

Returns all registered metrics.

/metrics?scope=<scope>

GET

Prometheus

Returns metrics that are registered for the specified scope.

/metrics?scope=<scope>&name=<metric_name>

GET

Prometheus

Returns metrics that match the metric name for the specified scope.

Metrics endpoints in MicroProfile Metrics 4.0 and earlier

The following table displays the different endpoints that can be accessed with a GET request in MicroProfile Metrics 4.0 and earlier to provide metrics in Prometheus or JSON format.

Metrics endpoints that are accessible by GET request
EndpointRequest typeSupported formatsDescription

/metrics

GET

Prometheus, JSON

Returns all registered metrics.

/metrics/<scope>

GET

Prometheus, JSON

Returns metrics that are registered for the specified scope.

/metrics/<scope>/<metric_name>

GET

Prometheus, JSON

Returns metrics that match the metric name for the specified scope.

JMX metrics

You can access JMX metrics by enabling the Performance Monitoring feature. After you add this feature to your server configuration, JMX metrics are automatically monitored. The Performance Monitoring feature provides MXBeans that you can use with monitoring tools that use JMX, such as JConsole.

JConsole is a graphical monitoring tool that you can use to monitor JVM and Java applications. After you enable monitoring for Open Liberty, you can use JConsole to connect to the JVM and view performance data by clicking attributes of the MXBeans. You can also use other products that consume JMX metrics to view your metrics information. For more information, see Configuring JMX connections. For a list of all JMX metrics that are available for Open Liberty, see the JMX metrics reference list.

MicroProfile and JMX metrics combined

The MicroProfile Metrics feature provides basic metrics about the JVM and about metrics that are added to applications by using the MicroProfile Metrics API. However, the MicroProfile Metrics feature doesn’t provide metrics about Open Liberty server components unless it’s used along with the Performance Monitoring feature.

If you enable both the MicroProfile Metrics and Performance Monitoring features, then the MXBeans for monitoring and the /metrics REST endpoint are activated. In this case, metrics for Open Liberty server components are exposed through both interfaces. The MicroProfile Metrics feature versions 2.3 and later automatically enable the Performance Monitoring feature.