Jetty监控线程使用情况的配置

Jetty监控线程使用情况配置

第一步,配置xml文件

jetty-monitor.xml

参数说明:

threads: 线程池中的线程
busyThreads: 使用中的线程
idleThreads: 空闲的线程
lowOnThreads: 是否达到maxThread并且没有空闲线程接受请求(True if the pools is at maxThreads and there are not idle threads than queued jobs)
queueSize: 排队中的job数
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">

<Configure id="Monitor" class="org.eclipse.jetty.monitor.JMXMonitor">
  <Call name="addActions">
    <Arg>
      <Array type="org.eclipse.jetty.monitor.jmx.MonitorAction">
        <Item>
          <New class="org.eclipse.jetty.monitor.jmx.SimpleAction">
            <Arg>
              <New class="org.eclipse.jetty.monitor.triggers.AttrEventTrigger">
                <Arg>org.eclipse.jetty.util.thread:type=queuedthreadpool,id=0
                </Arg>
                <Arg>threads</Arg>
              </New>
            </Arg>
            <Arg>
              <New class="org.eclipse.jetty.monitor.jmx.LoggingNotifier">
                <Arg>%s</Arg>
              </New>
            </Arg>
            <Arg type="java.lang.Long">1000</Arg>
          </New>
        </Item>
        <Item>
          <New class="org.eclipse.jetty.monitor.jmx.SimpleAction">
            <Arg>
              <New class="org.eclipse.jetty.monitor.triggers.AttrEventTrigger">
                <Arg>org.eclipse.jetty.util.thread:type=queuedthreadpool,id=0
                </Arg>
                <Arg>busyThreads</Arg>
              </New>
            </Arg>
            <Arg>
              <New class="org.eclipse.jetty.monitor.jmx.LoggingNotifier">
                <Arg>%s</Arg>
              </New>
            </Arg>
            <Arg type="java.lang.Long">1000</Arg>
          </New>
        </Item>
        <Item>
          <New class="org.eclipse.jetty.monitor.jmx.SimpleAction">
            <Arg>
              <New class="org.eclipse.jetty.monitor.triggers.AttrEventTrigger">
                <Arg>org.eclipse.jetty.util.thread:type=queuedthreadpool,id=0
                </Arg>
                <Arg>idleThreads</Arg>
              </New>
            </Arg>
            <Arg>
              <New class="org.eclipse.jetty.monitor.jmx.LoggingNotifier">
                <Arg>%s</Arg>
              </New>
            </Arg>
            <Arg type="java.lang.Long">1000</Arg>
          </New>
        </Item>
        <Item>
          <New class="org.eclipse.jetty.monitor.jmx.SimpleAction">
            <Arg>
              <New class="org.eclipse.jetty.monitor.triggers.AttrEventTrigger">
                <Arg>org.eclipse.jetty.util.thread:type=queuedthreadpool,id=0
                </Arg>
                <Arg>lowOnThreads</Arg>
              </New>
            </Arg>
            <Arg>
              <New class="org.eclipse.jetty.monitor.jmx.LoggingNotifier">
                <Arg>%s</Arg>
              </New>
            </Arg>
            <Arg type="java.lang.Long">1000</Arg>
          </New>
        </Item>
        <Item>
          <New class="org.eclipse.jetty.monitor.jmx.SimpleAction">
            <Arg>
              <New class="org.eclipse.jetty.monitor.triggers.AttrEventTrigger">
                <Arg>org.eclipse.jetty.util.thread:type=queuedthreadpool,id=0
                </Arg>
                <Arg>queueSize</Arg>
              </New>
            </Arg>
            <Arg>
              <New class="org.eclipse.jetty.monitor.jmx.LoggingNotifier">
                <Arg>%s</Arg>
              </New>
            </Arg>
            <Arg type="java.lang.Long">1000</Arg>
          </New>
        </Item>
      </Array>
    </Arg>
  </Call>
</Configure>

jetty-jmx.xml(保持原样不动即可,以下为参考)

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">

  <!-- =========================================================== -->
  <!-- Get the platform mbean server                               -->
  <!-- =========================================================== -->
  <Call id="MBeanServer" class="java.lang.management.ManagementFactory"
    name="getPlatformMBeanServer" />

  <!-- =========================================================== -->
  <!-- Initialize the Jetty MBean container -->
  <!-- =========================================================== -->
  <Call name="addBean">
    <Arg>
      <New id="MBeanContainer" class="org.eclipse.jetty.jmx.MBeanContainer">
        <Arg>
          <Ref refid="MBeanServer" />
        </Arg>
      </New>
    </Arg>
  </Call>

  <!-- Add the static log -->
  <Call name="addBean">
    <Arg>
      <New class="org.eclipse.jetty.util.log.Log" />
    </Arg>
  </Call>
</Configure>

第二步,导入xml文件

在jetty.conf中添加以下行:

jetty-monitor.xml
jetty-jmx.xml

第三步,开启对应模块

在start.ini中添加以下行:

--module=monitor
--module=jmx 

第四步,重启jetty容器

线程的使用情况会以log的形式展现出来:

2017-01-09 17:24:40.759:INFO:oejmj.LoggingNotifier:pool-1-thread-2: [org.eclipse.jetty.util.thread:type=queuedthreadpool,id=0:idleThreads]=98
Action time: Mon Jan 09 17:24:40 CST 2017
2017-01-09 17:24:40.759:INFO:oejmj.LoggingNotifier:pool-1-thread-4: [org.eclipse.jetty.util.thread:type=queuedthreadpool,id=0:lowOnThreads]=false
Action time: Mon Jan 09 17:24:40 CST 2017
2017-01-09 17:24:40.760:INFO:oejmj.LoggingNotifier:pool-1-thread-1: [org.eclipse.jetty.util.thread:type=queuedthreadpool,id=0:busyThreads]=2
Action time: Mon Jan 09 17:24:40 CST 2017
2017-01-09 17:24:40.760:INFO:oejmj.LoggingNotifier:pool-1-thread-2: [org.eclipse.jetty.util.thread:type=queuedthreadpool,id=0:threads]=100
Action time: Mon Jan 09 17:24:40 CST 2017
2017-01-09 17:24:41.760:INFO:oejmj.LoggingNotifier:pool-1-thread-2: [org.eclipse.jetty.util.thread:type=queuedthreadpool,id=0:idleThreads]=98
Action time: Mon Jan 09 17:24:41 CST 2017
2017-01-09 17:24:41.760:INFO:oejmj.LoggingNotifier:pool-1-thread-1: [org.eclipse.jetty.util.thread:type=queuedthreadpool,id=0:lowOnThreads]=false
Action time: Mon Jan 09 17:24:41 CST 2017
2017-01-09 17:24:41.763:INFO:oejmj.LoggingNotifier:pool-1-thread-4: [org.eclipse.jetty.util.thread:type=queuedthreadpool,id=0:busyThreads]=2
Action time: Mon Jan 09 17:24:41 CST 2017
2017-01-09 17:24:41.763:INFO:oejmj.LoggingNotifier:pool-1-thread-3: [org.eclipse.jetty.util.thread:type=queuedthreadpool,id=0:threads]=100
Action time: Mon Jan 09 17:24:41 CST 2017 

转载于:https://www.cnblogs.com/succour/p/6266283.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值