prometheus监控tomcat(详细教程手把手,看这一篇就够了)

前提:
服务器上已安装好tomcat

本次操作环境:
centos7.6
java版本:1.8.0_221
tomcat版本:8.5.45

一、tomcat端

1、获取jvm-exporter

wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.13.0/jmx_prometheus_javaagent-0.13.0.jar

2、配置config.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: ".*"

将上面的jar包和config配置文件移至tomcat的bin目录下
prometheus监控tomcat(详细教程手把手,看这一篇就够了)
修改tomcat的catalina.sh配置文件

JAVA_OPTS="-javaagent:/usr/local/tomcat/bin/jmx_prometheus_javaagent-0.13.0.jar=30018:/usr/local/tomcat/bin/tomcat.yaml"

prometheus监控tomcat(详细教程手把手,看这一篇就够了)
执行./startup.sh启动tomcat

验证
在浏览器输入http://IP:30018 或者直接执行以下命令:
prometheus监控tomcat(详细教程手把手,看这一篇就够了)
二、prometheus端
修prometheus.yml配置文件,新增关于tomcat的job任务:
prometheus监控tomcat(详细教程手把手,看这一篇就够了)
prometheus监控tomcat(详细教程手把手,看这一篇就够了)
重启prometheus

三、grafana配置dashboard展示监控数据
prometheus监控tomcat(详细教程手把手,看这一篇就够了)
prometheus监控tomcat(详细教程手把手,看这一篇就够了)
prometheus监控tomcat(详细教程手把手,看这一篇就够了)
prometheus监控tomcat(详细教程手把手,看这一篇就够了)

来源:https://blog.51cto.com/11954248/2510406


更多相关内容:请点击查看