跳到主要内容

Micrometer Azure Monitor

DeepSeek V3 中英对照 Azure Monitor Micrometer Azure Monitor

Azure Monitor 是一个具有内置仪表板功能的维度时间序列 SaaS 服务。

1. 安装 micrometer-registry-azure-monitor

建议使用 Micrometer(或您的框架,如果有的话)提供的 BOM,您可以在此处查看如何配置它 here。以下示例假设您正在使用 BOM。

1.1. Gradle

配置 好 BOM 之后,添加以下依赖项:

implementation 'io.micrometer:micrometer-registry-azure-monitor'
groovy
备注

由于该依赖项的版本由 BOM 定义,因此不需要指定版本。

1.2. Maven

配置 了 BOM 之后,添加以下依赖:

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-azure-monitor</artifactId>
</dependency>
xml
备注

由于版本由 BOM 定义,因此此依赖项不需要版本。

2. 配置

以下示例配置了一个 Micrometer Azure Monitor:

AzureMonitorConfig azureMonitorConfig = new AzureMonitorConfig() {
@Override
public String instrumentationKey() {
return MY_KEY;
}

@Override
public String get(String key) {
return null;
}
};
MeterRegistry registry = new AzureMonitorMeterRegistry(azureMonitorConfig, Clock.SYSTEM);
java

AzureMonitorConfig 是一个带有一组默认方法的接口。如果在 get(String k) 的实现中,你将其绑定到一个属性源而不是返回 null,那么你可以覆盖默认配置。例如,Micrometer 的 Spring Boot 支持将前缀为 management.metrics.export.azure-monitor 的属性直接绑定到 AzureMonitorConfig

management.metrics.export.azure-monitor:
instrumentation-key: YOURKEY

# You will probably want disable Azure Monitor publishing in a local development profile.
enabled: true

# The interval at which metrics are sent to Azure Monitor. The default is 1 minute.
step: 1m
yml