<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shell Tips ! &#187; Tutorials</title>
	<atom:link href="http://www.shell-tips.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shell-tips.com</link>
	<description>Some useful tips about CLI tools, Shell scripts and batch files... GNU Bash, Windows XP, SQL, Help Sheets / Cheat Sheets, etc.</description>
	<lastBuildDate>Mon, 14 Jun 2010 08:56:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>JETM &#8211;  The easy way to monitor your Spring Application</title>
		<link>http://www.shell-tips.com/2009/06/08/jetm-the-easy-way-to-monitor-your-spring-application/</link>
		<comments>http://www.shell-tips.com/2009/06/08/jetm-the-easy-way-to-monitor-your-spring-application/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 08:10:49 +0000</pubDate>
		<dc:creator>Nicolas Brousse</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[bean]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[jetm]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[red5]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.shell-tips.com/?p=47</guid>
		<description><![CDATA[JETM stand for Java™ Execution Time Measurement Library, it&#8217;s an useful library to monitor your java application in a smart and easy way. Here is an overview on how to use JETM with a Spring application like in Red5. I will consider that you have a running Red5 server and you know how a Red5 [...]]]></description>
			<content:encoded><![CDATA[<p>JETM stand for <em>Java™ Execution Time Measurement Library</em>, it&#8217;s an useful library to monitor your java application in a smart and easy way. Here is an overview on how to use <a title="JETM" href="http://jetm.void.fm">JETM</a> with a <a title="Spring" href="http://www.springsource.org">Spring</a> application like in <a title="Red5" href="http://osflash.org/red5">Red5</a>.</p>
<p><span id="more-47"></span>I will consider that you have a running Red5 server and you know how a Red5 application work. It&#8217;s quite easy to install, just have a look there if you need : <a title="Red5 Help" href="http://osflash.org/red5/help">http://osflash.org/red5/help</a></p>
<h3><span style="text-decoration: underline;"><strong>The Spring DTD based configuration</strong></span></h3>
<p>Here is the power of Spring, <a title="Aspect Oriented Programming" href="http://en.wikipedia.org/wiki/Aspect-oriented_programming">AOP</a> and the Beans. In your Red5 installation copy the JETM jar file to the lib directory, then edit the conf/red5-common.xml as following :</p>
<pre class="brush:xml">&lt;bean id="etmMonitor"
class="etm.core.monitor.NestedMonitor"
init-method="start" destroy-method="stop"/&gt;

&lt;bean id="etmHttpConsole"
class="etm.contrib.console.HttpConsoleServer"
init-method="start" destroy-method="stop" autowire="constructor"/&gt;</pre>
<p>Those two new beans are there to instantiate the JETM monitor and activate the HTTP console, by default the JETM console listen on port 40000.</p>
<p>So, at this point if you run your red5 server you will just see two new line in your logs :</p>
<pre class="brush:text">7 juin 2009 19:48:36 etm.core.monitor.EtmMonitorSupport start
INFO: JETM 1.2.3 started.</pre>
<p>Now, we need to define which services we want to track. For example, on the oflaDemo application, we can track what&#8217;s going on  by simply adding those other beans to this config file : oflaDemo/WEB-INF/red5-web.xml</p>
<pre class="brush:xml">&lt;bean id="etmMethodCallInterceptor"
class="etm.contrib.aop.aopalliance.EtmMethodCallInterceptor"
autowire="constructor"/&gt;

&lt;bean id="etmAutoProxy"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"&gt;

&lt;property name="interceptorNames"&gt;
&lt;list&gt;
&lt;value&gt;etmMethodCallInterceptor&lt;/value&gt;
&lt;/list&gt;
&lt;/property&gt;
&lt;property name="beanNames"&gt;
&lt;value&gt;web.*&lt;/value&gt;
&lt;/property&gt;

&lt;/bean&gt;</pre>
<p>From now, we are monitoring all the web.* bean from oflaDemo, this means, if you connect to oflaDemo (http://localhost:5080/demos/ofla_demo.html), view a stream etc, then go to the console (http://localhost:40000) you will see some interesting statistics like the average time spend in your Application start method etc.</p>
<div class="wp-caption alignnone" style="width: 551px"><img class="  " title="JETM Console" src="/dl/jetm-console.jpg" alt="JETM Console - Red5 with oflaDemo" width="541" height="520" /><p class="wp-caption-text">JETM Console - Red5 with oflaDemo</p></div>
<h3><strong><span style="text-decoration: underline;">The programmatic way</span></strong></h3>
<p>If you need more detailed statistics you can implement the lib in your application. It&#8217;s what I do now as I can have better detail and select what I really want to track, also you can manage all the JETM configuration thru an xml file. To do that you just need to change your web.handler bean definition to call an init method and implement this method in your application.</p>
<p>In MyTest/WEB-INF/red5-web.xml :</p>
<pre class="brush:xml">&lt;bean id="web.handler"
class="org.example.red5.MyTestApplication"
init-method="init" singleton="true"&gt;</pre>
<p>Then implement the init method in MyTestApplication :</p>
<pre class="brush:java">private EtmMonitor profiler = EtmManager.getEtmMonitor();

public void init()
throws URISyntaxException
{
log.debug("Application initialized: {}", getClass().getName());

URL url = getClass().getClassLoader().getResource("jetm-mytest.xml");
try {
XmlEtmConfigurator.configure(new FileInputStream(url.getPath()));
if (!profiler.isStarted())
profiler.start();
} catch (FileNotFoundException fne) {
log.warn(fne.getMessage());
}
}</pre>
<p>Add the jetm-mytest.xml file in your classpath like in red5/conf or in MyTest/WEB-INF/lib. The xml file look like something like that :</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE jetm-config PUBLIC "-// void.fm //DTD JETM Config 1.2//EN"
"http://jetm.void.fm/dtd/jetm_config_1_2.dtd"&gt;

&lt;jetm-config timer="sun"&gt;

&lt;aggregator-chain&gt;

&lt;chain-element class="etm.core.aggregation.BufferedTimedAggregator"&gt;
&lt;!-- Set aggregation interval to 1 second --&gt;
&lt;property name="aggregationInterval"&gt;1000&lt;/property&gt;
&lt;/chain-element&gt;

&lt;chain-element class="etm.contrib.aggregation.log.CommonsLoggingAggregator"&gt;
&lt;!-- Set commons-logging log category --&gt;
&lt;property name="logName"&gt;etm-result&lt;/property&gt;
&lt;/chain-element&gt;

&lt;chain-root class="etm.core.aggregation.persistence.PersistentRootAggregator"&gt;
&lt;property name="aggregationInterval"&gt;10000&lt;/property&gt;
&lt;/chain-root&gt;

&lt;/aggregator-chain&gt;

&lt;extension&gt;
&lt;plugin class="etm.contrib.console.HttpConsoleServerPlugin"&gt;
&lt;property name="listenPort"&gt;40000&lt;/property&gt;
&lt;property name="expanded"&gt;true&lt;/property&gt;
&lt;property name="worker-size"&gt;3&lt;/property&gt;
&lt;/plugin&gt;
&lt;/extension&gt;

&lt;/jetm-config&gt;</pre>
<p>That&#8217;s it, now when you want to collect the statistic in one of your method or in a specific process you can just do something like that :</p>
<pre class="brush:java">public void MyMethod() {

EtmPoint point = profiler.createPoint(getClass().getName()+"#MyMethod");

... Your stuff ...

point.collect();

}</pre>
<p>All this is a succinct introduction, you can go further and do some amazing things. JETM is a really powerful tool to improve your application performance.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F06%2F08%2Fjetm-the-easy-way-to-monitor-your-spring-application%2F&amp;title=JETM+-++The+easy+way+to+monitor+your+Spring+Application" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F06%2F08%2Fjetm-the-easy-way-to-monitor-your-spring-application%2F&amp;title=JETM+-++The+easy+way+to+monitor+your+Spring+Application" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F06%2F08%2Fjetm-the-easy-way-to-monitor-your-spring-application%2F&amp;title=JETM+-++The+easy+way+to+monitor+your+Spring+Application" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F06%2F08%2Fjetm-the-easy-way-to-monitor-your-spring-application%2F&amp;headline=JETM+-++The+easy+way+to+monitor+your+Spring+Application" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=JETM+-++The+easy+way+to+monitor+your+Spring+Application&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F06%2F08%2Fjetm-the-easy-way-to-monitor-your-spring-application%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=JETM+-++The+easy+way+to+monitor+your+Spring+Application&amp;u=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F06%2F08%2Fjetm-the-easy-way-to-monitor-your-spring-application%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=JETM+-++The+easy+way+to+monitor+your+Spring+Application&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F06%2F08%2Fjetm-the-easy-way-to-monitor-your-spring-application%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=JETM+-++The+easy+way+to+monitor+your+Spring+Application&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F06%2F08%2Fjetm-the-easy-way-to-monitor-your-spring-application%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=JETM+-++The+easy+way+to+monitor+your+Spring+Application&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F06%2F08%2Fjetm-the-easy-way-to-monitor-your-spring-application%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F06%2F08%2Fjetm-the-easy-way-to-monitor-your-spring-application%2F&amp;title=JETM+-++The+easy+way+to+monitor+your+Spring+Application&amp;summary=&amp;source=" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F06%2F08%2Fjetm-the-easy-way-to-monitor-your-spring-application%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fwww.shell-tips.com%2F2009%2F06%2F08%2Fjetm-the-easy-way-to-monitor-your-spring-application%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fwww.shell-tips.com%2F2009%2F06%2F08%2Fjetm-the-easy-way-to-monitor-your-spring-application%2F" ><img class="lightsocial_img" src="http://www.shell-tips.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://www.shell-tips.com/2009/06/08/jetm-the-easy-way-to-monitor-your-spring-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
