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 
posted @ 2017-01-09 18:52  Succour  阅读(5764)  评论(0编辑  收藏  举报