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
73e1dd87
Commit
73e1dd87
authored
Apr 06, 2021
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Auto-configure Mongo metrics"
See gh-23990
parent
81c18214
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
150 additions
and
21 deletions
+150
-21
MongoMetricsAutoConfiguration.java
...onfigure/metrics/mongo/MongoMetricsAutoConfiguration.java
+4
-2
package-info.java
...oot/actuate/autoconfigure/metrics/mongo/package-info.java
+20
-0
spring.factories
...utoconfigure/src/main/resources/META-INF/spring.factories
+1
-1
MongoMetricsAutoConfigurationTests.java
...ure/metrics/mongo/MongoMetricsAutoConfigurationTests.java
+1
-1
build.gradle
spring-boot-project/spring-boot-docs/build.gradle
+1
-0
production-ready-features.adoc
...oot-docs/src/docs/asciidoc/production-ready-features.adoc
+13
-17
SampleCommandTagsProviderConfiguration.java
...metrics/mongo/SampleCommandTagsProviderConfiguration.java
+45
-0
SampleConnectionPoolTagsProviderConfiguration.java
.../mongo/SampleConnectionPoolTagsProviderConfiguration.java
+45
-0
package-info.java
...s/productionreadyfeatures/metrics/mongo/package-info.java
+20
-0
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MongoMetricsAutoConfiguration.java
→
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/
mongo/
MongoMetricsAutoConfiguration.java
View file @
73e1dd87
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
;
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
.
mongo
;
import
com.mongodb.MongoClientSettings
;
import
io.micrometer.core.instrument.MeterRegistry
;
...
...
@@ -25,6 +25,8 @@ import io.micrometer.core.instrument.binder.mongodb.MongoMetricsCommandTagsProvi
import
io.micrometer.core.instrument.binder.mongodb.MongoMetricsConnectionPoolListener
;
import
io.micrometer.core.instrument.binder.mongodb.MongoMetricsConnectionPoolTagsProvider
;
import
org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/mongo/package-info.java
0 → 100644
View file @
73e1dd87
/*
* Copyright 2012-2021 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
*
* https://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 Mongo metrics.
*/
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
.
mongo
;
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/spring.factories
View file @
73e1dd87
...
...
@@ -46,7 +46,6 @@ org.springframework.boot.actuate.autoconfigure.metrics.Log4J2MetricsAutoConfigur
org.springframework.boot.actuate.autoconfigure.metrics.LogbackMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.MetricsEndpointAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.MongoMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.SystemMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.amqp.RabbitMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.cache.CacheMetricsAutoConfiguration,\
...
...
@@ -71,6 +70,7 @@ org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront.Wavefron
org.springframework.boot.actuate.autoconfigure.metrics.integration.IntegrationMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.jersey.JerseyServerMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.mongo.MongoMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.orm.jpa.HibernateMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.r2dbc.ConnectionPoolMetricsAutoConfiguration,\
org.springframework.boot.actuate.autoconfigure.metrics.web.client.HttpClientMetricsAutoConfiguration,\
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MongoMetricsAutoConfigurationTests.java
→
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/
mongo/
MongoMetricsAutoConfigurationTests.java
View file @
73e1dd87
...
...
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
;
package
org
.
springframework
.
boot
.
actuate
.
autoconfigure
.
metrics
.
mongo
;
import
java.util.List
;
...
...
spring-boot-project/spring-boot-docs/build.gradle
View file @
73e1dd87
...
...
@@ -80,6 +80,7 @@ dependencies {
implementation
(
"org.glassfish.jersey.core:jersey-server"
)
implementation
(
"org.hibernate:hibernate-jcache"
)
implementation
(
"org.jooq:jooq"
)
implementation
(
"org.mongodb:mongodb-driver-sync"
)
implementation
(
"org.slf4j:jul-to-slf4j"
)
implementation
(
"org.springframework:spring-jdbc"
)
implementation
(
"org.springframework:spring-test"
)
...
...
spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc
View file @
73e1dd87
...
...
@@ -2400,8 +2400,11 @@ For more details refer to {spring-kafka-docs}#micrometer-native[Micrometer Nativ
[[production-ready-metrics-mongodb]]
==== MongoDB Metrics
[[production-ready-metrics-mongodb-command]]
===== Command Metrics
Auto-configuration will register a `MongoMetricsCommandListener`
for the auto-configured MongoClient
.
Auto-configuration will register a `MongoMetricsCommandListener`
with the auto-configured `MongoClient`
.
A timer metric with the name `mongodb.driver.commands` is created for each command issued to the underlying MongoDB driver.
Each metric is tagged with the following information by default:
...
...
@@ -2421,17 +2424,14 @@ Each metric is tagged with the following information by default:
| Outcome of the command - one of (`SUCCESS`, `FAILED`)
|===
You can replace the default metric tags by providing
a `MongoMetricsCommandTagsProvider` bean, as shown in the following example:
To replace the default metric tags, define
a `MongoMetricsCommandTagsProvider` bean, as shown in the following example:
[source,java,
pending-extract=true,
indent=0]
[source,java,indent=0]
----
@Bean
MongoMetricsCommandTagsProvider mongoMetricsCommandTagsProvider() {
return new MyCustomMongoMetricsCommandTagsProvider();
}
include::{include-productionreadyfeatures}/metrics/mongo/SampleCommandTagsProviderConfiguration.java[tag=*]
----
If you want to disable the auto-configured command metrics, you can
set the following property:
To disable the auto-configured command metrics,
set the following property:
[source,yaml,indent=0,configprops,configblocks]
----
...
...
@@ -2443,7 +2443,7 @@ If you want to disable the auto-configured command metrics, you can set the foll
----
===== Connection Pool Metrics
Auto-configuration will register a `MongoMetricsConnectionPoolListener`
for the auto-configured MongoClient
.
Auto-configuration will register a `MongoMetricsConnectionPoolListener`
with the auto-configured `MongoClient`
.
The following gauge metrics are created for the connection pool:
...
...
@@ -2462,18 +2462,14 @@ Each metric is tagged with the following information by default:
| Address of the server the connection pool corresponds to
|===
You can replace the default metric tags by providing
a `MongoMetricsConnectionPoolTagsProvider` bean, as shown in the following example:
To replace the default metric tags, define
a `MongoMetricsConnectionPoolTagsProvider` bean, as shown in the following example:
[source,java,
pending-extract=true,
indent=0]
[source,java,indent=0]
----
@Bean
@ConditionalOnMissingBean
MongoMetricsConnectionPoolTagsProvider mongoMetricsConnectionPoolTagsProvider() {
return new DefaultMongoMetricsConnectionPoolTagsProvider();
}
include::{include-productionreadyfeatures}/metrics/mongo/SampleConnectionPoolTagsProviderConfiguration.java[tag=*]
----
If you want to disable the auto-configured connection pool metrics, you can
set the following property:
To disable the auto-configured connection pool metrics,
set the following property:
[source,yaml,indent=0,configprops,configblocks]
----
...
...
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/mongo/SampleCommandTagsProviderConfiguration.java
0 → 100644
View file @
73e1dd87
/*
* Copyright 2012-2021 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
*
* https://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
.
docs
.
productionreadyfeatures
.
metrics
.
mongo
;
// tag::code[]
import
com.mongodb.event.CommandEvent
;
import
io.micrometer.core.instrument.Tag
;
import
io.micrometer.core.instrument.binder.mongodb.MongoMetricsCommandTagsProvider
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
(
proxyBeanMethods
=
false
)
public
class
SampleCommandTagsProviderConfiguration
{
@Bean
MongoMetricsCommandTagsProvider
customCommandTagsProvider
()
{
return
new
CustomCommandTagsProvider
();
}
}
// end::code[]
class
CustomCommandTagsProvider
implements
MongoMetricsCommandTagsProvider
{
@Override
public
Iterable
<
Tag
>
commandTags
(
CommandEvent
commandEvent
)
{
return
java
.
util
.
Collections
.
emptyList
();
}
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/mongo/SampleConnectionPoolTagsProviderConfiguration.java
0 → 100644
View file @
73e1dd87
/*
* Copyright 2012-2021 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
*
* https://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
.
docs
.
productionreadyfeatures
.
metrics
.
mongo
;
// tag::code[]
import
com.mongodb.event.ConnectionPoolCreatedEvent
;
import
io.micrometer.core.instrument.Tag
;
import
io.micrometer.core.instrument.binder.mongodb.MongoMetricsConnectionPoolTagsProvider
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
(
proxyBeanMethods
=
false
)
public
class
SampleConnectionPoolTagsProviderConfiguration
{
@Bean
MongoMetricsConnectionPoolTagsProvider
customConnectionPoolTagsProvider
()
{
return
new
CustomConnectionPoolTagsProvider
();
}
}
// end::code[]
class
CustomConnectionPoolTagsProvider
implements
MongoMetricsConnectionPoolTagsProvider
{
@Override
public
Iterable
<
Tag
>
connectionPoolTags
(
ConnectionPoolCreatedEvent
event
)
{
return
java
.
util
.
Collections
.
emptyList
();
}
}
spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/productionreadyfeatures/metrics/mongo/package-info.java
0 → 100644
View file @
73e1dd87
/*
* Copyright 2012-2021 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
*
* https://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.
*/
/**
* Examples for the "Production Ready Features - Metrics - MongoDB" section.
*/
package
org
.
springframework
.
boot
.
docs
.
productionreadyfeatures
.
metrics
.
mongo
;
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