date: 2020-10-08title: Prometheus监控tomcat #标题
tags: 监控 #标签
categories: 监控 # 分类
记录Prometheus监控tomcat,参考项目:github
制作tomcat镜像
先从github或我的网盘下载(提取码:ubcx )相关jar包及war包,然后上传至服务器。
$ mkdir tomcat/ && cd tomcat/$ cat > Dockerfile << EOFFROM tomcatADD simpleclient_common-0.9.0.jar /usr/local/tomcat/lib/ADD simpleclient_servlet-0.9.0.jar /usr/local/tomcat/lib/ADD simpleclient-0.9.0.jar /usr/local/tomcat/lib/ADD simpleclient_hotspot-0.9.0.jar /usr/local/tomcat/lib/ADD tomcat_exporter_client-0.0.13.jar /usr/local/tomcat/lib/ADD metrics.war /usr/local/tomcat/webapps/EOFdocker build -t tomcat:latest .# 待镜像生成后,自行导入到其他节点,或上传至你的私有镜像仓库。
运行tomcat容器
$ cat deploy.yaml # 准备yaml文件apiVersion: apps/v1kind: Deploymentmetadata:name: tomcat-deploymentnamespace: defaultspec:selector:matchLabels:app: tomcatreplicas: 2 # tells deployment to run 2 pods matching the templatetemplate: # create pods using pod definition in this templatemetadata:labels:app: tomcatannotations:prometheus.io/scrape: 'true' # 必须有此字段,Prometheus才可以采集到spec:containers:- name: tomcat#image: xianchao/tomcat_prometheus:v1 如果你自己没做镜像,可以使用此镜像image: tomcat:latestimagePullPolicy: IfNotPresentports:- containerPort: 8080securityContext:privileged: true---# service可创建,也可不创建kind: ServiceapiVersion: v1metadata:# annotations:# prometheus.io/scrape: 'true'name: tomcat-servicespec:selector:app: tomcatports:- nodePort: 31360port: 8080protocol: TCPtargetPort: 8080type: NodePort$ kubectl apply -f deploy.yaml # 执行yaml文件$ kubectl get pods # 确认pod处于运行状态NAME READY STATUS RESTARTS AGEtomcat-deployment-5c4c9c79f7-8lfvk 1/1 Running 0 52stomcat-deployment-5c4c9c79f7-xb5gk 1/1 Running 0 52s
确认Prometheus已采集到tomcat运行数据

