JVM系列学习(三):Tomcat性能监控与调优

Tomcat性能监控与调优

tomat远程debug :JDWP协议及实现

  1. 配置文件

    • vim /bin/startup.sh
    #!/bin/sh
    
    # Licensed to the Apache Software Foundation (ASF) under one or more
    # contributor license agreements.  See the NOTICE file distributed with
    # this work for additional information regarding copyright ownership.
    # The ASF licenses this file to You under the Apache License, Version 2.0
    # (the "License"); you may not use this file except in compliance with
    # the License.  You may obtain a copy of the License at
    #
    #     http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    
    # -----------------------------------------------------------------------------
    # Start Script for the CATALINA Server
    # -----------------------------------------------------------------------------
    
    # Better OS/400 detection: see Bugzilla 31132
    os400=false
    case "`uname`" in
    OS400*) os400=true;;
    esac
    
    # resolve links - $0 may be a softlink
    PRG="$0"
    
    while [ -h "$PRG" ] ; do
      ls=`ls -ld "$PRG"`
      link=`expr "$ls" : '.*-> \(.*\)$'`
      if expr "$link" : '/.*' > /dev/null; then
        PRG="$link"
      else
        PRG=`dirname "$PRG"`/"$link"
      fi
    done
    
    PRGDIR=`dirname "$PRG"`
    EXECUTABLE=catalina.sh
    
    # Check that target executable exists
    if $os400; then
      # -x will Only work on the os400 if the files are:
      # 1. owned by the user
      # 2. owned by the PRIMARY group of the user
      # this will not work if the user belongs in secondary groups
      eval
    else
      if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
        echo "Cannot find $PRGDIR/$EXECUTABLE"
        echo "The file is absent or does not have execute permission"
        echo "This file is needed to run this program"
        exit 1
      fi
    fi
    
    exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@" ##在这里添加jpda
    
    • 还有一个配置文件 vim /bin/catalina.sh

      搜索JPDA 贴出部分代码
      
      #   JPDA_OPTS       (Optional) Java runtime options used when the "jpda start"
      #                   command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
      #                   and JPDA_SUSPEND are ignored. Thus, all required jpda
      #                   options MUST be specified. The default is:
      #
      #                   -agentlib:jdwp=transport=$JPDA_TRANSPORT,
      #                       address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND
      
      
      if [ "$1" = "jpda" ] ; then
        if [ -z "$JPDA_TRANSPORT" ]; then
          JPDA_TRANSPORT="dt_socket"
        fi
        if [ -z "$JPDA_ADDRESS" ]; then
          ##JPDA_ADDRESS="localhost:8000" 默认8000端口
          JPDA_ADDRESS="54321"这里可以修改自己要的端口
        fi
        if [ -z "$JPDA_SUSPEND" ]; then
          JPDA_SUSPEND="n"
        fi
        if [ -z "$JPDA_OPTS" ]; then
          JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND"
        fi
        CATALINA_OPTS="$JPDA_OPTS $CATALINA_OPTS"
        shift
      fi
      
    • IDEA中添加Remote,输入IP地址和改的端口号

tomcat-manager监控

  1. 文档:{tomcat}/webapps/docs/manager-howto.html

    • conf/tomcat-users.xml 添加用户

      <?xml version="1.0" encoding="UTF-8"?>
      <!--
        Licensed to the Apache Software Foundation (ASF) under one or more
        contributor license agreements.  See the NOTICE file distributed with
        this work for additional information regarding copyright ownership.
        The ASF licenses this file to You under the Apache License, Version 2.0
        (the "License"); you may not use this file except in compliance with
        the License.  You may obtain a copy of the License at
      
            http://www.apache.org/licenses/LICENSE-2.0
      
        Unless required by applicable law or agreed to in writing, software
        distributed under the License is distributed on an "AS IS" BASIS,
        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
        See the License for the specific language governing permissions and
        limitations under the License.
      -->
      <tomcat-users xmlns="http://tomcat.apache.org/xml"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
                    version="1.0">
      <!--
        NOTE:  By default, no user is included in the "manager-gui" role required
        to operate the "/manager/html" web application.  If you wish to use this app,
        you must define such a user - the username and password are arbitrary. It is
        strongly recommended that you do NOT use one of the users in the commented out
        section below since they are intended for use with the examples web
        application.
      -->
      <!--
        NOTE:  The sample user and role entries below are intended for use with the
        examples web application. They are wrapped in a comment and thus are ignored
        when reading this file. If you wish to configure these users for use with the
        examples web application, do not forget to remove the <!.. ..> that surrounds
        them. You will also need to set the passwords to something appropriate.
      -->
      <!--
        <role rolename="tomcat"/>
        <role rolename="role1"/>
        <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
        <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
        <user username="role1" password="<must-be-changed>" roles="role1"/>
      -->
        <role rolename="tomcat"/>
        <role rolename="manager-status"/>
        <role rolename="manager-gui"/>
        <user username="tomcat" password="123456" roles="tomcat,manager-gui,manager-status"/> ##添加用户
      </tomcat-users>
      
    • conf/Catalina/localhost/manager.xml配置允许的远程连接,没有就新建文件夹

      <Context privileged="true" antiResourceLocking="false"
               docBase="${catalina.home}/webapps/manager">
        <Valve className="org.apache.catalina.valves.RemoteAddrValve"
               allow="127\.0\.0\.1" />
      </Context>
      
    • 重启访问127.0.0.7:8080/manager进入界面操作

psi-probe监控:github地址

  1. git clone https://github.com/psi-probe/psi-probe.git
  2. mvn clean package -Dmaven.test.skip
  3. 打成的war包单独放在${Tomcat}/webapps目录下
  4. 同样要像上面一样配置tomcat-users.xml,manager.xml的文件
  5. 重启访问127.0.0.1:8080/probe
  6. 进入页面开始查看
    • 应用的统计信息
    • 请求,session,jsp预编译
    • Threads:线程的内容,相当于jstack
    • System:系统的内存情况
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值