Spring Boot 2.0 HTTP request metrics.

Spring Boot auto-configures a composite MeterRegistry and adds a registry to the composite for each of the supported implementations that it finds on the classpath. Having a dependency on micrometer-registry-{system} in your runtime classpath is enough for Spring Boot to configure the registry.
Most registries share common features. For instance, you can disable a particular registry even if the Micrometer registry implementation is on the classpath. For instance, to disable Datadog:
management.metrics.export.datadog.enabled=false
Spring Boot will also add any auto-configured registries to the global static composite registry on the Metrics class unless you explicitly tell it not to:
management.metrics.use-global-registry=false
You can register any number of MeterRegistryCustomizer beans to further configure the registry, such as applying common tags, before any meters are registered with the registry:
@Bean
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
 return registry -> registry.config().commonTags("region", "us-east-1");
}
You can apply customizations to particular registry implementations by being more specific about the generic type:
@Bean
MeterRegistryCustomizer<GraphiteMeterRegistry> graphiteMetricsNamingConvention() {
 return registry -> registry.config().namingConvention(MY_CUSTOM_CONVENTION);
}
With that setup in place you can inject MeterRegistry in your components and register metrics:
@Component
public class SampleBean {

 private final Counter counter;

 public SampleBean(MeterRegistry registry) {
  this.counter = registry.counter("received.messages");
 }

 public void handleMessage(String message) {
  this.counter.increment();
  // handle message implementation
 }

}
Spring Boot also configures built-in instrumentation (i.e. MeterBinder implementations) that you can control via configuration or dedicated annotation markers.


Supported monitoring systems

54.2.1 Atlas

By default, metrics are exported to Atlas running on your local machine. The location of the Atlas server to use can be provided using:
management.metrics.export.atlas.uri=http://atlas.example.com:7101/api/v1/publish

54.2.2 Datadog

Datadog registry pushes metrics to datadoghq periodically. To export metrics to Datadog, your API key must be provided:
management.metrics.export.datadog.api-key=YOUR_KEY
You can also change the interval at which metrics are sent to Datadog:
management.metrics.export.datadog.steps=30s

54.2.3 Ganglia

By default, metrics are exported to Ganglia running on your local machine. The Ganglia server host and port to use can be provided using:
management.metrics.export.ganglia.host=ganglia.example.com
management.metrics.export.ganglia.post=9649

54.2.4 Graphite

By default, metrics are exported to Graphite running on your local machine. The Graphite server host and port to use can be provided using:
management.metrics.export.graphite.host=graphite.example.com
management.metrics.export.graphite.post=9004

54.2.5 Influx

By default, metrics are exported to Influx running on your local machine. The location of the Influx server to use can be provided using:
management.metrics.export.influx.uri=http://influx.example.com:8086

54.2.6 JMX

Micrometer provides a hierarchical mapping to JMX, primarily as a cheap and portable way to view metrics locally. Spring Boot provides a default HierarchicalNameMapper that governs how a dimensional meter id is mapped to flat hierarchical names.

Source:
https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html

Kommentare

Beliebte Posts