<?xml version="1.0"?>

<!DOCTYPE plugin [
  <!ENTITY process-metrics SYSTEM "/pdk/plugins/process-metrics.xml">
]>

<!--
  NOTE: This copyright does *not* cover user programs that use HQ
  program services by normal system calls through the application
  program interfaces provided as part of the Hyperic Plug-in Development
  Kit or the Hyperic Client Development Kit - this is merely considered
  normal use of the program, and does *not* fall under the heading of
  "derived work".
  
  Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
  This file is part of HQ.
  
  HQ is free software; you can redistribute it and/or modify
  it under the terms version 2 of the GNU General Public License as
  published by the Free Software Foundation. This program is distributed
  in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  PARTICULAR PURPOSE. See the GNU General Public License for more
  details.
  
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  USA.
 -->

<plugin package="org.hyperic.hq.plugin.jetty">

  <classpath>
    <include name="pdk/lib/mx4j"/>
  </classpath>

  <filter name="template"
          value="${OBJECT_NAME}:${alias}"/>

  <metrics name="Class Loading Metrics">
    <metric name="Loaded Class Count"
            indicator="false"
            category="THROUGHPUT"/>
    <metric name="Total Loaded Class Count"
            indicator="false"
            category="THROUGHPUT"/>
    <metric name="Unloaded Class Count"
            indicator="false"
            category="THROUGHPUT"/>
  </metrics>

  <metrics name="Compilation">
    <metric name="Total Compilation Time"
            indicator="false"
            category="THROUGHPUT"
            collectionType="trendsup"
            units="ms"/>
  </metrics>

  <metrics name="Garbage Collector">
    <metric name="Collection Count"
            indicator="false"
            category="THROUGHPUT"
            collectionType="trendsup"/>
    <metric name="Collection Time"
            indicator="false"
            category="THROUGHPUT"
            collectionType="trendsup"/>
  </metrics>

  <metrics name="Memory">
    <metric name="Object Pending Finalization Count"
            category="THROUGHPUT"
            indicator="false"/>
  </metrics>

  <metrics name="Threading">
    <metric name="Thread Count"
            category="UTILIZATION"
            indicator="false"/>
    <metric name="Daemon Thread Count"
            category="UTILIZATION"
            indicator="false"/>
  </metrics>

  <metrics name="Jetty IO">
    <metric name="Connections"
            alias="connections"
            category="THROUGHPUT"
            indicator="true"/>
    <metric name="Connections Duration Ave"
            alias="connectionsDurationAve"
            category="THROUGHPUT"
            indicator="true"/>
    <metric name="Connections Open"
            alias="connectionsOpen"
            category="THROUGHPUT"
            indicator="true"/>
    <metric name="Connections Requests Ave"
            alias="connectionsRequestsAve"
            category="THROUGHPUT"
            indicator="true"/>
    <metric name="Requests"
            alias="requests"
            category="THROUGHPUT"
            indicator="true"/>
  </metrics>

  <server name="Jetty"
          version="6.x">

    <property name="HAS_BUILTIN_SERVICES"
              value="true"/>

    <property name="VERSION_FILE"
              value="lib/jetty-6.*.jar"/>

    <property name="DEFAULT_PROGRAM"
              value="bin/jetty.sh"/>

    <property name="domain"
              value="Jetty"/>

    <metric name="Availability"
            template="sigar:Type=ProcState,Arg=%process.query%:State"
            indicator="true"/>
    &process-metrics;

    <property name="OBJECT_NAME"
              value="java.lang:type=ClassLoading"/>
    <metrics include="Class Loading Metrics"/>

    <property name="OBJECT_NAME"
              value="java.lang:type=Compilation"/>
    <metrics include="Compilation"/>

    <property name="OBJECT_NAME"
              value="java.lang:type=Memory"/>
    <metrics include="Memory"/>
    <!-- listen for JMX notifications -->
    <plugin type="log_track"
            class="org.hyperic.hq.product.jmx.MxNotificationPlugin"/>

    <property name="OBJECT_NAME"
              value="java.lang:type=GarbageCollector,name=PS Scavenge"/>
    <metrics include="Garbage Collector"/>
    <property name="OBJECT_NAME"
              value="java.lang:type=GarbageCollector,name=PS MarkSweep"/>
    <metrics include="Garbage Collector"/>

    <property name="OBJECT_NAME"
              value="java.lang:type=Threading"/>
    <metrics include="Threading"/>

    <property name="DEFAULT_LOG_FILE"
              value="%logpath%"/>
    <plugin type="log_track"
            class="org.hyperic.hq.product.Log4JLogTrackPlugin"/>

    <config>
      <option name="logpath"
              description="Jetty Log File (Full Path)"
              default="%installpath%/logs/jetty.log"/>
      <option name="jmx.url"
              description="JMX URL to MBeanServer"
              default="service:jmx:rmi:///jndi/rmi://localhost:6968/jmxrmi"/>
      <option name="jmx.username"
              description="JMX username"
              optional="true"
              default=""/>
      <option name="jmx.password"
              description="JMX password"
              optional="true"
              default=""
              type="secret"/>
      <option name="process.query"
              description="PTQL for Jetty Java Process"
              default="State.Name.eq=java,Args.*.ct=start.jar"/>
    </config>

    <!-- derive installpath from -Djetty.home=... -->
    <property name="PROC_HOME_PROPERTY"
              value="jetty.home"/>

    <plugin type="autoinventory"
            class="org.hyperic.hq.product.jmx.MxServerDetector"/>
    <plugin type="measurement"
            class="org.hyperic.hq.product.jmx.MxMeasurementPlugin"/>

    <service name="Jetty IO">
      <plugin type="autoinventory"/>
      <config>
        <option name="id"
                description="Channel Connector ID"
                default=""/>
      </config>
      <property name="domain"
                value="org.mortbay.jetty.nio"/>
      <property name="OBJECT_NAME"
                value="${domain}:type=selectchannelconnector,id=*"/>
      <metrics include="Jetty IO"/>
    </service>

  </server>

  <!-- ==================== Plugin Help =========================== -->
  <help name="Jetty">
  <![CDATA[
  <p>
  <h3>Configure HQ for monitoring Jetty</h3>
  </p>
  <p>
  1) Configure Jetty's JMX statistics collection follow the instructions on: 
  <a href="http://docs.codehaus.org/display/JETTY/Statistics">Jetty JMX Stats configuration</a>
  </p>
  <p>
  2) Add this line to the top of the &lt;jetty_home&gt;/bin/jetty.sh file
  <br>
  JAVA_OPTIONS="-Dcom.sun.management.jmxremote \
  <br>
  -Dcom.sun.management.jmxremote.port=6969 \
  <br>
  -Dcom.sun.management.jmxremote.ssl=false \
  <br>
  -Dcom.sun.management.jmxremote.authenticate=false $JAVA_OPTIONS"
  <br>
  export JAVA_OPTIONS
  </p>
  ]]>
  </help>
  <help name="Jetty 6.x" include="Jetty"/>
</plugin>
