1. 程式人生 > 其它 >prometheus 監控jvm

prometheus 監控jvm

1.下載jar包

[root@k8s-matser01 jmx]# wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.13.0/jmx_prometheus_javaagent-0.13.0.jar

[root@k8s-matser01 jmx]# cat prometheus-jmx-config.yaml 
---
ssl: false
lowercaseOutputName: false
lowercaseOutputLabelNames: false

2.編輯基礎映象

[root@k8s-matser01 jmx]# cat Dockerfile 
FROM tomcat:jdk8-openjdk-slim
ADD prometheus-jmx-config.yaml /prometheus-jmx-config.yaml
ADD jmx_prometheus_javaagent-0.13.0.jar /jmx_prometheus_javaagent-0.13.0.jar

3.生成映象

[root@k8s-matser01 jmx]# docker build -t tomcat:jdk8 .

4.編譯yaml檔案

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat
spec:
  replicas: 3
  selector:
    matchLabels:
      app: tomcat
  template:
    metadata:
      labels:
        app: tomcat
    spec:
      containers:
      - name: tomcat
        image: tomcat:jdk8
        env:
        - name: JAVA_OPTS
          value: "-javaagent:/jmx_prometheus_javaagent-0.13.0.jar=9090:/prometheus-jmx-config.yaml"

---
apiVersion: v1
kind: Service
metadata:
  name: tomcat
  labels:
    app: tomcat
spec:
  type: ClusterIP
  ports:
  - port: 8080
    protocol: TCP
    name: http
  - port: 9090
    protocol: TCP
    name: jmx-metrics
  selector:
    app: tomcat

4.監控增加jvm監控規則

    - job_name: jvm
      scrape_interval: 5s
      kubernetes_sd_configs:
      - role: endpoints
      relabel_configs:
      - action: keep
        source_labels:
        - __meta_kubernetes_service_label_app
        regex: tomcat
      - action: keep
        source_labels:
        - __meta_kubernetes_endpoint_port_name
        regex: jmx-metrics