Message-ID: <2035052293.617.1369176756674.JavaMail.email@example.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_616_1123375010.1369176756673" ------=_Part_616_1123375010.1369176756673 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
This is the getting started guide for the Generic Statistics (gstatistic= s) component of the grepo framework. It's not supposed to be a complete ref= erence manual - the goal is to show a basic usage and configuration scenari= o of grepo's gstatistics component. If you have problems understanding part= s of this guide or the framework in general or if you have any suggestions,= good ideas or if you have found potential bugs please let us know. So let'= s get started!
This is the getting started guide for the Generic Statistics (gstatistic= s) component of the grepo framework version 1.5.x.
The demo project for this guide can be checked out from our SVN reposito= ry as follows:
The demo project is a maven project and we highly recommend that you use= maven to set up the project. If you don't want to use maven you can also s= et up the project manually. If you use maven and eclipse you can easily mak= e an eclipse project using the following command in the demo project's root= directory:
You can now import the project in your eclipse workspace.
After you have imported the project you should now be able to run the
The teeny-weeny demo application consists of one interface (MyServic= e) and a class implementing the interface (MyServiceImpl). Th= e method doSomething1() makes use of grepo's MethodStatistics<= /em> annotation. Method doSomething2() demonstrates how to use gre= po's StatisticsManager directly.
Note: In the demo project we use the gstatistics compon= ent to track statistics of method executions. However its also possible to = track statistics for various executions (not just method executions), e.g. = tracking statistics of entire business processes etc.
In order to use the gstatistics component you need the following grepo a= rtifacts (jars) in your project's classpath:
Somewhere in your Spring application context (xml) you have to import th= e default configuration of the grepo gstatistics component.
In the demo project this is done in src/main/resources/META-INF/spri= ng/application-context.xml. Note that you may not need to import that = file if you decide to setup grepo with special/custom configuration - you c= ould for instance configure the required "grepo" beans d= irectly in your application context.
Furthermore we use spring's component-scan feature in order to create a = (spring) bean for our MyServiceImpl class - this is standard sprin= g configuration. Additionally we use grepo's SimpleStatisticsCollection= Printer which is used to print out summary and details about collected= statistics. (Using the SimpleStatisticsCollectionPrinter is optio= nal, but we use its handy methods in our MyServiceTest class to pr= int out some information about collected statistics):
That's it, you are now ready to collect statistics using the grepo fram= ework!
When running test-method from MyServiceTest you should get a su= mmary output similar to the following:
This output is produced by grepo's SimpleStatisticsCollection p= rinter using the printSummary() method. We can see that we have 1 = collection entry, which is displayed in the line below. We read the line as= follows: The identifier for the collection entry is 'demo.service.MySe= rvice.doSomething1' and there were 10 invocations for that identifier.= The minimum duration was 10 milliseconds, the maximum duration was 476 mil= liseconds, and the average duration is 275 milliseconds.
You should also see detail output similar to the following:
Here we can see the details about the collection entry with the identifi= er 'demo.service.MyService.doSomething1'. This output is produced = by grepo's SimpleStatisticsCollection printer using the printD= etail() method. At the top of the output we see the summary f= or the collection entry (invocations, min-duration, max-duration, average-d= uration). Then we see five the top durations (including details) that is in= vocations which had the longest execution duration. And finally we see the = 10 recent invocations (including details).
The identifier for the collection entry is generated automatically using= an instance of org.codehaus.grepo.statistics.service.StatisticsEntryId= entifierGenerationStrategy. In the default configuration grepo uses an= instance of org.codehaus.grepo.statistics.service.StatisticsEntryIdent= ifierGenerationStrategyImpl - this implementation generates identifier= s as follows:
Feel free to provide your own implementation if desired.
You can also use the identifier attribute of grepo's Method= Statistics annotation. Doing so grepo won't use the StatisticsEntr= yIdentifierGenerationStrategy at all. When using the StatisticsMan= ager directly (as demonstrated in MyServiceImpl.doSomething2()) then you have to provide an appropriate identifier anyway, so grepo won'= t use the StatisticsEntryIdentifierGenerationStrategy in that case= .
The StatisticsManager uses a org.codehaus.grepo.statistics.= collection.StatisticsCollectionStrategy for collecting statistics. In = the default configuration grepo uses an instance of org.codehaus.grepo.= statistics.collection.InMemoryStatisticsCollectionStrategy which store= s collections entries in memory using an instance of org.codehaus.grepo= .statistics.collection.StatisticsCollection. Feel free to provide your= own implementation(s) if desired.
The org.codehaus.grepo.statistics.collection.StatisticsCollectionImp= l holds all collection entries - grepo's SimpleStatisticsCollectio= nPrinter uses a StatisticsCollection instance for printing ou= t summary and details. Because grepo stores collection entries in memory by= default, there are two properties for the StatisticsCollectionImpl which should be configured appropriately to avoid wasting of memory:
We have already used grepo's SimpleStatisticsCollectionPrinter = in the examples above. This class is appropriately annotated so that it is = easy to export instances of this class to a JMX server using springs MB= eanExporter as follows:
The gquery and gprocedure components of the grepo framework can be easil= y configured for statistics. See the getting started guides for the Generic= Query (Hibernte/Jpa) and Generic Procedure components for details.------=_Part_616_1123375010.1369176756673--