[[MicroProfile_Metrics_SmallRye]]
= MicroProfile Metrics Subsystem Configuration

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

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

This extension is included in all the standalone configurations included in the
WildFly distribution.

You can also add the extension to a configuration without it either by adding
an `<extension module="org.wildfly.extension.microprofile.metrics-smallrye"/>`
element to the xml or by using the following CLI operation:

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

== Management Model

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

* `security-enabled` - a boolean to indicate whether authentication is required to access the HTTP metrics endpoint (described below). By default, it is `true`. The
standalone configurations explicitly sets it to `false` to accept unauthenticated access to the HTTP endpoints.
* `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.
If it is set to `true`, the HTTP client must be authenticated.

If the application server is healthy, it will return a `200 OK` response:

----
$ 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
...
----

If security has been enabled, the HTTP client must pass the credentials corresponding to a management user
created by the `add-user` script. For example:

----
$ curl -v --digest -u myadminuser:myadminpassword 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
...
----

If the authentication fails, the  server will reply with a `401 NOT AUTHORIZED` response.

== 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.

=== WildFly Metrics Description

WildFly metrics names is based on the subsystem that provides them as well as the name of the attribute from the management model.
Their name can also be prepended with a `prefix` (specified on the `/subsystem=microprofile-metrics` resource).
Other information are stored using labels.

For example Undertow exposes a metric attribute `request-count` for every Servlet in an application deployment.
This attribute will be exposed to Prometheus with the name `wildfly_undertow_request_count`.
Other information such as the name of the Servlet are added to the labels of the metrics.

The [helloworld-rs quickstart](https://github.com/wildfly/quickstart/tree/master/helloworld-rs) creates a JAX-RS application
that can be deployed in WildFly.
A corresponding metric will be exposed for it with the name and labels:

* `wildfly_undertow_request_count_total{deployment="helloworld-rs.war",servlet="org.jboss.as.quickstarts.rshelloworld.JAXActivator",subdeployment="helloworld-rs.war"}`

[NOTE]
Some subsystems (such as `undertow` or `messaing-activemq`) do not enable their statistics by default
as they have an impact on performance and memory usage. These subsystems provides a `statistics-enabled` attribute that must
be set to `true` to enable them.
For convenience, WildFly standalone configuration provides expression to enable the statistics by setting a
System property `-Dwildfly.statistics-enabled=true` to enable statistics on the subsystems provided by the configuration.

== Component Reference

The Eclipse MicroProfile Metrics is implemented by the SmallRye Metrics project.

****

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

****