spring-boot - Spring Boot 未在 promethes 端点上注册
问题描述
我正在尝试使用 spring boot 配置 Prometheus 和 Grafana。
@Configuration
@EnableSpringBootMetricsCollector
public class MetricsConfiguration {
/**
* Register common tags application instead of job. This application tag is
* needed for Grafana dashboard.
*
* @return registry with registered tags.
*/
@Value("${spring.application.name}")
private String applicationName;
@Value("${spring.profiles.active}")
private String environment;
@Bean
public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
return registry -> {
registry.config().commonTags("application", applicationName, "environment", environment)
.meterFilter(getDefualtConfig());
};
}
private MeterFilter getDefualtConfig() {
return new MeterFilter() {
@Override
public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
return DistributionStatisticConfig.builder().percentilesHistogram(true).percentiles(0.95, 0.99).build()
.merge(config);
}
};
}
}
在运行应用程序时,我可以在localhost:8080/prometheus url 上看到训练。
但同样我无法在localhost:9090/metrics url 上看到它是 Prometheus URL。
我已经在 prometheus.yml 中添加了配置并重新启动了 Prometheus。
- job_name: 'my-api'
scrape_interval: 10s
metrics_path: '/prometheus'
target_groups:
- targets: ['localhost:8080']
解决方案
在花了 2 个小时找到解决方案后,我们也对所有健康点使用基本身份验证问题是我没有在我的 proemtheus.yml 中设置基本身份验证
- job_name: 'my-api'
scrape_interval: 10s
metrics_path: '/prometheus'
target_groups:
- targets: ['localhost:8080']
basic_auth:
username: test
password: test
推荐阅读
- typescript - 从属性断言类型
- reactjs - 我的反应登录页面和路由器代码有问题
- angular - 如何为“mat-text-column”设置宽度
- php - 删除 ftp 名称中包含字符串的文件
- php - 即使文件夹有777的权限问题
- css - 在 CSS 中何时使用伪类以及何时使用伪元素选择器
- android - 如何使用 adb shell 命令播放视频?
- schema - Schema.org HTML 标记与 JSON-LD
- javascript - Javascript处理数组和对象
- elasticsearch - Elasticsearch:将新字段添加到具有基于现有字段的值的嵌套对象