我正在使用 spring boot 2.0 并在 POM 中添加了以下依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我的 application.yml 看起来像这样
management.endpoints.web.base-path = /manage
management.endpoints.web.exposure.include = "*"
endpoints.prometheus.enabled = true
当我访问 Prometheus 时
本地主机/管理/普罗米修斯
我能够看到所有指标。
接下来,我的目标是在 Prometheus UI 中查看上述指标。为此,我在 POM 中添加了以下依赖项
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
<version>${prometheus.version}</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>${prometheus.version}</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_servlet</artifactId>
<version>${prometheus.version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在 Prometheus UI 中查看指标的下一步是什么,最终目标是将 Prometheus 集成到 Grafana。
PS:我在 google 上进行了搜索,并尝试添加 prometheus.yml 并添加诸如 @EnablePrometheusEndpoint 之类的注释,因为所有文章都是旧的,因此没有任何效果。
编辑:如果 spring boot jar 托管在不同的主机(Azure/AWS)和 prometheus 服务器在不同的主机中,那么如何配置 prometheus.yml(metrics_path,targets)。
spring spring-boot spring-boot-actuator prometheus micrometer
public void manage()
{
double speed = getSpeedfromVehicle();
if(speed >=0 && speed <= 10)
{
System.out.println("Low Speed mode");
}
else if(speed > 10 && speed < 60)
{
System.out.println("Medium Speed Mode");
}
else if(speed >= 60)
{
System.out.println("High Speed Mode");
}
}
Run Code Online (Sandbox Code Playgroud)
当车辆开始移动时,我的管理方法被调用用于每个速度变化.如果速度保持在一个类别(0到10)中,我只需要打印一次输出语句,即使对于速度0到10,manage()被称为无限次,这也适用于其他速度范围.它也应该切换到其他速度范围,并且应该只打印一次速度范围.