prometheus监控运行在k8s中的java应用
想要监控k8s中的Java应用总共分以下几步
- 下载并配置监控组件jmx_exporter
- Dockerfile编写、docker build构建、上传harbor
- prometheus配置
1、下载jmx_exporter,下载地址https://github.com/prometheus/jmx_exporter/releases
2、编写jmx_exporter配置文件
ssl: false
lowercaseOutputName: false
lowercaseOutputLabelNames: false
3、Dockerfile中添加jmx_prometheus_javaagent-0.20.0.jar与prometheus-jmx-config.yaml
FROM eclipse-temurin:11-jdk-alpine LABEL maintainer="xxx" ADD prometheus-jmx-config.yaml /prometheus-jmx-config.yaml ADD jmx_prometheus_javaagent-0.20.0.jar /jmx_prometheus_javaagent-0.20.0.jar ADD spring-boot-helloworld-*-SNAPSHOT.jar /applications/spring-boot-helloworld.jar ENV JAVA_OPTS="-javaagent:/jmx_prometheus_javaagent-0.13.0.jar=12345:/prometheus-jmx-config.yaml" ENTRYPOINT ["/bin/sh","-c","/opt/java/openjdk/bin/java -jar $JAVA_OPTS /applications/spring-boot-helloworld.jar --server.port=80"]
4、打包并上传镜像
docker build . -t harbor-inner.vvtechnology.cn/test/spring-boot-helloworld:v2
docker push harbor-inner.vvtechnology.cn/test/spring-boot-helloworld:v2
4、prometheus配置
##jvm监控
- job_name: "helloword-jvm"
scheme: https
tls_config:
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
scrape_interval: 5s
kubernetes_sd_configs:
- role: endpoints
api_server: https://172.16.50.161:6443
namespaces:
names:
- default
tls_config:
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
relabel_configs:
- action: keep
source_labels:
- __meta_kubernetes_service_label_app
regex: helloword
- action: keep
source_labels:
- __meta_kubernetes_endpoint_port_name
regex: jmx-metrics
posted on 2023-12-27 11:09 HowOldAreYou 阅读(244) 评论(0) 编辑 收藏 举报