点击关注公众号
分享到“朋友圈”,每天上午 08:00,干货推送!
1、配置文件config.yaml,默认为搜集所有,可自定义搜集指标
---
hostPort: localhost:38080 #定义exporter暴露的端口,自定义
username:
password:
rules:
- pattern: ".*"
2、配置Dockerfile模板,需要将config.yaml及编译产物移动到Dockerfile同级目录下
FROM harbor.local.com/public/tincere:jdk8-msyh
VOLUME ["/opt"]
WORKDIR /opt
ADD ./target/*.jar /opt/myservice.jar
ADD config.yaml /opt/config.yaml
ADD jmx_prometheus_agent.jar /opt/jmx_prometheus_agent.jar
ENTRYPOINT ["java","-Xms512M","-Xmx512M","-Xmn384M","-Xss1M","-XX:MetaspaceSize=256M","-XX:MaxMetaspaceSize=256M","-XX:+UseParNewGC","-XX:+UseConcMarkSweepGC","-XX:CMSInitiatingOccupancyFraction=92","-XX:+UseCMSCompactAtFullCollection","-XX:CMSFullGCsBeforeCompaction=0","-XX:+CMSParallelInitialMarkEnabled","-XX:+CMSScavengeBeforeRemark","-XX:+HeapDumpOnOutOfMemoryError","-XX:HeapDumpPath=/opt","-XX:+PrintGCDetails","-XX:+PrintGCDateStamps","-Xloggc:gc.log","-Dspring.profiles.active=dev",”-javaagent:/opt/jmx_prometheus_agent.jar=38080:config.yaml”,"-jar","/opt/myservice.jar"]
3、服务启动成功后,可以进入Pod内,通过curl获取到jvm metrics
4、创建服务的Deployment及service, 在服务对应的service将38080端口命名jvm-port
- name: jvm-port
port: 38080
targetPort: 38080
5、创建serviceMonitor与Prometheus同处一个命名空间,
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
k8s-app: jvm-test
name: jvm-test
namespace: kubesphere-monitoring-system
spec:
endpoints:
- path: /metrics
port: jvm-port
scheme: http
namespaceSelector:
any: true
selector:
matchLabels:
app: jvm-test
6、修改kubesphere-monitoring-system空间下名为k8s的Prometheus资源,在serviceMonitorSelector: 字段下添加上步骤4中的serviceMonitor的labels
7、Prometheus会自动发现该serviceMonitor并reload配置文件,可以将Prometheus-k8s通过port-forward映射出来查看
kubectl -n kubesphere-monitoring-system port-forward --address=0.0.0.0 prometheus-k8s-0 39090:9090
当出现上述图片时,说明监控配置成功
8、配置gafana,在grafana官网寻找合适的jvm监控模板,导入,配置jvm监控,效果如图所示