在以前的文章中,我们介绍了Spring Micrometer和InfluxDB。 所以你要问我为什么普罗米修斯。
原因是Prometheus在InfluxDB的拉模型与推模型上进行操作。
这意味着,如果将千分尺与InfluxDB一起使用,则在将结果推送到数据库中时肯定会有一些开销,并且使InfluxDB数据库始终可用于处理所有请求是一个额外的痛苦点。
![](https://i-blog.csdnimg.cn/blog_migrate/3dd44a10b76d052cb2f28e1700fc4447.png)
那么,如果不是推送数据而是使用其他工具从应用程序中提取数据怎么办?
这是使用Prometheus可以获得的东西之一。 通过使用普罗米修斯,您可以从应用程序中请求数据,而不必接收数据。
因此,我们要做的是使用与第一个教程完全相同的项目。
所需的唯一更改应在applicaiton.yaml以及pom.xml上
我们将从pom.xml开始,并为prometheus添加千分尺二进制。
<? xml version = "1.0" encoding = "UTF-8" ?> < project xmlns = " http://maven.apache.org/POM/4.0.0 " xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " xsi:schemaLocation = " http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd " >
< modelVersion >4.0.0</ modelVersion >
< parent >
< groupId >org.springframework.boot</ groupId >
< artifactId >spring-boot-starter-parent</ artifactId >
< version >2.2.4.RELEASE</ version >
</ parent >
< groupId >com.gkatzioura</ groupId >
< artifactId >spring-prometheus-micrometer</ artifactId >
< version >1.0-SNAPSHOT</ version >
< properties >
< micrometer.version >1.3.2</ micrometer.version >
</ properties >
< build >
< defaultGoal >spring-boot:run</ defaultGoal >
< plugins >
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-compiler-plugin</ artifactId >
< configuration >
< source >8</ source >
< target >8</ target >
</ configuration >
</ plugin >
< plugin >
< groupId >org.springframework.boot</ groupId >
< artifactId >spring-boot-maven-plugin</ artifactId >
</ plugin >
</ plugins >
</ build >
< dependencies >
< dependency >
< groupId >org.springframework.boot</ groupId >
< artifactId >spring-boot-starter-webflux</ artifactId >
</ dependency >
< dependency >
< groupId >org.springframework.boot</ groupId >
< artifactId >spring-boot-starter-actuator</ artifactId >
</ dependency >
< dependency >
< groupId >io.micrometer</ groupId >
< artifactId >micrometer-core</ artifactId >
< version >${micrometer.version}</ version >
</ dependency >
< dependency >
< groupId >io.micrometer</ groupId >
< artifactId >micrometer-registry-prometheus</ artifactId >
< version >${micrometer.version}</ version >
</ dependency >
< dependency >
< groupId >org.projectlombok</ groupId >
< artifactId >lombok</ artifactId >
< version >1.18.12</ version >
< scope >provided</ scope >
</ dependency >
</ dependencies > </ project >
然后,我们将添加启用prometheus的application.yaml。
管理:
端点:
网络: 接触: 包括:普罗米修斯
现在,我们准备运行该应用程序。
> mvn spring-boot:run
如果我们尝试访问执行器,我们将看到普罗米修斯端点。
> curl http: //localhost:8080/actuator {
"_links" : {
"self" : {
"href" : " http://localhost:8080/actuator " ,
"templated" : false
},
"prometheus" : {
"href" : " http://localhost:8080/actuator/prometheus " ,
"templated" : false
}
} }
这个“ http:// localhost:8080 / actuator / prometheus&#8221 ; 是我们的prometheus服务器用来提取数据的端点。
因此,我们的prometheus服务器需要配置为访问该端点公开的这些数据。
在下一个博客中,我们将部署Prometheus并查看一些指标。