Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference doc update for tomcat #4599

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
** xref:reference/mongodb.adoc[MongoDB]
** xref:reference/netty.adoc[Netty]
** xref:reference/okhttpclient.adoc[OkHttpClient]
** xref:reference/tomcat.adoc[Tomcat]
* xref:guides.adoc[Guides]
** xref:guides/console-reporter.adoc[Passing through to Dropwizard's console reporter]
** xref:guides/http-sender-resilience4j-retry.adoc[HttpSender with Resilience4j retry]
Expand Down
15 changes: 15 additions & 0 deletions docs/modules/ROOT/pages/reference/tomcat.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[overview]]
= Apache Tomcat Metrics Instrumentation

The https://tomcat.apache.org/[Apache Tomcat] software is an open source implementation of the Jakarta Servlet, Jakarta Server Pages, Jakarta Expression Language, Jakarta WebSocket, Jakarta Annotations and Jakarta Authentication specifications.

[source,java,subs=+attributes]
-----
// Setting up instrumentation
include::{include-core-test-java}/io/micrometer/core/instrument/binder/tomcat/TomcatMetricsTest.java[tags=setup, indent=0]

include::{include-core-test-java}/io/micrometer/core/instrument/binder/tomcat/TomcatMetricsTest.java[tags=monitor, indent=0]

// Example of Tomcat metrics
include::{include-core-test-java}/io/micrometer/core/instrument/binder/tomcat/TomcatMetricsTest.java[tags=example, indent=0]
-----
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ class TomcatMetricsTest {

private static final int PROCESSING_TIME_IN_MILLIS = 10;

private SimpleMeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());
// tag::setup[]
SimpleMeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());

// end::setup[]

private int port;

Expand Down Expand Up @@ -108,15 +111,19 @@ public Context getContext() {
expiredSession.setCreationTime(System.currentTimeMillis() - 10_000);
manager.remove(expiredSession, true);

// tag::monitor[]
Iterable<Tag> tags = Tags.of("metricTag", "val1");
TomcatMetrics.monitor(registry, manager, tags);
// end::monitor[]

// tag::example[]
assertThat(registry.get("tomcat.sessions.active.max").tags(tags).gauge().value()).isEqualTo(3.0);
assertThat(registry.get("tomcat.sessions.active.current").tags(tags).gauge().value()).isEqualTo(2.0);
assertThat(registry.get("tomcat.sessions.expired").tags(tags).functionCounter().count()).isEqualTo(1.0);
assertThat(registry.get("tomcat.sessions.rejected").tags(tags).functionCounter().count()).isEqualTo(1.0);
assertThat(registry.get("tomcat.sessions.created").tags(tags).functionCounter().count()).isEqualTo(3.0);
assertThat(registry.get("tomcat.sessions.alive.max").tags(tags).timeGauge().value()).isGreaterThan(1.0);
// end::example[]
}

private void sleep() {
Expand Down