首页 > 其他分享 >kube-prometheus(prometheus-operator)监控(四):监控SpringBoot

kube-prometheus(prometheus-operator)监控(四):监控SpringBoot

时间:2022-11-25 15:59:39浏览次数:74  
标签:http name app auth prometheus vchain 监控 operator

准备工作

在工程的 pom 文件中添加两个依赖

文件路径:http://gitlab.vonechain.com:9002/haianSCF/vchain-framework/blob/dev/vchain-auth/pom.xml
增加的内容:

<!-- spring-boot-actuator依赖 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- prometheus依赖 -->
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

配置位置如截图:

添加对外暴露监控端点指标

文件路径:http://gitlab.vonechain.com:9002/haianSCF/vchain-framework/blob/dev/vchain-auth/src/main/resources/bootstrap.yml

添加内容:

management:
  endpoints:
    web:
      exposure:
        include:
        - 'prometheus'
        - 'health'
        - 'info'
    jmx:
      exposure:
        include: '*'
  metrics:
    tags:
      application: ${spring.application.name}
位置如图

添加完成后,重新编译打包,部署。部署完成后,ip:端口/actuator/prometheus 可以查看到监控数据。

我们微服务因走了gateway网关路由,所以地址为:http://网关ip:网关端口/路由服务名称/actuator/prometheus

http://10.10.246.39:31999/auth/actuator/prometheus

添加vchain-auth-Service

# cat vchain-authService.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    app: vchain-auth
    project: haian
  name: vchain-auth
  namespace: kube-system
spec:
  type: ClusterIP
  ports:
  - name: http
    port: 31999
    protocol: TCP
    targetPort: 31999
---
apiVersion: v1
kind: Endpoints
metadata:
  labels:
    app: vchain-auth
    project: haian
  name: vchain-auth
  namespace: kube-system
subsets:
- addresses:
  - ip: 10.10.246.39
  ports:
  - name: http
    port: 31999
    protocol: TCP

启动:kubectl create -f vchain-authService.yaml

添加serviceMonitor-vchain-auth

# cat prometheus-serviceMonitor-vchain-auth.yaml 
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    app: vchain-auth 
  name: vchain-auth
  namespace: monitoring
spec:
  endpoints:
  - interval: 30s
    path: /auth/actuator/prometheus
    port: http
  jobLabel: app
  namespaceSelector:
    matchNames:
    - kube-system
  selector:
    matchLabels:
      app: vchain-auth

启动:kubectl create -f prometheus-serviceMonitor-vchain-auth.yaml

检查:

配置grafana

在官方网站找到https://grafana.com/grafana/dashboards/4701-jvm-micrometer/
导入:4701

标签:http,name,app,auth,prometheus,vchain,监控,operator
From: https://www.cnblogs.com/zoujiaojiao/p/16925386.html

相关文章