From 25ff82f1d76dad7e12cbb7213c5ec8a68f2b6a5a Mon Sep 17 00:00:00 2001 From: Jon Schneider Date: Fri, 2 Mar 2018 13:48:17 -0600 Subject: [PATCH] Improve docs on custom metrics See gh-12324 --- .../asciidoc/production-ready-features.adoc | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc index e2a3fb69d41..470af18015c 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc @@ -1749,9 +1749,25 @@ factories with a metric named `rabbitmq`. [[production-ready-metrics-custom]] === Registering custom metrics -To register custom metrics, create a `MeterBinder` bean. By default, all `MeterBinder` -beans will be automatically applied to the micrometer `MeterRegistry.Config`. +To register custom metrics, inject `MeterRegistry` into your component: +[source,java,indent=0] +---- +class Dictionary { + private List words = new CopyOnWriteArrayList<>(); + + public MyComponent(MeterRegistry registry) { + registry.gaugeCollectionSize("dictionary.size", Tags.empty(), words); + } + + ... +} +---- + +If you find that you repeatedly instrument a suite of metrics across components or +applications, you may encapsulate this suite in a `MeterBinder` implementation. By +default, metrics from all `MeterBinder` beans will be automatically bound to +the Spring-managed `MeterRegistry`. [[production-ready-metrics-per-meter-properties]]