Skip to content

Commit ee223df

Browse files
author
Miguel Rodriguez
authored
Add Jetty Integration (#320)
* Add jetty integration * Update Readmes * Add Default app to generate session metrics * Spotless * Fix doc description
1 parent 8e0c440 commit ee223df

File tree

7 files changed

+181
-1
lines changed

7 files changed

+181
-1
lines changed

jmx-metrics/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ mutually exclusive with `otel.jmx.groovy.script`. The currently supported target
7373
| [`cassandra`](./docs/target-systems/cassandra.md) |
7474
| [`hbase`](./docs/target-systems/hbase.md) |
7575
| [`hadoop`](./docs/target-systems/hadoop.md) |
76+
| [`jetty`](./docs/target-systems/jetty.md) |
7677
| [`kafka`](./docs/target-systems/kafka.md) |
7778
| [`kafka-consumer`](./docs/target-systems/kafka-consumer.md) |
7879
| [`kafka-producer`](./docs/target-systems/kafka-producer.md) |
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Jetty Metrics
2+
3+
The JMX Metric Gatherer provides built in Jetty metric gathering capabilities.
4+
Details about using JMX with WildFly can be found here: https://www.eclipse.org/jetty/documentation/jetty-11/operations-guide/index.html#og-jmx
5+
6+
### Metrics
7+
* Name: `jetty.select.count`
8+
* Description: The number of select calls.
9+
* Unit: `{operations}`
10+
* Instrument Type: longCounterCallback
11+
12+
13+
* Name: `jetty.session.count`
14+
* Description: The number of sessions created.
15+
* Unit: `{sessions}`
16+
* Instrument Type: LongCounterCallback
17+
18+
19+
* Name: `jetty.session.time.total`
20+
* Description: The total time sessions have been active.
21+
* Unit: `s`
22+
* Instrument Type: longUpDownCounterCallback
23+
24+
25+
* Name: `jetty.session.time.max`
26+
* Description: The maximum amount of time a session has been active.
27+
* Unit: `s`
28+
* Instrument Type: longValueCallback
29+
30+
31+
* Name: `jetty.thread.count`
32+
* Description: The current number of threads.
33+
* Unit: `{threads}`
34+
* Labels: `state`
35+
* Instrument Type: longValueCallback
36+
37+
38+
* Name: `jetty.thread.queue.count`
39+
* Description: The current number of threads in the queue.
40+
* Unit: `{threads}`
41+
* Instrument Type: longValueCallback
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.contrib.jmxmetrics.target_systems;
7+
8+
import static org.assertj.core.api.Assertions.entry;
9+
10+
import io.opentelemetry.contrib.jmxmetrics.AbstractIntegrationTest;
11+
import java.time.Duration;
12+
import org.junit.jupiter.api.Test;
13+
import org.testcontainers.containers.GenericContainer;
14+
import org.testcontainers.containers.Network;
15+
import org.testcontainers.containers.wait.strategy.Wait;
16+
import org.testcontainers.images.builder.ImageFromDockerfile;
17+
import org.testcontainers.junit.jupiter.Container;
18+
19+
class JettyIntegrationTest extends AbstractIntegrationTest {
20+
21+
JettyIntegrationTest() {
22+
super(/* configFromStdin= */ false, "target-systems/jetty.properties");
23+
}
24+
25+
@Container
26+
GenericContainer<?> jetty =
27+
new GenericContainer<>(
28+
new ImageFromDockerfile()
29+
.withDockerfileFromBuilder(
30+
builder ->
31+
builder
32+
.from("jetty")
33+
.run(
34+
"java",
35+
"-jar",
36+
"/usr/local/jetty/start.jar",
37+
"--add-to-startd=jmx,stats,http")
38+
.run("mkdir -p /var/lib/jetty/webapps/ROOT/")
39+
.run("touch /var/lib/jetty/webapps/ROOT/index.html")
40+
.env(
41+
"JAVA_OPTIONS",
42+
"-Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.rmi.port=1099")
43+
.build()))
44+
.withNetwork(Network.SHARED)
45+
.withEnv("LOCAL_JMX", "no")
46+
.withNetworkAliases("jetty")
47+
.withExposedPorts(1099, 8080)
48+
.withStartupTimeout(Duration.ofMinutes(2))
49+
.waitingFor(Wait.forLogMessage(".*Started Server.*", 1));
50+
51+
@Test
52+
void endToEnd() throws InterruptedException {
53+
waitAndAssertMetrics(
54+
metric ->
55+
assertSumWithAttributes(
56+
metric,
57+
"jetty.session.count",
58+
"The number of sessions established in total.",
59+
"{sessions}",
60+
attrs -> attrs.containsKey("resource")),
61+
metric ->
62+
assertSumWithAttributes(
63+
metric,
64+
"jetty.session.time.total",
65+
"The total time sessions have been active.",
66+
"s",
67+
attrs -> attrs.containsKey("resource")),
68+
metric ->
69+
assertGaugeWithAttributes(
70+
metric,
71+
"jetty.session.time.max",
72+
"The maximum amount of time a session has been active.",
73+
"s",
74+
attrs -> attrs.containsKey("resource")),
75+
metric ->
76+
assertSum(metric, "jetty.select.count", "The number of select calls.", "{operations}"),
77+
metric ->
78+
assertGaugeWithAttributes(
79+
metric,
80+
"jetty.thread.count",
81+
"The current number of threads.",
82+
"{threads}",
83+
attrs -> attrs.contains(entry("state", "busy")),
84+
attrs -> attrs.contains(entry("state", "idle"))),
85+
metric ->
86+
assertGauge(
87+
metric,
88+
"jetty.thread.queue.count",
89+
"The current number of threads in the queue.",
90+
"{threads}"));
91+
}
92+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
otel.jmx.interval.milliseconds = 3000
2+
otel.metrics.exporter = otlp
3+
otel.jmx.service.url = service:jmx:rmi:///jndi/rmi://jetty:1099/jmxrmi
4+
otel.jmx.target.system = jetty
5+
6+
# these will be overridden by cmd line
7+
otel.exporter.otlp.endpoint = http://host.testcontainers.internal

jmx-metrics/src/main/groovy/io/opentelemetry/contrib/jmxmetrics/JmxConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class JmxConfig {
4949
"cassandra",
5050
"hbase",
5151
"hadoop",
52+
"jetty",
5253
"jvm",
5354
"kafka",
5455
"kafka-consumer",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
def beanSelector = otel.mbean("org.eclipse.jetty.io:context=*,type=managedselector,id=*")
18+
otel.instrument(beanSelector, "jetty.select.count", "The number of select calls.", "{operations}","selectCount", otel.&longCounterCallback)
19+
20+
def beanSessions = otel.mbean("org.eclipse.jetty.server.session:context=*,type=sessionhandler,id=*")
21+
otel.instrument(beanSessions, "jetty.session.count", "The number of sessions established in total.", "{sessions}",
22+
["resource" : { mbean -> mbean.name().getKeyProperty("context") }],
23+
"sessionsCreated", otel.&longCounterCallback)
24+
otel.instrument(beanSessions, "jetty.session.time.total", "The total time sessions have been active.", "s",
25+
["resource" : { mbean -> mbean.name().getKeyProperty("context") }],
26+
"sessionTimeTotal", otel.&longUpDownCounterCallback)
27+
otel.instrument(beanSessions, "jetty.session.time.max", "The maximum amount of time a session has been active.", "s",
28+
["resource" : { mbean -> mbean.name().getKeyProperty("context") }],
29+
"sessionTimeMax", otel.&longValueCallback)
30+
31+
def beanThreads = otel.mbean("org.eclipse.jetty.util.thread:type=queuedthreadpool,id=*")
32+
otel.instrument(beanThreads, "jetty.thread.count", "The current number of threads.", "{threads}",
33+
[
34+
"busyThreads":["state" : {"busy"}],
35+
"idleThreads": ["state" : {"idle"}]
36+
], otel.&longValueCallback)
37+
otel.instrument(beanThreads, "jetty.thread.queue.count", "The current number of threads in the queue.", "{threads}","queueSize", otel.&longValueCallback)

jmx-metrics/src/test/java/io/opentelemetry/contrib/jmxmetrics/JmxConfigTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void staticValues() {
2323
"cassandra",
2424
"hbase",
2525
"hadoop",
26+
"jetty",
2627
"jvm",
2728
"kafka",
2829
"kafka-consumer",
@@ -191,7 +192,7 @@ void invalidTargetSystem() {
191192
assertThatThrownBy(config::validate)
192193
.isInstanceOf(ConfigurationException.class)
193194
.hasMessage(
194-
"[jvm, unavailabletargetsystem] must specify targets from [activemq, cassandra, hbase, hadoop, jvm, "
195+
"[jvm, unavailabletargetsystem] must specify targets from [activemq, cassandra, hbase, hadoop, jetty, jvm, "
195196
+ "kafka, kafka-consumer, kafka-producer, solr, tomcat, wildfly]");
196197
}
197198

0 commit comments

Comments
 (0)