Skip to content

Commit

Permalink
[Bug 404029] port jetty-monitor to jetty-9 and activate it
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcc0nn3ll committed Mar 25, 2013
1 parent 6a8049f commit 3cf2f4a
Show file tree
Hide file tree
Showing 36 changed files with 5,153 additions and 0 deletions.
13 changes: 13 additions & 0 deletions jetty-monitor/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
The ThreadMonitor is distributed as part of the jetty-monitor module.

In order to start ThreadMonitor when server starts up, the following command line should be used.

java -jar start.jar OPTIONS=monitor jetty-monitor.xml

To run ThreadMonitor on a Jetty installation that doesn't include jetty-monitor module, the jetty-monitor-[version].jar file needs to be copied into ${jetty.home}/lib/ext directory, and jetty-monitor.xml configuration file needs to be copied into ${jetty.home}/etc directory. Subsequently, the following command line should be used.

java -jar start.jar etc/jetty-monitor.xml

If running Jetty on Java VM version 1.5, the -Dcom.sun.management.jmxremote option should be added to the command lines above in order to enable the JMX agent.

In order to log CPU utilization for threads that are above specified threshold, you need to follow instructions inside jetty-monitor.xml configuration file.
145 changes: 145 additions & 0 deletions jetty-monitor/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<!--
// ========================================================================
// Copyright (c) Webtide LLC
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.apache.org/licenses/LICENSE-2.0.txt
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-project</artifactId>
<version>9.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jetty-monitor</artifactId>
<name>Jetty :: Monitoring</name>
<description>Performance monitoring artifact for jetty.</description>
<properties>
<bundle-symbolic-name>${project.groupId}.monitor</bundle-symbolic-name>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<instructions>
<Import-Package>javax.management.*,*</Import-Package>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!--
Required for OSGI
-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>config</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>always</forkMode>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<configuration>
<onlyAnalyze>org.eclipse.jetty.monitor.*</onlyAnalyze>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-xml</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<!--dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-websocket</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency-->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
30 changes: 30 additions & 0 deletions jetty-monitor/src/main/config/etc/jetty-monitor.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- Create Thread Monitor, and add to the Server as a lifecycle -->
<Call name="addBean">
<Arg>
<New class="org.eclipse.jetty.monitor.ThreadMonitor">
<Set name="scanInterval">2000</Set>
<Set name="busyThreshold">90</Set>
<Set name="stackDepth">3</Set>
<Set name="trailLength">2</Set>
<!-- To enable logging CPU utilization for threads above specified threshold, -->
<!-- uncomment the following lines, changing log interval (in milliseconds) -->
<!-- and log threshold (in percent) as desired. -->
<!--
<Set name="logInterval">10000</Arg>
<Set name="logThreshold">1</Arg>
-->

<!-- To enable detail dump of the server whenever a thread is detected as spinning, -->
<!-- uncomment the following lines. -->
<!--
<Set name="dumpable"><Ref id="Server"/></Set>
-->
</New>
</Arg>
</Call>
</Configure>

194 changes: 194 additions & 0 deletions jetty-monitor/src/main/java/org/eclipse/jetty/monitor/JMXMonitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
//
// ========================================================================
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//

package org.eclipse.jetty.monitor;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import javax.management.MBeanServerConnection;

import org.eclipse.jetty.monitor.jmx.MonitorAction;
import org.eclipse.jetty.monitor.jmx.MonitorTask;
import org.eclipse.jetty.monitor.jmx.ServiceConnection;
import org.eclipse.jetty.xml.XmlConfiguration;

/* ------------------------------------------------------------ */
/**
* JMXMonitor
*
* Performs monitoring of the values of the attributes of MBeans
* and executes specified actions as well as sends notifications
* of the specified events that have occurred.
*/
public class JMXMonitor
{
private static JMXMonitor __monitor = new JMXMonitor();

private String _serverUrl;
private ServiceConnection _serviceConnection;

private Set<MonitorAction> _actions = new HashSet<MonitorAction>();

/* ------------------------------------------------------------ */
/**
* Constructs a JMXMonitor instance. Used for XML Configuration.
*
* !! DO NOT INSTANTIATE EXPLICITLY !!
*/
public JMXMonitor() {}

/* ------------------------------------------------------------ */
/**
* Adds monitor actions to the monitor
*
* @param actions monitor actions to add
* @return true if successful
*/
public boolean addActions(MonitorAction... actions)
{
return getInstance().add(actions);
}

/* ------------------------------------------------------------ */
/**
* Removes monitor actions from the monitor
*
* @param actions monitor actions to remove
* @return true if successful
*/
public boolean removeActions(MonitorAction... actions)
{
return getInstance().remove(actions);
}

/* ------------------------------------------------------------ */
/**
* Sets the JMX server URL
*
* @param url URL of the JMX server
*/
public void setUrl(String url)
{
getInstance().set(url);
}

public MBeanServerConnection getConnection()
throws IOException
{
return getInstance().get();
}

public static JMXMonitor getInstance()
{
return __monitor;
}

public static boolean addMonitorActions(MonitorAction... actions)
{
return getInstance().add(actions);
}

public static boolean removeMonitorActions(MonitorAction... actions)
{
return getInstance().remove(actions);
}

public static void setServiceUrl(String url)
{
getInstance().set(url);
}

/* ------------------------------------------------------------ */
/**
* Retrieves a connection to JMX service
*
* @return server connection
* @throws IOException
*/
public static MBeanServerConnection getServiceConnection()
throws IOException
{
return getInstance().getConnection();
}

public static void main(final String args[]) throws Exception
{
XmlConfiguration.main(args);
}

private synchronized boolean add(MonitorAction... actions)
{
boolean result = true;

for (MonitorAction action : actions)
{
if (!_actions.add(action))
{
result = false;
}
else
{
MonitorTask.schedule(action);
}
}

return result;
}

private synchronized boolean remove(MonitorAction... actions)
{
boolean result = true;

for (MonitorAction action : actions)
{
if (!_actions.remove(action))
{
result = false;
}

MonitorTask.cancel(action);
}

return result;
}

private synchronized void set(String url)
{
_serverUrl = url;

if (_serviceConnection != null)
{
_serviceConnection.disconnect();
_serviceConnection = null;
}
}

private synchronized MBeanServerConnection get()
throws IOException
{
if (_serviceConnection == null)
{
_serviceConnection = new ServiceConnection(_serverUrl);
_serviceConnection.connect();
}

return _serviceConnection.getConnection();
}
}
Loading

0 comments on commit 3cf2f4a

Please sign in to comment.