K8S Prometheus Springboot Actuator ServiceMonitor配置

本文介绍了如何在Springboot项目中集成Actuator进行监控,包括添加依赖、配置Management端、设置ServiceMonitor以自动暴露监控数据,并展示了如何在Grafana中创建SpringBoot仪表板。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值