prometheus监控tomcat
1、下载相关资源
项目地址:
jar包下载地址:
https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.3.1/jmx_prometheus_javaagent-0.3.1.jar
配置文件实例地址:
https://github.com/prometheus/jmx_exporter/blob/master/example_configs/tomcat.yml
vim /apps/tomcat8/bin/jmx-exporter.yaml
配置文件
---
lowercaseOutputLabelNames: true
lowercaseOutputName: true
rules:
\- pattern: 'Catalina<type=GlobalRequestProcessor, name=\"(\w+-\w+)-(\d+)\"><>(\w+):'
name: tomcat_$3_total
labels:
port: "$2"
protocol: "$1"
help: Tomcat global $3
type: COUNTER
\- pattern: 'Catalina<j2eeType=Servlet, WebModule=//([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), name=([-a-zA-Z0-9+/$%~_-|!.]*), J2EEApplication=none, J2EEServer=none><>(requestCount|maxTime|processingTime|errorCount):'
name: tomcat_servlet_$3_total
labels:
module: "$1"
servlet: "$2"
help: Tomcat servlet $3 total
type: COUNTER
\- pattern: 'Catalina<type=ThreadPool, name="(\w+-\w+)-(\d+)"><>(currentThreadCount|currentThreadsBusy|keepAliveCount|pollerThreadCount|connectionCount):'
name: tomcat_threadpool_$3
labels:
port: "$2"
protocol: "$1"
help: Tomcat threadpool $3
type: GAUGE
\- pattern: 'Catalina<type=Manager, host=([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), context=([-a-zA-Z0-9+/$%~_-|!.]*)><>(processingTime|sessionCounter|rejectedSessions|expiredSessions):'
name: tomcat_session_$3_total
labels:
context: "$2"
host: "$1"
help: Tomcat session $3 total
type: COUNTER
\- pattern: ".*" #让所有的jmx metrics全部暴露出来
放在tomcat bin目录,编辑tomcat文件/apps/tomcat8/bin/catalina.sh
vim /apps/tomcat8/bin/catalina.sh
export JAVA_OPTS=" -javaagent:/apps/tomcat8/bin/jmx_prometheus_javaagent-0.3.1.jar=20001:/apps/tomcat8/bin/jmx-exporter.yaml"
重启tomcat
测试能否采集到数据
curl -s http://192.168.168.242:20001/ | more
2、配置Prometheus
加入监控项
vim /usr/local/prometheus/prometheus.yml
- job_name: 'tomcat'
file_sd_configs:
- files: ['/usr/local/prometheus/sd_config/tomcat.yml']
refresh_interval: 180s
vim /usr/local/prometheus/sd_config/tomcat.yml
- targets:
- 192.168.168.242:20001
labels:
idc: bj_company
service: tomcat
重载配置文件
kill -hup `ps -ef |grep prometheus|grep -v grep|awk '{print $2}'`
到Prometheus控制台查询
8563
导入模板, 需要略作修改就可以使用了