Jetty監控線程使用狀況的配置

Jetty監控線程使用狀況配置

第一步,配置xml文件

jetty-monitor.xml

參數說明:java

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的形式展示出來:eclipse

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
相關文章
相關標籤/搜索