diff --git a/src/components/DocRoot/index.js b/src/components/DocRoot/index.js index 749021e9..722adade 100644 --- a/src/components/DocRoot/index.js +++ b/src/components/DocRoot/index.js @@ -160,6 +160,9 @@ export default function DocRoot() { +
  • Support policy. Micrometer's support policy for releases. diff --git a/src/components/DocRoutes/index.js b/src/components/DocRoutes/index.js index d1cce7c3..7e135386 100644 --- a/src/components/DocRoutes/index.js +++ b/src/components/DocRoutes/index.js @@ -14,6 +14,7 @@ let docsOkHttpClient = require('!asciidoc-loader!../../docs/okhttpclient/index.a let docsConsoleReporter = require('!asciidoc-loader!../../docs/guide/console-reporter.adoc'); let docsHealthCheck = require('!asciidoc-loader!../../docs/guide/health-check.adoc'); let docsHttpSenderResilience4jRetry = require('!asciidoc-loader!../../docs/guide/http-sender-resilience4j-retry.adoc'); +let docsCustomMeterRegistry = require('!asciidoc-loader!../../docs/guide/custom-meter-registry.adoc'); let docsSupport = require('!asciidoc-loader!../../docs/support/index.adoc'); const systems = ['appOptics', 'atlas', 'azure-monitor', 'datadog', 'dynatrace', 'elastic', 'ganglia', 'graphite', 'humio', 'influx', 'instana', 'jmx', 'kairos', 'new-relic', 'prometheus', 'signalFx', 'stackdriver', 'statsD', 'wavefront']; @@ -67,6 +68,10 @@ export default function DocRoutes() { }/> + + + }/> + }/> diff --git a/src/docs/guide/custom-meter-registry.adoc b/src/docs/guide/custom-meter-registry.adoc new file mode 100644 index 00000000..d39dd0ff --- /dev/null +++ b/src/docs/guide/custom-meter-registry.adoc @@ -0,0 +1,72 @@ += Custom meter registry + +Micrometer supports popular meter registries out of the box, so please check them first. +For an existing meter registry, if you think that your requirements are generally useful, please consider creating an issue or PR against the Micrometer issue tracker. +For a non-existing meter registry, if it's widely-used, please consider creating an issue or PR for it. + +For some reasons such as unusual requirements, if you want to create your own custom meter registry, you can create it by extending one of base classes for meter registries: `MeterRegistry`, `PushMeterRegistry`, and `StepMeterRegistry`. + +Most common way is to extend `StepMeterRegistry`. +You can create your own custom `StepMeterRegistry` as follows. + +First, define your own meter registry configuration by extending `StepRegistryConfig` as follows: + +[source,java] +---- +public interface CustomRegistryConfig extends StepRegistryConfig { + + CustomRegistryConfig DEFAULT = k -> null; + + @Override + default String prefix() { + return "custom"; + } + +} +---- + +Second, define your own meter registry by extending `StepMeterRegistry` as follows: + +[source,java] +---- +public class CustomMeterRegistry extends StepMeterRegistry { + + public CustomMeterRegistry(CustomRegistryConfig config, Clock clock) { + super(config, clock); + + start(new NamedThreadFactory("custom-metrics-publisher")); + } + + @Override + protected void publish() { + getMeters().stream().forEach(meter -> System.out.println("Publishing " + meter.getId())); + } + + @Override + protected TimeUnit getBaseTimeUnit() { + return TimeUnit.MILLISECONDS; + } + +} +---- + +Finally, create the meter registry configuration and the meter registry. +If you are using Spring Boot, you can do as follows: + +[source,java] +---- +@Configuration +public class MetricsConfig { + + @Bean + public CustomRegistryConfig customRegistryConfig() { + return CustomRegistryConfig.DEFAULT; + } + + @Bean + public CustomMeterRegistry customMeterRegistry(CustomRegistryConfig customRegistryConfig, Clock clock) { + return new CustomMeterRegistry(customRegistryConfig, clock); + } + +} +----