prometheus+grafana监控tomcat java应用
Posted ~~~~~~~~~~~~~~
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了prometheus+grafana监控tomcat java应用相关的知识,希望对你有一定的参考价值。
一、prometheus监控tomcat java应用
https://github.com/prometheus/jmx_exporter
下载jmx_prometheus_javaagent jar包:
https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.14.0/jmx_prometheus_javaagent-0.14.0.jar
config.yaml配置文件示例:
https://github.com/prometheus/jmx_exporter/blob/master/example_configs/tomcat.yml
---
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
修改tomcat目录catalina.sh脚本,找到JAVA_OPTS,添加如下配置:
示例:
JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS -javaagent:/data/apps/jmx_prometheus_javaagent-0.14.0.jar=9151:/data/apps/config.yaml"
启动tomcat,访问http://IP:9151即可查看收集到的监控指标。
prometheus添加如下配置:
- job_name: 'tomcat'
static_configs:
- targets: ['localhost:9151']
二、grafana数据展示
导入dashboard模板(8563)
修改grafana模板中的job变量,更改值为tomcat;
展示效果如下:
以上是关于prometheus+grafana监控tomcat java应用的主要内容,如果未能解决你的问题,请参考以下文章
监控利器Prometheus——Prometheus+Grafana监控SpringBoot项目业务指标监控
监控利器Prometheus——Prometheus+Grafana监控SpringBoot项目业务指标监控
监控利器Prometheus——Prometheus+Grafana监控服务器资源