K8S Prometheus Springboot Actuator ServiceMonitor配置
用于展示Springboot Actuator监控内容。
·
用于展示Springboot Actuator监控内容
引入Springboot相关的监控配置包
Springboot 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>
配置管理端,暴露Metrics Exporter
bootstrap.yml
management:
endpoints:
web:
exposure:
include: '*'
metrics:
tags:
application: ${spring.application.name}
region: my-region
配置获取监控数据的任务
需要在prometheus中配置获取监控数据的任务,在K8S中直接使用ServiceMonitor即可
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
jobLabel: actuator-yourapp-exporter
name: prometheus-prometheus-actuator-yourapp-exporter
namespace: develop
spec:
endpoints:
- interval: 60s
port: yourapp-ports # 端口名称,与你的app svc中配置的ports一致
path: /yourappcontext-path/actuator/prometheus #actuator的监控数据路径
jobLabel: jobLabel
namespaceSelector: # 标签匹配 Service 所在的命名空间
matchNames:
- develop
selector: # 标签匹配 Service
matchLabels:
app: yourapp-svc
应用
kubectl apply -f serviceMonitor-yourapp.yaml
检查Prometheus配置
找到yourapp看看配置是否正确
Configuration
Targets
Grafana Dashboard
SpringBoot APM Dashboard 12900
参考:
Prometheus Operator 使用ServiceMonitor管理监控配置_prometheus servicemonitor-CSDN博客
endpoints - path配置
Monitoring Spring Boot Microservices with Prometheus and Grafana
更多推荐
已为社区贡献17条内容
所有评论(0)