用于展示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-exportername: prometheus-prometheus-actuator-yourapp-exporternamespace: develop
spec:endpoints:- interval: 60sport: yourapp-ports # 端口名称,与你的app svc中配置的ports一致path: /yourappcontext-path/actuator/prometheus #actuator的监控数据路径jobLabel: jobLabelnamespaceSelector: # 标签匹配 Service 所在的命名空间matchNames:- developselector: # 标签匹配 ServicematchLabels:app: yourapp-svc
应用
kubectl apply -f serviceMonitor-yourapp.yaml
检查Prometheus配置
找到yourapp看看配置是否正确
Configuration
Targets
Grafana Dashboard
Dashboards | Grafana Labs
SpringBoot APM Dashboard 12900
参考:
Prometheus Operator 使用ServiceMonitor管理监控配置_prometheus servicemonitor-CSDN博客
prometheus监控hikari连接池-CSDN博客
endpoints - path配置
Monitoring Spring Boot Microservices with Prometheus and Grafana
Prometheus: monitoring a custom Service using ServiceMonitor and PrometheusRule | Fabian Lee : Software Engineer