用于展示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

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

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐