-
Couldn't load subscription status.
- Fork 1.1k
Add Jetty's ThreadPool metrics #593
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
Merged
jkschneider
merged 8 commits into
micrometer-metrics:master
from
matsumana:feature/add-jetty-threadpool-metrics
May 24, 2018
+193
−0
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3f46c6c
add Jetty's threadpool metrics
matsumana d216dde
fix test
matsumana c24112f
Update metric name
matsumana 7c02cc7
update metrics name and delete idle metric
matsumana 4cec3d5
fix test
matsumana f64f6ab
Add auto configuration to enable InstrumentedQueuedThreadPool
matsumana 02c633e
fix test
matsumana f89ff6f
fix test
matsumana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...rc/main/java/io/micrometer/core/instrument/binder/jetty/InstrumentedQueuedThreadPool.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /** | ||
| * Copyright 2017 Pivotal Software, Inc. | ||
| * <p> | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.core.instrument.binder.jetty; | ||
|
|
||
| import io.micrometer.core.instrument.MeterRegistry; | ||
| import io.micrometer.core.instrument.Tag; | ||
| import org.eclipse.jetty.util.thread.QueuedThreadPool; | ||
|
|
||
| public class InstrumentedQueuedThreadPool extends QueuedThreadPool { | ||
|
|
||
| private final MeterRegistry registry; | ||
| private final Iterable<Tag> tags; | ||
|
|
||
| public InstrumentedQueuedThreadPool(MeterRegistry registry, Iterable<Tag> tags) { | ||
| this.registry = registry; | ||
| this.tags = tags; | ||
| } | ||
|
|
||
| @Override | ||
| protected void doStart() throws Exception { | ||
| super.doStart(); | ||
| JettyServerThreadPoolMetrics threadPoolMetrics = new JettyServerThreadPoolMetrics(this, tags); | ||
| threadPoolMetrics.bindTo(registry); | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
...rc/main/java/io/micrometer/core/instrument/binder/jetty/JettyServerThreadPoolMetrics.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /** | ||
| * Copyright 2017 Pivotal Software, Inc. | ||
| * <p> | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.core.instrument.binder.jetty; | ||
|
|
||
| import io.micrometer.core.instrument.Gauge; | ||
| import io.micrometer.core.instrument.MeterRegistry; | ||
| import io.micrometer.core.instrument.Tag; | ||
| import io.micrometer.core.instrument.binder.MeterBinder; | ||
|
|
||
| public class JettyServerThreadPoolMetrics implements MeterBinder { | ||
|
|
||
| private final InstrumentedQueuedThreadPool threadPool; | ||
| private final Iterable<Tag> tags; | ||
|
|
||
| public JettyServerThreadPoolMetrics(InstrumentedQueuedThreadPool threadPool, Iterable<Tag> tags) { | ||
| this.threadPool = threadPool; | ||
| this.tags = tags; | ||
| } | ||
|
|
||
| @Override | ||
| public void bindTo(MeterRegistry registry) { | ||
| Gauge.builder("jetty.threads.min", threadPool, InstrumentedQueuedThreadPool::getMinThreads) | ||
| .tags(tags) | ||
| .description("The number of min threads") | ||
| .register(registry); | ||
| Gauge.builder("jetty.threads.max", threadPool, InstrumentedQueuedThreadPool::getMaxThreads) | ||
| .tags(tags) | ||
| .description("The number of max threads") | ||
| .register(registry); | ||
| Gauge.builder("jetty.threads.live", threadPool, InstrumentedQueuedThreadPool::getThreads) | ||
| .tags(tags) | ||
| .description("The current number of live threads") | ||
| .register(registry); | ||
| Gauge.builder("jetty.threads.idle", threadPool, InstrumentedQueuedThreadPool::getIdleThreads) | ||
| .tags(tags) | ||
| .description("The current number of idle threads") | ||
| .register(registry); | ||
| Gauge.builder("jetty.threads.busy", threadPool, InstrumentedQueuedThreadPool::getBusyThreads) | ||
| .tags(tags) | ||
| .description("The current number of busy threads") | ||
| .register(registry); | ||
| } | ||
| } | ||
65 changes: 65 additions & 0 deletions
65
...est/java/io/micrometer/core/instrument/binder/jetty/JettyServerThreadPoolMetricsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /** | ||
| * Copyright 2017 Pivotal Software, Inc. | ||
| * <p> | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.core.instrument.binder.jetty; | ||
|
|
||
| import io.micrometer.core.instrument.MockClock; | ||
| import io.micrometer.core.instrument.Tag; | ||
| import io.micrometer.core.instrument.simple.SimpleConfig; | ||
| import io.micrometer.core.instrument.simple.SimpleMeterRegistry; | ||
| import org.eclipse.jetty.server.Connector; | ||
| import org.eclipse.jetty.server.Server; | ||
| import org.eclipse.jetty.server.ServerConnector; | ||
| import org.eclipse.jetty.util.thread.QueuedThreadPool; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Collections; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class JettyServerThreadPoolMetricsTest { | ||
| private SimpleMeterRegistry registry; | ||
| private Server server; | ||
|
|
||
| @BeforeEach | ||
| void setup() throws Exception { | ||
| registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock()); | ||
|
|
||
| Iterable<Tag> tags = Collections.singletonList(Tag.of("id", "0")); | ||
| QueuedThreadPool threadPool = new InstrumentedQueuedThreadPool(registry, tags); | ||
| threadPool.setMinThreads(32); | ||
| threadPool.setMaxThreads(100); | ||
| server = new Server(threadPool); | ||
| ServerConnector connector = new ServerConnector(server); | ||
| server.setConnectors(new Connector[] { connector }); | ||
| server.start(); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void teardown() throws Exception { | ||
| server.stop(); | ||
| } | ||
|
|
||
| @Test | ||
| void threadsMetrics() throws Exception { | ||
| assertThat(registry.get("jetty.threads.min").gauge().value()).isEqualTo(32.0); | ||
| assertThat(registry.get("jetty.threads.max").gauge().value()).isEqualTo(100.0); | ||
| assertThat(registry.get("jetty.threads.live").gauge().value()).isNotEqualTo(0.0); | ||
| assertThat(registry.get("jetty.threads.idle").gauge().value()).isNotEqualTo(0.0); | ||
| assertThat(registry.get("jetty.threads.busy").gauge().value()).isNotEqualTo(0.0); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this compare to the Tomcat equivalent? Wondering if
activeis a better name and how it differs from busy? Or is it merelyidle + busy?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided the name
livewith reference to JvmThreadMetrics.https://github.com/micrometer-metrics/micrometer/blob/v1.0.3/micrometer-core/src/main/java/io/micrometer/core/instrument/binder/jvm/JvmThreadMetrics.java#L57
For the meaning of the metric please refer to the Jetty's source.
https://github.com/eclipse/jetty.project/blob/jetty-9.4.8.v20171121/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java#L428-L455
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unified with Tomcat's metrics name.
(from
livetocurrent)https://github.com/micrometer-metrics/micrometer/blob/v1.0.3/micrometer-core/src/main/java/io/micrometer/core/instrument/binder/tomcat/TomcatMetrics.java#L89