0%

项目接入prometheus监控步骤

添加依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<exclusions>
<exclusion>
<artifactId>logback-core</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
<exclusion>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>

<!-- https://mvnrepository.com/artifact/io.micrometer/micrometer-registry-prometheus -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.8.5</version>
</dependency>

工程的 Apollo 添加配置并发布

命名空间:spring.application

1
2
3
4
#prometheus相关-actuator暴露接口
management.endpoints.web.exposure.include = metrics,prometheus
# prometheus相关-Whether Tomcat's MBean Registry should be enabled
server.tomcat.mbeanregistry.enabled = true

启动项目

访问 http://localhost:8080/actuator/prometheus确认生效

k8s 工程添加参数并发布

1
2
3
4
annotations:
prometheus.io/path: /actuator/prometheus
prometheus.io/port: "8080"
prometheus.io/scrape: "true"

进入 grafana 查看监控