[[MicroProfile_Metrics_SmallRye_Subsystem_Config]]
= MicroProfile Metrics Subsystem Configuration

Support for https://microprofile.io/project/eclipse/microprofile-metrics[MicroProfile Metrics] is provided by
 the _microprofile-metrics-smallrye_ subsystem.

[[required-extension-microprofile-metrics-smallrye]]
== Required Extension

This extension is included in the standalone-microprofile configurations included in the
WildFly distribution.

You can add the extension to a configuration without it either by using the following CLI operations:

[source,options="nowrap"]
----
[standalone@localhost:9990 /] /extension=org.wildfly.extension.microprofile.metrics-smallrye:add
{"outcome" => "success"}

[standalone@localhost:9990 /] /subsystem=microprofile-metrics-smallrye:add
{
    "outcome" => "success",
    "response-headers" => {
        "operation-requires-reload" => true,
        "process-state" => "reload-required"
    }
}

[standalone@localhost:9990 /] reload
----

Or by adding an element to the application server profile XML to `<extensions>` section:

[source,xml,options="nowrap"]
----
<extension module="org.wildfly.extension.microprofile.metrics-smallrye"/>
----

and then the subsystem in the `<profile>` section:

[source,xml,options="nowrap"]
----
<subsystem xmlns="urn:wildfly:microprofile-metrics-smallrye:2.0"/>
----

It depends on the base metrics extension `org.wildfly.extension.metrics` that must be installed.

== Management Model

The `/subsystem=microprofile-metrics-smallrye` resource defines two attributes:

* `exposed-subsystems` - a list of strings corresponding to the names of subsystems that exposes their metrics in the HTTP metrics endpoints.
  By default, it is not defined (there will be no metrics exposed by subsystem. The special wildcard "\*" can be used to expose metrics from _all_ subsystems. The standalone
  configuration sets this attribute to "*".
* `prefix` - A string to prepend to WildFly metrics that are exposed by the HTTP endpoint `/metrics` with the Prometheus output format.

== HTTP Endpoint

The Metric HTTP endpoint is accessible on WildFly HTTP management interface http://localhost:9990/metrics[http://localhost:9990/metrics].

Secured access to the HTTP endpoint is controlled by the `security-enabled` attribute of the `/subsystem=microprofile-metrics-smallrye` resource.
The value of this attribute will override the `security-enabled` attribute of the `/subsystem=metrics` resource (documented in <<metrics-metrics-http-endpoint,Metrics subsystem configuration guide>>).

When the `microprofile.metrics-smallrye` is installed, this HTTP endpoint will return metrics according to MicroProfile Metrics specification.

----
$ curl -v http://localhost:9990/metrics
< HTTP/1.1 200 OK
...
# HELP base:classloader_total_loaded_class_count Displays the total number of classes that have been loaded since the Java virtual machine has started execution
.
# TYPE base:classloader_total_loaded_class_count counter
base:classloader_total_loaded_class_count 10822.0
...
----

== Exposed Metrics

The HTTP endpoint exposes the following metrics:

* Base metrics - Required metrics specified in the MicroProfile 1.1 specification are exposed in the `base`  scope.
* Vendor metrics - Vendor-specific metrics (e.g. for memory pools)
* Application metrics - Metrics from the application and from the deployment's subsystems are exposed in the `application` scope.

The WildFly metrics (that measures activity in the subsystem or application deployments) are exposed only on the `/metrics`
endpoint with the Prometheus format.

== Component Reference

The MicroProfile Metrics implementation is provided by the SmallRye Metrics project.

****

* https://microprofile.io/project/eclipse/microprofile-metrics[MicroProfile Metrics]
* http://github.com/smallrye/smallrye-metrics/[SmallRye Metrics]

****
