带Prometheus的Spring Boot和测微表第4部分:基础项目

在以前的文章中,我们介绍了Spring Micrometer和InfluxDB。 所以你要问我为什么普罗米修斯。
原因是Prometheus在InfluxDB的拉模型与推模型上进行操作。

这意味着,如果将千分尺与InfluxDB一起使用,则在将结果推送到数据库中时肯定会有一些开销,并且使InfluxDB数据库始终可用于处理所有请求是一个额外的痛苦点。

那么,如果不是推送数据而是使用其他工具从应用程序中提取数据怎么办?
这是使用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并查看一些指标。

翻译自: https://www.javacodegeeks.com/2020/05/spring-boot-and-micrometer-with-prometheus-part-4-the-base-project.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值