Skip to content

Commit

Permalink
[WFLY-17678] Add Micrometer quickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondlee committed Sep 28, 2023
1 parent b3fd30c commit e9e44ec
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 277 deletions.
62 changes: 42 additions & 20 deletions micrometer/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include::../shared-doc/attributes.adoc[]
:author: Jason Lee
:level: Beginner
:technologies: Micrometer
:custom-bootable-jar-layers: {lt}layer{gt}micrometer{lt}/layer{gt}

[abstract]
The `micrometer` quickstart demonstrates the use of the Micrometer library in {productName}.
Expand All @@ -20,32 +21,30 @@ https://micrometer.io[Micrometer] is a vendor-neutral facade that allows applica

In this quickstart, we will build a small, simple application that shows the usage of a number of Micrometer's `Meter` implementations. We will also demonstrate the means by which {productName} exports the metrics data, which is via the https://opentelemetry.io/docs/reference/specification/protocol/otlp/[OpenTelemetry Protocol (OTLP)] to the https://opentelemetry.io/docs/collector/[OpenTelemetry Collector]. To provide simpler access to the published metrics, the Collector will be configured with a Prometheus endpoint, from which we can scrape data.

// System Requirements
include::../shared-doc/system-requirements.adoc[leveloffset=+1]
== Prerequisites

To complete this guide, you will need:

* less than 15 minutes
* JDK 11+ installed with `JAVA_HOME` configured appropriately
* Apache Maven 3.5.3+

// Use of {jbossHomeName}
include::../shared-doc/use-of-jboss-home-name.adoc[leveloffset=+1]

// Start the {productName} Standalone Server
== Steps

include::../shared-doc/start-the-standalone-server.adoc[leveloffset=+1]

include::../shared-doc/build-and-deploy-the-quickstart.adoc[leveloffset=+1]

== Solution

We recommend that you follow the instructions that
<<creating-new-project, create the application step by step>>. However, you can
also go right to the completed example which is available in this directory.
We recommend that you follow the instructions that <<creating-new-project, create the application step by step>>. However,
you can also go right to the completed example which is available in this directory.

// Build and Deploy the Quickstart
include::../shared-doc/build-and-deploy-the-quickstart.adoc[leveloffset=+1]

// Undeploy the Quickstart
include::../shared-doc/undeploy-the-quickstart.adoc[leveloffset=+1]


// Run the Quickstart in Red Hat CodeReady Studio or Eclipse
include::../shared-doc/run-the-quickstart-in-jboss-developer-studio.adoc[leveloffset=+1]


[[creating-new-project]]
== Creating the Maven Project

Expand Down Expand Up @@ -77,7 +76,15 @@ Now we need to start adding our dependencies. Since this will be demo will use J
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-ee</artifactId>
<version>${version.server.bom}</version>
<version>${version.server}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Import micrometer dependency information -->
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-common-expansion-dependency-management</artifactId>
<version>${version.server}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -93,7 +100,6 @@ Next, we need to add the dependencies for both Micrometer, Jakarta REST, and CDI
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.9.3</version>
<scope>provided</scope>
</dependency>
Expand Down Expand Up @@ -252,13 +258,13 @@ Before we can deploy the application to {productName}, however, we need to confi

[source,subs="attributes+"]
----
$ /path/to/{productName]/bin/jboss-cli -c
$ /path/to/{productName}/bin/jboss-cli.sh -c
[standalone@localhost:9990 /] /extension=org.wildfly.extension.micrometer:add
[standalone@localhost:9990 /] /subsystem=micrometer:add(endpoint="http://localhost:4318/v1/metrics")
[standalone@localhost:9990 /] reload
----

By default, {productName} will publish metrics every 10 seconds, so you will soon start seeing errors about a refused connection. This is because we told {productName} to publish to a server that is not there, so we need to fix that. To make that as simple as possible, you can use Docker/Podman compose to start an instance of the OpenTelemetry Collector:
By default, {productName} will publish metrics every 10 seconds, so you will soon start seeing errors about a refused connection. This is because we told {productName} to publish to a server that is not there, so we need to fix that. To make that as simple as possible, you can use Docker Compose to start an instance of the OpenTelemetry Collector:

[source,yaml]
----
Expand Down Expand Up @@ -295,7 +301,7 @@ You can either access the application via your browser at http://localhost:8080/
$ curl http://localhost:8080/micrometer/prime/13
----

Once given enough time to allow {productName} to publish metrics updates, you now see your application's meters reported in the http://localhost:1234/metrics[Promethues export]. You can also view them via the command-line:
Once given enough time to allow {productName} to publish metrics updates, you now see your application's meters reported in the http://localhost:1234/metrics[Prometheus export]. You can also view them via the command-line:

[source,bash]
----
Expand All @@ -320,6 +326,22 @@ prime_timer_count{job="wildfly"} 1

Notice that all four meters registered in the `@PostConstruct` method as well as the `Timer` in our endpoint method have all been published.

// Server Distribution Testing
include::../shared-doc/run-integration-tests-with-server-distribution.adoc[leveloffset=+2]

include::../shared-doc/undeploy-the-quickstart.adoc[leveloffset=+1]

// Bootable JAR
include::../shared-doc/build-and-run-the-quickstart-with-bootable-jar.adoc[leveloffset=+1]

// OpenShift
include::../shared-doc/build-and-run-the-quickstart-with-openshift.adoc[leveloffset=+1]

// Build and run sections for other environments/builds
ifndef::ProductRelease,EAPXPRelease[]
include::../shared-doc/build-and-run-the-quickstart-with-provisioned-server.adoc[leveloffset=+1]
endif::[]

== Conclusion

Micrometer provides a de facto standard way of capturing and publishing metrics to the monitoring solution of your choice. {productName} provides a convenient, out-of-the-box integration of Micrometer to make it easier to capture those metrics and monitor your application's health and performance. For more information on Micrometer, please refer to the project's https://micrometer.io[website].
Loading

0 comments on commit e9e44ec

Please sign in to comment.