Tuesday, January 26, 2010

Customizing JMX Reporter

JMX Reporter is a Coherence utility that generates statistical logs about nodes, networks, memory, proxy and cache usage. If enabled (-Dtangosol.coherence.management.report.autostart=true) by default every minute it prints these statistical logs and every hour creates a new set of files. What if we need to customize it?

  1. Easiest is to unzip coherence.jar and extract reports directory. This is what we would customize by putting in the classpath before coherence.jar
  2. Edit report-group.xml to change the frequency and the location where these reports should be created.
  3. Configure the <report-list> to have a list of <report-config> for the reports we want to have. The report-config takes a location of where the configuration of a specific type is defined.
  4. Copy the report configurations in the directory as defined in the report-group.xml
Following is a sample of report-group.xml under reports/ directory that prints memory status and network health reports at a frequency of 10mins:
<report-group>
<frequency>10m<</frequency>
<output-directory>../StatisticalReports</output-directory>
<report-list>
<report-config>
<location>reports/report-memory-status.xml</location>
</report-config>
<report-config>
<location>reports/report-network-health.xml</location>
</report-config>
</report-list>
</report-group>
reports/report-memory-status.xml and reports/report-network-health.xml has a list of respective attributes to be reported. Each report-config sets the file-name and the delimiter typically set as {date}-<stat-name>.txt and {tab} respectively. The report generated are CSV files that can be opened in MS Excel or Openoffice and historically analyzed. What if at the end of the day you want to open in Excel and analyze it? Following is a simple shell script that concatenates the reports appropriately (by removing repeated headers) and names it aggregate-<report-type>.xls:
#!/bin/bash
p=0;
k=`ls *$1.txt 2>/dev/null | wc -l`
if [[ $k == 0 ]]
then echo "Valid types are: ";
echo -e "\tmemory-status";
echo -e "\tnetwork-health";
exit;
else
for i in `ls --sort time -r *$1.txt`
do
if [[ $p == 0 ]]
then
cat $i >> aggregate-$1.xls;
p=1;
else
sed '1d' $i | cat >> aggregate-$1.xls
fi
done
dos2unix aggregate-$1.xls
fi
Enjoy!

2 comments:

prabhakar said...

nice post.i have a question,
I want to generate the report daily once ( as you mentioned it creates each hour), any idea how to do that?

prabhakar said...

Thanks for sharing this. i have one doubt,
how can i configure the report file creation in a daily basis? (not in hour basis).

Reply to this would be really appreciated.

Thanks!