Spring Boot 1.5
Table of Contents(目录)
3.2. Client-side HTTP Instrumentation
8. Customizing individual metrics
1. Installing(安装)
Micrometer provides a legacy bridge to Spring Boot 1.5. To install the required dependency in Gradle:
千分尺为Spring Boot 1.5提供了一个传统的桥梁。 在Gradle中安装所需的依赖项:
In Gradle:
compile 'io.micrometer:micrometer-spring-legacy:latest.release'
Or in Maven:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-spring-legacy</artifactId>
<version>${micrometer.version}</version>
</dependency>
This dependency should be added alongside any registry implementations you want to use, e.g. micrometer-registry-prometheus
.
此依赖项应与您要使用的所有注册表实现一起添加,例如 千分尺注册普罗米修斯。
2. Configuring(配置)
Spring Boot auto-configures a composite meter registry 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. Spring Boot will also add any autoconfigured registries to the global static composite registry on the Metrics
class unless you explicitly tell it not to by setting:
Spring Boot自动配置组合仪表注册表,并为其在类路径上找到的每个受支持的实现向组合添加注册表。 在运行时类路径中具有对micrometer-registry- {system}的依赖足以让Spring Boot配置注册表。 Spring Boot还会将任何自动配置的注册表添加到Metrics类的全局静态复合注册表中,除非您通过设置明确指示不要这样做:
# true by default
management.metrics.use-global-registry=false
Leaving configuration of the global registry on enables you to collect metrics from libraries that use the static global registry to wire their metrics without doing anything further.
通过保留全局注册表的配置,您可以从使用静态全局注册表连接其指标的库中收集指标,而无需执行任何其他操作。
You can control whether a registry implementation is autoconfigured via a property, even if it is otherwise present on the classpath:
您可以控制是否通过属性自动配置注册表实现,即使该实现存在于类路径中也是如此:
# true by default
management.metrics.export.{system}.enabled=false
Optionally register any number of `MeterRegistryCustomizer`s to further configure the registry (such as applying common tags) before any meters are registered with the registry.
(可选)注册任意数量的“ MeterRegistryCustomizer”,以在将任何仪表注册到注册表之前进一步配置注册表(例如,应用通用标签)。
@SpringBootApplication
public class MyApplication {
@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:
您可以通过更具体地了解通用类型,将自定义项应用于特定的注册表实现:
@SpringBootApplication
public class MyApplication {
@Bean
MeterRegistryCustomizer<GraphiteMeterRegistry> graphiteMetricsNamingConvention() {
return registry -> registry.config().namingConvention(MY_CUSTOM_CONVENTION);
}
}
2.1. Meter Binders
Spring auto-configures the most commonly used binders.
Spring自动配置最常用的活页夹。
The JvmMemoryMetrics
binder will be automatically configured to record memory and buffer pool utilization. In the presence of Logback, the LogbackMetrics
binder will also be configured to record the number of events logged to Logback at each level. Lastly, UptimeMetrics
reports a gauge for uptime and a fixed gauge representing the application’s absolute start time.
JvmMemoryMetrics绑定程序将自动配置为记录内存和缓冲池利用率。在存在Logback的情况下,还将配置LogbackMetrics联编程序以记录每个级别记录到Logback的事件数。最后,UptimeMetrics会报告正常运行时间的量度和代表应用程序绝对启动时间的固定量度。
To register other binders with the registry, add them as `@Bean`s to your application context.
要在注册表中注册其他联编程序,请将它们作为@Bean添加到您的应用程序上下文中。
2.2. Atlas
Below is a list of the most common configuration properties you will want to change and their default values (from any property source, e.g. application.yml):
以下是您要更改的最常见配置属性及其默认值的列表(来自任何属性源,例如application.yml):
# The location of your Atlas server
management.metrics.export.atlas.uri=http://localhost:7101/api/v1/publish
# You will probably want disable Atlas publishing in a local development profile.
management.metrics.export.atlas.enabled=true # default is true
# The interval at which metrics are sent to Atlas. See Duration.parse for the expected format.
# The default is 1 minute.
management.metrics.export.atlas.step=PT1M
For a full list of configuration properties that can influence Atlas publishing, see com.netflix.spectator.atlas.AtlasConfig
.
有关可能影响Atlas发布的配置属性的完整列表,请参见com.netflix.spectator.atlas.AtlasConfig。
2.3. Prometheus
If Spring Boot Actuator is on the classpath, an actuator endpoint will be wired to /prometheus
by default that presents a Prometheus scrape with the appropriate format.
如果Spring Boot Actuator在类路径中,则默认情况下,会将一个执行器端点连接到/prometheus
,以正确的格式显示Prometheus抓取。
To add actuator if it isn’t already present on your classpath in Gradle:
要添加执行器(如果尚未在Gradle的类路径中添加执行器):
compile 'org.springframework.boot:spring-boot-starter-actuator'
Or in Maven:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Here is an example scrape_config
to add to prometheus.yml:
这是添加到prometheus.yml的示例scrape_config:
scrape_configs:
- job_name: 'spring'
metrics_path: '/prometheus'
static_configs:
- targets: ['HOST:PORT']
If you’d like the endpoint to use a different path, add the property:
如果您希望端点使用其他路径,请添加属性:
endpoints.prometheus.path=micrometheus
NOTE |
The endpoint is secured by default, so either include authentication in your Prometheus scrape endpoint or unsecure the prometheus endpoint with a property like management.security.enabled=false |
注意:
默认情况下,该端点是安全的,因此可以在Prometheus抓取端点中包括身份验证,或者使用诸如management.security.enabled = false之类的属性取消对Prometheus端点的安全保护 。
2.4. Datadog
The Datadog registry pushes metrics to datadoghq periodically. Below is a list of the most common configuration properties you will want to change and their default values (from any property source, e.g. application.yml
):
Datadog注册表会定期将指标推送到datadoghq。以下是您要更改的最常见配置属性及其默认值的列表(来自任何属性源,例如application.yml):
management.metrics.export.datadog.api-key=YOURKEY
# Needed to send meter-level metadata like descriptions and base units to Datadog, but not strictly required.
management.metrics.export.datadog.application-key=YOURKEY
# You will probably want disable Datadog publishing in a local development profile.
management.metrics.export.datadog.enabled=true # default is true
# The interval at which metrics are sent to Datadog. See Duration.parse for the expected format.
# The default is 10 seconds, which matches the Datadog Agent publishes at.
management.metrics.export.datadog.step=PT10S
For a full list of configuration properties that can