<?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>Gridshore &#187; beet</title>
	<atom:link href="http://www.gridshore.nl/tag/beet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gridshore.nl</link>
	<description>A weblog about software engineering, Architecture, Technology an other things we like.</description>
	<lastBuildDate>Tue, 13 Dec 2011 15:36:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Analyzing beet results with groovy</title>
		<link>http://www.gridshore.nl/2009/11/20/analyzing-beet-results-with-groovy/</link>
		<comments>http://www.gridshore.nl/2009/11/20/analyzing-beet-results-with-groovy/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 20:27:32 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[groovy and grails]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[beet]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[jfreechart]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=931</guid>
		<description><![CDATA[<p>The recent weeks I have been playing around with grails. When working with grails you have to learn groovy as well. Sometimes I am just amazed by the easiness of doing things with groovy. That is why I started out using groovy for a very small project (at least with groovy) to analyze an [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.gridshore.nl/wp-content/uploads/logo_groovy.png" alt="logo_groovy.png" border="0" width="203" height="100" align="left" />The recent weeks I have been playing around with grails. When working with grails you have to learn groovy as well. Sometimes I am just amazed by the easiness of doing things with groovy. That is why I started out using groovy for a very small project (at least with groovy) to analyze an xml file as generated by the <a href="http://beet.sourceforge.net/">performance measurement framework Beet</a>.</p>
<p>In this blog post I go step-to-step through a solution that analyzes the xml file and plots the results in a chart generated with <a href="http://www.jfree.org/jfreechart/">jfreechart</a>.</p>
<p><span id="more-931"></span><br />
<h2>Introduction</h2>
<p><img src="http://www.gridshore.nl/wp-content/uploads/Screen-shot-2009-11-20-at-8.20.15-PM.png" alt="Screen shot 2009-11-20 at 8.20.15 PM.png" border="0" width="219" height="71" align="right" />In one of my previous posts I have discussed a nice framework for easy performance measurement called Beet. You can find this post here: <a href="http://www.gridshore.nl/2009/09/01/using-beet-to-monitor-your-spring-framework-application/">Using beet to monitor your (springframework) application</a>. The result of a monitor session with beet can be an xml file. Nice, but how do you analyze this file? By hand? No way, you need a tool. Excel or Numbers can be fine, but it can be a lot faster. Therefore I decided to create a small groovy application.</p>
<p>The first requirement for me was very easy, read the events in the xml file and calculate the average of all events of a certain type. I asked a few of my collegues about their estimated effort when having to do it in java. They varied from 1 hour (pretty optimistic) to half a day. Curious how much time it took me?</p>
<h2>First iteration</h2>
<p>The first iteration was to calculate the overall average, an optimist of 2 hour java work. First you locate the file, than you <em>slurp</em> the xml out of the file. With the xml file in your hand, you obtain all events with a child element type with the value <em>method</em>. The following code block shows these three lines of code, yes for real, three lines.</p>
<pre class="brush: groovy; title: ; notranslate">
def file = new File(&quot;beet-integration-web-perf.xml&quot;)
def xml = new XmlSlurper().parse(file)
def methodEvents = xml.event.findAll {it.type == &quot;method&quot;}
</pre>
<p>The next step is to take all durations from the found events. Using these durations, calculating the average is very easy.</p>
<pre class="brush: groovy; title: ; notranslate">
def file = new File(&quot;beet-integration-web-perf.xml&quot;)
def xml = new XmlSlurper().parse(file)
def methodEvents = xml.event.findAll {it.type == &quot;method&quot;}
def durations = methodEvents*.&quot;duration-ms&quot;
println &quot;Average duration is ${durations.sum {it.toBigDecimal()} / durations.size()}&quot;
</pre>
<p>That is it, this took me 10 minutes. And yes for 5 lines of code that is still a lot, but cut me some slag man, I am still learning groovy <img src='http://www.gridshore.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  . What I forgot to mention is that I use the groovyConsole to create and run the application.</p>
<h2>Second iteration</h2>
<p>The total average is nice, but with hundreds of measurements, not very useful. Of course we want more information on the data. To stretch myself a little bit, I had the idea to take the average of each minute and print that on screen. The next code block does just that, it calculates the averages of all measurements in the same minute and prints the result on the screen. When reading the code, take this tip. We create an array with all durations for each minute and put the result in a map with the minute as a key and the array with durations as a value.</p>
<pre class="brush: groovy; title: ; notranslate">
def averages = [:]
def start = methodEvents[0].start.text()[0..16]
def minuteItems = []
methodEvents.each {
    def duration = it.&quot;duration-ms&quot;.toBigDecimal()
    def currentStart = it.start.text()[0..16]

    if (start == currentStart) {
        minuteItems.add duration
    } else {
        averages.put ((start),minuteItems)
        minuteItems = [duration]
        start = currentStart
    }
}

averages.each {key,value -&gt;
    println &quot;Minute : ${key} has average duration of ${value.sum {it.toBigDecimal()} / value.size()}&quot;
}
</pre>
<h2>Third and final iteration</h2>
<p>Having this data written to the screen is oke, but a nice graph would be even better. For this I used a <a href="http://groovy.codehaus.org/Plotting+graphs+with+JFreeChart">sample I found via google</a>. Since the code is pretty straightforward, I just copy it in here.</p>
<pre class="brush: groovy; title: ; notranslate">
def dataset = new DefaultCategoryDataset()
dataset.with{
    avarages.each {key,values -&gt;
    def value = (values.sum {it.toInteger()} / values.size())
        addValue value , &quot;average&quot;, key[-3..-1]
    }
}

def labels = [&quot;Registered events total ${methodEvents.size()}&quot;, &quot;Minute&quot;, &quot;Average&quot;]
def options = [true, true, true]
def chart = ChartFactory.createLineChart(*labels, dataset,Orientation.VERTICAL, *options)
def swing = new SwingBuilder()
def frame = swing.frame(title:'Groovy LineChart',
        defaultCloseOperation:WC.EXIT_ON_CLOSE) {
    panel(id:'canvas') { widget(new ChartPanel(chart)) }
}
frame.pack()
frame.show()
</pre>
<p>For those java people, check the way you can work with arrays in line 5. Counting from the end of the array, nice.</p>
<p>The result is shown in the next image.</p>
<p><img src="http://www.gridshore.nl/wp-content/uploads/Screen-shot-2009-11-20-at-9.20.31-PM.png" alt="Screen shot 2009-11-20 at 9.20.31 PM.png" border="0" width="770" height="532" /></p>
<p>That is about it, just two last things. First you need to add two jars to the classpath of groovy: jcommon-1.0.16.jar, jfreechart-1.0.13.jar. These are in the jfreechart download package. I used the mechanism to create a folder .groovy/lib in your root and add the jars to that folder.</p>
<p>The other thing I wanted to mention is the option to create a shell script from groovy. Just add the following line at the top and make your file executable and you are good to go.</p>
<pre>
#!/usr/bin/env groovy
</pre>
<p>That is it, in total 2 hours of work, not bad I think for a beginner in groovy with access to google. If you are good at groovy and you spot improvements, please let me know, I am eager to learn more.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F11%2F20%2Fanalyzing-beet-results-with-groovy%2F&amp;title=Analyzing%20beet%20results%20with%20groovy&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/11/20/analyzing-beet-results-with-groovy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using Beet to monitor your (spring framework) application</title>
		<link>http://www.gridshore.nl/2009/09/01/using-beet-to-monitor-your-spring-framework-application/</link>
		<comments>http://www.gridshore.nl/2009/09/01/using-beet-to-monitor-your-spring-framework-application/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 20:07:28 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[beet]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[profiling]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=875</guid>
		<description><![CDATA[<p>As a programmer you are writing code. As a designer you are creating solid designs and if you are wise, the code is a good reflection of your design. My previous post was about Domain Driven Design. One of the things I want to repeat is the strong relation between the domain, the design [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.gridshore.nl/wp-content/uploads/beet-logo.png" alt="beet-logo.png" border="0" width="225" height="72" align="left" />As a programmer you are writing code. As a designer you are creating solid designs and if you are wise, the code is a good reflection of your design. My previous post was about Domain Driven Design. One of the things I want to repeat is the strong relation between the domain, the design and the code. The best way to accomplish this is to combine the role of designer and implementer. That way you get the best representation of the domain in your solution.</p>
<p>Why this introduction, when I promised to write about performance and monitoring? For performance I see the same relationship. A tester creates the test plan, including the performance test. If you are lucky requirements for monitoring are available as well. Ok, I do not want to combine the role of tester and developer. Still they should both have a very good idea about what the other one does and how you can help each other. Real performance testing is hard and should not be taken to light. Monitoring however can be done on a low level during development. How often have you written log statements like: <em>This method X is executed</em>. Sometimes with a start and end time. Some of you might have used there own aspects to be non intrusive and other might have used a framework.</p>
<p>This blog post is about using a framework to do basic performance measurement and monitoring. The framework I am going to discuss is the <a href="http://beet.sourceforge.net/">Beet framework</a>.</p>
<p><cite>Beet records user behavior and performance data for your Spring-based Java application.  It can thus help you to analyze usage patterns and research production performance issues.</cite></p>
<p>Read on to learn about my experiences with the framework and why I like it to do some basic monitoring.</p>
<p><span id="more-875"></span><br />
<h3>What does it do?</h3>
<p>I am not going to enlist all features, go to the website to find out what it can do for you. Here are some of the features that I like:</p>
<ul>
<li>Very nice integration with spring framework including namespace support.</li>
<li>Manager that does logging of events using a memory and flush mechanism.</li>
<li>Easy configuration to write the logs to disk or database.</li>
<li>Use a binary format for events that is very condensed together with utilities to generate readable xml, csv or database inserts.</li>
<li>Easy http-request monitoring</li>
<li>JMX integration, switching monitoring on and off</li>
<li>Good user manual and well written and documented code.</li>
</ul>
<h3>What does it look like?</h3>
<p>I am using the code of yourscrum to experiment with Beet. <a href="http://code.google.com/p/your-scrum/source/checkout">Check out the code </a>if you want to follow a long.<a href="http://code.google.com/p/your-scrum/source/checkout"><img src="http://www.gridshore.nl/wp-content/uploads/yourscrum_logo.png" alt="yourscrum_logo.png" border="0" width="66" height="81" align="right" /></a></p>
<p>Before you can use Beet, you have to download it. Luckily it is available in a maven repository. More information about the repository and the dependency can be found on the <a href="http://beet.sourceforge.net/downloads">beet download page</a>. For my sample I only included the beet artifact. I downloaded the utils (more on those later) as a tar file. You can find the downloads here: <a href="http://sourceforge.net/projects/beet/files/">http://sourceforge.net/projects/beet/files/</a>.</p>
<p>Now we have Beet available, we should add the namespace defintion to the spring configuration and the first very basic tracking manager to track all http-requests.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
       xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
       xmlns:bt=&quot;http://www.mantis-tgi.com/schema/bt/1.1&quot;
       xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot;
       xsi:schemaLocation=&quot;
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
            http://www.mantis-tgi.com/schema/bt/1.1 http://www.mantis-tgi.com/schema/bt/mtgi-bt-1.1.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd&quot;&gt;

    &lt;bean class=&quot;org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&quot;/&gt;
	...
    &lt;bt:manager id=&quot;defaultTrackingManager&quot;
                application=&quot;yourscrum&quot;
                register-mbeans=&quot;false&quot;
                flush-schedule=&quot;0/30 * * * * ?&quot;&gt;
        &lt;bt:xml-persister binary=&quot;true&quot; compress=&quot;true&quot; file=&quot;${log.dir}/beet-yourscrum-perf.xml&quot;/&gt;
        &lt;bt:http-requests parameters=&quot;dispatch&quot;/&gt;
    &lt;/bt:manager&gt;
	...
&lt;/beans
</pre>
<p>There are a few things to learn from this confguration. First that we are logging in a binary format and compressed. This is not handy when you are trying to read the logs at runtime. Therefore you have the option to change this. The result is a nice readable XML formatted file. Other interesting things are the http_request configuration and the flush schedule. The flush schedule is used to cache logs and send them to the file only every 30 seconds in our case.</p>
<p>If you choose for the binary format, you need to use the beet-utils to extract the data into a csv file, readable xml or database calls. There is a basic command that you can use to uncompress and transform the data.</p>
<pre>
gzcat ./beet-yourscrum-perf.bxml.gz  | java -jar /path/to/beet-utils.jar -tool csv > result.csv
</pre>
<p>The *.bxml.gz is the binary data file. Beware that the original documentation explains the use of zcat. For me on the mac I had to use the older gzcat tool. But the commands are the same. The following image shows the results in csv format.</p>
<p><a href="http://www.gridshore.nl/wp-content/uploads/Screen-shot-2009-08-30-at-09.19.53.png" rel="lightbox"><img src="/wp-content/uploads/Screen-shot-2009-08-30-at-09.19.53-150x150.png" alt="Screen shot 2009-08-30 at 09.19.53.png" border="0" width="150" height="150" align="right" /></a></p>
<p>Next up is to configure method access.</p>
<h3>Can we monitor method calls?</h3>
<p>Of course we can track method calls. Actually Beet makes it very easy for you. The manager namespace has an attribute called track-method-expression. You can provided it with any pointcut expression and you are done.</p>
<p>There are two buts when using pointcuts. But 1, you want to use one tracking manager but multiple pointcuts. One to monitor services and one to monitor controllers. Beet provides a mechanism to create separate advisors and pointcuts. There is a small bug in the 1.4.0-b3 release that prevents your from using this though. But 2, think about the way spring treats multiple configuration files. One loaded by the web context (servlet) and the other by the application context (listener). Pointcuts can not overcome these context boundaries, therefore we need multiple tracking managers at the moment.</p>
<p>The code looks like this, check thetrack-method-expression</p>
<pre class="brush: xml; title: ; notranslate">
&lt;bt:manager id=&quot;webTrackingManager&quot;
            application=&quot;yourscrum&quot;
            register-mbeans=&quot;false&quot;
            track-method-expression=&quot;execution(* org.yourscrum.web.story.*Controller.*(..))&quot;
            flush-schedule=&quot;0/30 * * * * ?&quot;&gt;
    &lt;bt:xml-persister binary=&quot;true&quot; compress=&quot;true&quot; file=&quot;${log.dir}/beet-yourscrum-web-perf.xml&quot;/&gt;
    &lt;bt:http-requests parameters=&quot;dispatch&quot;/&gt;
&lt;/bt:manager&gt;
</pre>
<h3>Are there other things to monitor?</h3>
<p>Beet does provided some other helpful beans to monitor your application. A nice one is the datasource monitor. Very easy to configure. Just add an attribute to the datasource configuration. You can look at the following code block for an example. After that there is again an image with some sample csv data.</p>
<pre class="brush: xml; title: ; notranslate">
    &lt;bean id=&quot;dataSource&quot; class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;
          bt:tracking-manager=&quot;serviceTrackingManager&quot;&gt;

        &lt;property name=&quot;driverClassName&quot; value=&quot;${jdbc.driverclass}&quot;/&gt;
        &lt;property name=&quot;url&quot; value=&quot;${jdbc.url}&quot;/&gt;
        &lt;property name=&quot;username&quot; value=&quot;${jdbc.username}&quot;/&gt;
        &lt;property name=&quot;password&quot; value=&quot;${jdbc.password}&quot;/&gt;
    &lt;/bean&gt;
</pre>
<p><a href="http://www.gridshore.nl/wp-content/uploads/Screen-shot-2009-09-01-at-22.04.57.png" rel="lightbox"><img src="/wp-content/uploads/Screen-shot-2009-09-01-at-22.04.57-150x150.png" alt="Screen shot 2009-09-01 at 22.04.57.png" border="0" width="150" height="150" align="right" /></a></p>
<h3>What could be improved?</h3>
<p>Before I sound to negative I do like to mention that Jason responded fast to the issues I found. Still others can find them as well, let&#8217;s help Jason to fix the issues and improve the project. I think it is worth it.</p>
<ul>
<li>Problem configuring pointcuts and separate advise. The manager accepts an pointcut expression for tracking method calls. It is also possible to create you own pointcuts and combine them with existing pointcuts. That way you can combine it with transaction creation for instance. The fix does not look very hard, the issue is logged.</li>
<li>Problems logging to one file with one manager when the spring configuration is split up into multiple files and multiple contexts loaded by the servlet and the listener. To create a solution for this problem we need the pointcut option as mentioned in the previous point and preferably a separate bean for the http-request listener that is connected to the tracking manager at the moment. The issues are mentioned and a solution will be created.</li>
<li>The last point depends on your taste, to me it is a big problem. The project uses GIT for source control. I had never worked with it and needed to configure it on my machine to extract the sources from the repository. But the bigger problem is ant and ivy. Man I do not like this. I just love the maven integration in my IDE and the project setup. This project is not easy to open in a real IDE like intellij. But again, that is a matter of taste.</li>
</ul>
<h3>Conclusion</h3>
<p>I can say I am going to experiment more with this framework. It looks very promising. A few small issues need to be fixed. I am planning on using it for a bit bigger project to see how it holds up.</p>
<p>I am curious to learn from you about the frameworks that you use for performance testing and monitoring. Drop me a line or a comment.</p>
<p><br/><br />
<SCRIPT charset="utf-8" type="text/javascript" src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&#038;MarketPlace=US&#038;ID=V20070822/US/gridshore-20/8001/076b4862-1936-4847-9233-5a2c07bfc4c4"> </SCRIPT> <NOSCRIPT><A HREF="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&#038;MarketPlace=US&#038;ID=V20070822%2FUS%2Fgridshore-20%2F8001%2F076b4862-1936-4847-9233-5a2c07bfc4c4&#038;Operation=NoScript">Amazon.com Widgets</A></NOSCRIPT></p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F09%2F01%2Fusing-beet-to-monitor-your-spring-framework-application%2F&amp;title=Using%20Beet%20to%20monitor%20your%20%28spring%20framework%29%20application&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/09/01/using-beet-to-monitor-your-spring-framework-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

