• prometheus监控java应用的jvm指标


    k8s环境中我们有很多的java应用,需要监控其性能我们可以通过集成jmx的客户端,然后通过promethues的自动发现来实现监控数据的获取。
    promethues的部署he相关配置可参考:promethues部署

    准备jmx的客户端和配置文件

    jmx_prometheus_javaagent-0.17.2.jar(版本自定义,可以直接打包到镜像里)

    使用configmap挂载jmx-config.yaml
    
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: prometheus-jmx-config
      namespace: monitor
    data:
      prometheus-jmx-config.yaml: |
        lowercaseOutputLabelNames: true
        lowercaseOutputName: true
        whitelistObjectNames: ["java.lang:type=OperatingSystem"]
        blacklistObjectNames: []
        rules:
          - pattern: 'java.lang<>(committed_virtual_memory|free_physical_memory|free_swap_space|total_physical_memory|total_swap_space)_size:'
            name: os_$1_bytes
            type: GAUGE
            attrNameSnakeCase: true
          - pattern: 'java.lang<>((?!process_cpu_time)\w+):'
            name: os_$1
            type: GAUGE
            attrNameSnakeCase: true
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    部署应用(tomcat为例)

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: tomcat
      namespace: monitor
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: tomcat
      template:
        metadata:
          labels:
            app: tomcat
        spec:
          containers:
          - name: tomcat
            image: tomcat:jdk8-openjdk-slim
            env:
            - name: JAVA_OPTS
              value: "-javaagent:/jmx_prometheus_javaagent-0.17.2.jar=8088:/jmx/jmx-config.yaml"  **# (添加的启动命令参数)**
            resources:
              requests:
                cpu: 300m
                memory: 512Mi
              limits:
                cpu: 500m
                memory: 1024Mi
            volumeMounts:
            - mountPath: "/jmx_prometheus_javaagent-0.17.2.jar"    **#(将客户端挂载到容器)**
              name: jmx-prometheus-javaagent
            - mountPath: "/jmx"
              name: prometheus-jmx-config       **#(通过configmap挂载配置文件)**
          volumes:
          - name: jmx-prometheus-javaagent
            hostPath:
              path: /data/k8s_yaml/jvm/jmx_prometheus_javaagent-0.17.2.jar  **# (使用的是挂在本地路径)**
          - configMap: 
              name: prometheus-jmx-config
            name: prometheus-jmx-config
          nodeSelector:
            kubernetes.io/hostname: 10.1.40.121
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42

    服务的service

    apiVersion: v1
    kind: Service
    metadata:
      name: tomcat
      namespace: monitor
      labels:
        app: tomcat
      annotations:
        prometheus.io/port: "8088"     **#(jmx监听的端口)**
        prometheus.io/jvm: "true"
    spec:
      type: NodePort
      selector:
        app: tomcat
      ports:
      - name: http
        port: 8080
        protocol: TCP
      - name: jmx-metrics
        port: 8088
        protocol: TCP
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    jvm面板 10519参考

  • 相关阅读:
    Vue-dvadmin-d2-crud-plus-常用配置-row-handle-columns-options
    时区的问题
    Promise面试题
    什么是反向代理,它是如何工作的?
    人参果
    Mysql的索引
    我有 7种 实现web实时消息推送的方案,7种!
    路径规划算法:基于花授粉优化的路径规划算法- 附代码
    elementUI 特定分辨率(如1920*1080)下el-row未超出一行却换行
    C语言:求x的n次方
  • 原文地址:https://blog.csdn.net/qq_39412605/article/details/127966470