Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
2b11ee43
Commit
2b11ee43
authored
Oct 13, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auto-configure binding of Micrometer's JettyServerThreadPoolMetrics
Closes gh-14591
parent
6199af6c
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
335 additions
and
0 deletions
+335
-0
pom.xml
...g-boot-project/spring-boot-actuator-autoconfigure/pom.xml
+10
-0
JettyMetricsAutoConfiguration.java
...gure/metrics/web/jetty/JettyMetricsAutoConfiguration.java
+52
-0
package-info.java
...actuate/autoconfigure/metrics/web/jetty/package-info.java
+20
-0
spring.factories
...utoconfigure/src/main/resources/META-INF/spring.factories
+1
-0
JettyMetricsAutoConfigurationTests.java
...metrics/web/jetty/JettyMetricsAutoConfigurationTests.java
+149
-0
pom.xml
spring-boot-project/spring-boot-actuator/pom.xml
+5
-0
JettyServerThreadPoolMetricsBinder.java
...metrics/web/jetty/JettyServerThreadPoolMetricsBinder.java
+78
-0
package-info.java
...ramework/boot/actuate/metrics/web/jetty/package-info.java
+20
-0
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/pom.xml
View file @
2b11ee43
...
...
@@ -248,6 +248,11 @@
<artifactId>
elasticsearch
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.eclipse.jetty
</groupId>
<artifactId>
jetty-server
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.flywaydb
</groupId>
<artifactId>
flyway-core
</artifactId>
...
...
@@ -470,6 +475,11 @@
<artifactId>
aspectjrt
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.eclipse.jetty
</groupId>
<artifactId>
jetty-webapp
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.hsqldb
</groupId>
<artifactId>
hsqldb
</artifactId>
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/jetty/JettyMetricsAutoConfiguration.java
0 → 100644
View file @
2b11ee43
/*
* Copyright 2012-2018 the original author or authors.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
.
web
.
jetty
;
import
io.micrometer.core.instrument.MeterRegistry
;
import
io.micrometer.core.instrument.binder.jetty.JettyServerThreadPoolMetrics
;
import
org.eclipse.jetty.server.Server
;
import
org.springframework.boot.actuate.metrics.web.jetty.JettyServerThreadPoolMetricsBinder
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Jetty metrics.
*
* @author Andy Wilkinson
* @since 2.1.0
*/
@Configuration
@ConditionalOnWebApplication
@ConditionalOnClass
({
JettyServerThreadPoolMetrics
.
class
,
Server
.
class
})
public
class
JettyMetricsAutoConfiguration
{
@Bean
@ConditionalOnBean
(
MeterRegistry
.
class
)
@ConditionalOnMissingBean
({
JettyServerThreadPoolMetrics
.
class
,
JettyServerThreadPoolMetricsBinder
.
class
})
public
JettyServerThreadPoolMetricsBinder
jettyServerThreadPoolMetricsBinder
(
MeterRegistry
meterRegistry
)
{
return
new
JettyServerThreadPoolMetricsBinder
(
meterRegistry
);
}
}
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/jetty/package-info.java
0 → 100644
View file @
2b11ee43
/*
* Copyright 2012-2018 the original author or authors.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
/**
* Auto-configuration for Jetty actuator metrics.
*/
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
.
web
.
jetty
;
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories
View file @
2b11ee43
...
...
@@ -64,6 +64,7 @@ org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetric
org.springframework.boot.actuate.autoconfigure.metrics.jersey.JerseyServerMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.orm.jpa.HibernateMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.web.client.HttpClientMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.web.jetty.JettyMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.web.reactive.WebFluxMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.web.servlet.WebMvcMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.web.tomcat.TomcatMetricsAutoConfiguration,\
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/jetty/JettyMetricsAutoConfigurationTests.java
0 → 100644
View file @
2b11ee43
/*
* Copyright 2012-2018 the original author or authors.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
.
web
.
jetty
;
import
io.micrometer.core.instrument.MeterRegistry
;
import
io.micrometer.core.instrument.simple.SimpleMeterRegistry
;
import
org.junit.Test
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.actuate.metrics.web.jetty.JettyServerThreadPoolMetricsBinder
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration
;
import
org.springframework.boot.context.event.ApplicationStartedEvent
;
import
org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner
;
import
org.springframework.boot.test.context.runner.WebApplicationContextRunner
;
import
org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory
;
import
org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory
;
import
org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext
;
import
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.server.reactive.HttpHandler
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
* Tests for {@link JettyMetricsAutoConfiguration}.
*
* @author Andy Wilkinson
*/
public
class
JettyMetricsAutoConfigurationTests
{
@Test
public
void
autoConfiguresThreadPoolMetricsWithEmbeddedServletJetty
()
{
new
WebApplicationContextRunner
(
AnnotationConfigServletWebServerApplicationContext:
:
new
)
.
withConfiguration
(
AutoConfigurations
.
of
(
JettyMetricsAutoConfiguration
.
class
,
ServletWebServerFactoryAutoConfiguration
.
class
))
.
withUserConfiguration
(
ServletWebServerConfiguration
.
class
,
MeterRegistryConfiguration
.
class
)
.
run
((
context
)
->
{
context
.
publishEvent
(
new
ApplicationStartedEvent
(
new
SpringApplication
(),
null
,
context
.
getSourceApplicationContext
()));
assertThat
(
context
).
hasSingleBean
(
JettyServerThreadPoolMetricsBinder
.
class
);
SimpleMeterRegistry
registry
=
context
.
getBean
(
SimpleMeterRegistry
.
class
);
assertThat
(
registry
.
find
(
"jetty.threads.config.min"
).
meter
())
.
isNotNull
();
});
}
@Test
public
void
autoConfiguresThreadPoolMetricsWithEmbeddedReactiveJetty
()
{
new
ReactiveWebApplicationContextRunner
(
AnnotationConfigReactiveWebServerApplicationContext:
:
new
)
.
withConfiguration
(
AutoConfigurations
.
of
(
JettyMetricsAutoConfiguration
.
class
,
ReactiveWebServerFactoryAutoConfiguration
.
class
))
.
withUserConfiguration
(
ReactiveWebServerConfiguration
.
class
,
MeterRegistryConfiguration
.
class
)
.
run
((
context
)
->
{
context
.
publishEvent
(
new
ApplicationStartedEvent
(
new
SpringApplication
(),
null
,
context
.
getSourceApplicationContext
()));
SimpleMeterRegistry
registry
=
context
.
getBean
(
SimpleMeterRegistry
.
class
);
assertThat
(
registry
.
find
(
"jetty.threads.config.min"
).
meter
())
.
isNotNull
();
});
}
@Test
public
void
allowsCustomJettyServerThreadPoolMetricsBinderToBeUsed
()
{
new
WebApplicationContextRunner
()
.
withConfiguration
(
AutoConfigurations
.
of
(
JettyMetricsAutoConfiguration
.
class
))
.
withUserConfiguration
(
CustomJettyServerThreadPoolMetricsBinder
.
class
,
MeterRegistryConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
)
.
hasSingleBean
(
JettyServerThreadPoolMetricsBinder
.
class
)
.
hasBean
(
"customJettyServerThreadPoolMetricsBinder"
));
}
@Configuration
static
class
MeterRegistryConfiguration
{
@Bean
public
SimpleMeterRegistry
meterRegistry
()
{
return
new
SimpleMeterRegistry
();
}
}
@Configuration
static
class
ServletWebServerConfiguration
{
@Bean
public
JettyServletWebServerFactory
jettyFactory
()
{
return
new
JettyServletWebServerFactory
(
0
);
}
}
@Configuration
static
class
ReactiveWebServerConfiguration
{
@Bean
public
JettyReactiveWebServerFactory
jettyFactory
()
{
return
new
JettyReactiveWebServerFactory
(
0
);
}
@Bean
public
HttpHandler
httpHandler
()
{
return
mock
(
HttpHandler
.
class
);
}
}
@Configuration
static
class
CustomJettyServerThreadPoolMetricsBinder
{
@Bean
public
JettyServerThreadPoolMetricsBinder
customJettyServerThreadPoolMetricsBinder
(
MeterRegistry
meterRegistry
)
{
return
new
JettyServerThreadPoolMetricsBinder
(
meterRegistry
);
}
}
}
spring-boot-project/spring-boot-actuator/pom.xml
View file @
2b11ee43
...
...
@@ -113,6 +113,11 @@
<artifactId>
aspectjweaver
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.eclipse.jetty
</groupId>
<artifactId>
jetty-server
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.elasticsearch
</groupId>
<artifactId>
elasticsearch
</artifactId>
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/jetty/JettyServerThreadPoolMetricsBinder.java
0 → 100644
View file @
2b11ee43
/*
* Copyright 2012-2018 the original author or authors.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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
org
.
springframework
.
boot
.
actuate
.
metrics
.
web
.
jetty
;
import
java.util.Collections
;
import
io.micrometer.core.instrument.MeterRegistry
;
import
io.micrometer.core.instrument.Tag
;
import
io.micrometer.core.instrument.binder.jetty.JettyServerThreadPoolMetrics
;
import
org.eclipse.jetty.util.thread.ThreadPool
;
import
org.springframework.boot.context.event.ApplicationStartedEvent
;
import
org.springframework.boot.web.context.WebServerApplicationContext
;
import
org.springframework.boot.web.embedded.jetty.JettyWebServer
;
import
org.springframework.boot.web.server.WebServer
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationListener
;
/**
* Binds {@link JettyServerThreadPoolMetrics} in response to the
* {@link ApplicationStartedEvent}.
*
* @author Andy Wilkinson
* @since 2.1.0
*/
public
class
JettyServerThreadPoolMetricsBinder
implements
ApplicationListener
<
ApplicationStartedEvent
>
{
private
final
MeterRegistry
meterRegistry
;
private
final
Iterable
<
Tag
>
tags
;
public
JettyServerThreadPoolMetricsBinder
(
MeterRegistry
meterRegistry
)
{
this
(
meterRegistry
,
Collections
.
emptyList
());
}
public
JettyServerThreadPoolMetricsBinder
(
MeterRegistry
meterRegistry
,
Iterable
<
Tag
>
tags
)
{
this
.
meterRegistry
=
meterRegistry
;
this
.
tags
=
tags
;
}
@Override
public
void
onApplicationEvent
(
ApplicationStartedEvent
event
)
{
ApplicationContext
applicationContext
=
event
.
getApplicationContext
();
ThreadPool
threadPool
=
findThreadPool
(
applicationContext
);
if
(
threadPool
!=
null
)
{
new
JettyServerThreadPoolMetrics
(
threadPool
,
this
.
tags
)
.
bindTo
(
this
.
meterRegistry
);
}
}
private
ThreadPool
findThreadPool
(
ApplicationContext
applicationContext
)
{
if
(
applicationContext
instanceof
WebServerApplicationContext
)
{
WebServer
webServer
=
((
WebServerApplicationContext
)
applicationContext
)
.
getWebServer
();
if
(
webServer
instanceof
JettyWebServer
)
{
return
((
JettyWebServer
)
webServer
).
getServer
().
getThreadPool
();
}
}
return
null
;
}
}
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/web/jetty/package-info.java
0 → 100644
View file @
2b11ee43
/*
* Copyright 2012-2017 the original author or authors.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
/**
* Actuator support for Jetty metrics.
*/
package
org
.
springframework
.
boot
.
actuate
.
metrics
.
web
.
jetty
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment