JVM Statistics

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
equick
Cacti User
Posts: 72
Joined: Wed Jun 14, 2006 4:31 am
Contact:

JVM Statistics

Post by equick »

Hi,

I have created a cacti template for monitoring JVM statistics based on jstat (which comes with the Sun/Oracle JDK) . I am using Cacti 0.8.7g.

Hopefully this is useful and people like it. If anything looks wrong or enhancements are required, feel free to let me know.
This template works on both Windows and Linux, although the Windows version requires the Windows resource kit and PsExec.exe, not to mention Perl

Please see the
README.txt
(4.42 KiB) Downloaded 635 times
for further instructions to set the up graphs.

Changelog
=========

As of version 1.3 I have made some changes which make use of jstatd and rmi. This will hopefully help out the windows users who might not necessarily have ssh.

* Added two scripts ssh_jstat.pl and rmi_jstat.pl either of which can be used depending on whether you want collect remote stats over rmi or ssh. These go into the cacti scripts directory. Both of these work on windows or linux, although windows users will probably be better off using the rmi method.

* Added service scripts to run jstatd as a service on windows or linux.

* In the case of ssh this shouldn't be an issue, but if you choose RMI (which is the default in the template) and there is a firewall between the cacti server and the jstatd server you are querying, I have provided some configuration in rmi_jstat.pl which will route rmi calls via a proxy tunnel.

jstat_cacti_template_v1.3.zip
(30.31 KiB) Downloaded 660 times
MD5: dda8fc50eaad68983cb2e0c8ff986666

Thanks,

Ed.

jstatGraphs.png
jstatGraphs.png (241.82 KiB) Viewed 10900 times
Last edited by equick on Sat Aug 13, 2011 11:41 am, edited 19 times in total.
equick
Cacti User
Posts: 72
Joined: Wed Jun 14, 2006 4:31 am
Contact:

Re: JVM Statistics

Post by equick »

I have tested importing this template on a fresh install of cacti 0.8.7g and it worked fine without any issues.
Last edited by equick on Mon Jun 27, 2011 4:15 pm, edited 1 time in total.
equick
Cacti User
Posts: 72
Joined: Wed Jun 14, 2006 4:31 am
Contact:

Re: JVM Statistics

Post by equick »

Uploaded jstat cacti template v1.1 (download above).
The graphs are hopefully looking a bit better now and the capacity graphs show utilization too.
mrloon
Posts: 14
Joined: Wed May 31, 2006 10:11 pm

Re: JVM Statistics

Post by mrloon »

What would need to be updated in the code for this to work in a Windows environment calling other Windows servers JVMs? In my environment, I have a number of Tomcat servers running on Windows that I would like to collect this information from their VM's also.
equick
Cacti User
Posts: 72
Joined: Wed Jun 14, 2006 4:31 am
Contact:

Re: JVM Statistics

Post by equick »

mrloon wrote:What would need to be updated in the code for this to work in a Windows environment calling other Windows servers JVMs? In my environment, I have a number of Tomcat servers running on Windows that I would like to collect this information from their VM's also.
Hi, thanks for your post. I will try to look at this tonight or as soon as possible. It shouldn't be too hard if you are able to run the jdk utility jps (it will be in the same location as jstat). This will list the java processes, or you can try 'jps -l' to get a longer listing.
The tricky part might be if you can't ssh from your cacti server to other windows hosts? I think I know the answer to that. :wink:

* I should have spotted this before but in fact there's an easy and perhaps better way round the ssh issue, and that is to use jstatd which is specifically meant for remote jstat calls, although bear in mind the security aspect of it too. I will put together a jstatd server control script and add this to the template.

This is now done (in version 1.3)
Last edited by equick on Sun Jul 24, 2011 5:18 am, edited 5 times in total.
equick
Cacti User
Posts: 72
Joined: Wed Jun 14, 2006 4:31 am
Contact:

Re: JVM Statistics

Post by equick »

Hi,

I have updated the jstat.pl script to run on both Linux and Windows now.

For Windows I tested this using Strawberry Perl 5.12.3.0 and jdk 1.6.0_26.

Here is the script:
jstat.pl
(3.35 KiB) Downloaded 210 times
and expected output:

Code: Select all

C:\Documents and Settings\Edward\My Documents\Downloads\jstat_cacti_template_v1.1\jstat_cacti_template>perl jstat.pl Bootstrap
NGCMN:5440.0 NGCMX:87360.0 NGC:5504.0 S0CMX:512.0 S0C:512.0 S1CMX:8704.0 S1C:512.0 ECMX:69952.0 EC:4480.0 YGC:17 OGCMN:1
0944.0 OGCMX:174784.0 OGC:10944.0 OC:10944.0 FGC:2 FGCT:1.508 GCT:1.685 YGCT:0.177 PGCMN:12288.0 PGCMX:65536.0 PGC:12288
.0 PC:12288.0 EU:390.8 OU:6086.9 PU:11340.0 S0U:0.0 S1U:0.0 TT:1 MTT:15 DSS:256.0 E:8.72 O:55.62 P:92.28 Loaded:1749 Loa
dedBytes:2385.6 Unloaded:0 UnloadedBytes:0.0 ClassTime:7.93 Compiled:702 Failed:0 Invalid:0 CompilerTime:0.85
If you are using a different JDK or Perl, you will have to update the path settings but hopefully this should be fairly intuitive. If you get any issues, let me know.

Cheers,

Ed.
equick
Cacti User
Posts: 72
Joined: Wed Jun 14, 2006 4:31 am
Contact:

Re: JVM Statistics

Post by equick »

One of the annoying things about Cacti is that it generates multiple copies of the same rrd file when creating graphs using the same data template. At least that's what it does in the case of this JVM Statistics template, which has the potential to waste a lot of space.

I have written a perl script that will keep one of the associated rrd files created for a monitored java process, remove the copies and update this in the cacti database.
consolidate_rrds.pl
(3.81 KiB) Downloaded 167 times
The code should work on both Windows and Linux, alas it has one dependency which is the perl module DBD::MySQL. However that shouldn't be a problem if you're using Strawberry perl on Windows as it's preinstalled. If you use Redhat, then just run 'sudo yum install perl-DBD-MySQL'.

To run this script, the user needs to first update the config section at the top of the script.

Code: Select all

######### config section ####################

$database='cacti';
$host='db';
$port='3306';
$user='testcacti';
$password='testcacti';
$rrapath='/usr/share/cacti/rra';

######### end of config #####################
The script is invoked with the following arguments:

Code: Select all

Usage:

consolidate_rrds.pl <hostname> <description> <dsname>

Example: consolidate_rrds.pl javahost "java process" jstat_java_process
This will delete all but one RRD file associated with the java process running on javahost and rename it to jstat_java_process.rrd
Note that values for hostname and description need to match the device fields as displayed under Console->Devices
This is the expected output. Note that the filenames are all similar except for the digits, and the sizes are all the same too:

Code: Select all

[cactiadmin@cactiserver]$ ./consolidate_rrds.pl java "java process" java_process

Consolidate the following RRDs into one file: /usr/share/cacti/rra/java_process.rrd?

data_template_data.id   filename                                        size(bytes)
882                     /usr/share/cacti/rra/java_process_ngc_714.rrd   2145616    
883                     /usr/share/cacti/rra/java_process_ngc_715.rrd   2145616    
884                     /usr/share/cacti/rra/java_process_ngc_716.rrd   2145616    
885                     /usr/share/cacti/rra/java_process_ngc_717.rrd   2145616    
886                     /usr/share/cacti/rra/java_process_ngc_718.rrd   2145616    
887                     /usr/share/cacti/rra/java_process_ngc_719.rrd   2145616    
888                     /usr/share/cacti/rra/java_process_ngc_720.rrd   2145616    
889                     /usr/share/cacti/rra/java_process_ngc_721.rrd   2145616    
890                     /usr/share/cacti/rra/java_process_ngc_722.rrd   2145616    
891                     /usr/share/cacti/rra/java_process_ngc_723.rrd   2145616    
892                     /usr/share/cacti/rra/java_process_ngc_724.rrd   2145616    
893                     /usr/share/cacti/rra/java_process_ngc_725.rrd   2145616    
894                     /usr/share/cacti/rra/java_process_ngc_726.rrd   2145616    
895                     /usr/share/cacti/rra/java_process_ngc_727.rrd   2145616    
896                     /usr/share/cacti/rra/java_process_ngc_728.rrd   2145616    
897                     /usr/share/cacti/rra/java_process_ngc_729.rrd   2145616    
898                     /usr/share/cacti/rra/java_process_ngc_730.rrd   2145616    
899                     /usr/share/cacti/rra/java_process_ngc_731.rrd   2145616    
900                     /usr/share/cacti/rra/java_process_ngc_732.rrd   2145616    
901                     /usr/share/cacti/rra/java_process_ngc_733.rrd   2145616    
902                     /usr/share/cacti/rra/java_process_ngc_734.rrd   2145616    
903                     /usr/share/cacti/rra/java_process_ngc_735.rrd   2145616    
904                     /usr/share/cacti/rra/java_process_ngc_736.rrd   2145616    
905                     /usr/share/cacti/rra/java_process_ngc_737.rrd   2145616    

Answer [y/n]: y

Congratulations! You just saved 48MB space.
If you don't want to proceed, or if the output looks wrong, just type 'n' and the program will exit as follows:

Code: Select all

Answer [y/n]: n
Exiting. No database or file changes made.
If you try rerunning the script, it should report that the consolidation has already been done:

Code: Select all

[cactiadmin@cactiserver ~]# ./consolidate_rrds.pl java "java process" java_process

It looks like the datasource (/usr/share/cacti/rra/java_process.rrd) may already be consolidated.
After running the script you may need to rebuild the poller (under Console->Utilities) to pick up the changes. I had to do this when I noticed my graphs weren't updating.

There is potential to use this script for other templates such as Apache Statistics although I haven't tested it on that yet. Lastly it goes without saying, but before running the script please ensure you have an up to date back up of your RRDs and Database.

Cheers,

Ed.
equick
Cacti User
Posts: 72
Joined: Wed Jun 14, 2006 4:31 am
Contact:

Re: JVM Statistics

Post by equick »

Hi,

I have released v1.3 above which offers an RMI based solution instead of SSH. Please let me know if you need any help setting this up.

Kind Regards,

Ed.
rollingsun
Posts: 2
Joined: Mon Oct 11, 2010 2:34 am

Re: JVM Statistics

Post by rollingsun »

these scripts and templates works !

but , I have 2 tomcats running on a server , use a jdk .

I run 'jps' , and I saw two Bootstrap .

how to solve this situation ?


Thanks !
equick
Cacti User
Posts: 72
Joined: Wed Jun 14, 2006 4:31 am
Contact:

Re: JVM Statistics

Post by equick »

Hi there,

Thanks for trying out the template. If you have more than one tomcat running on the same box, you could try jps -v to differentiate them, for example:

Code: Select all

$ jps -v | grep instance_1
19351 Bootstrap -Djava.util.logging.config.file=/opt/projects/tomcat/shared/conf/logging.properties -Dcatalina.instance=1 -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.library.path=/usr/local/apr/lib -Dcatalina.config=file:///opt/projects/tomcat/instance_1/conf/catalina.properties.LIVE -DterracottaUrl=tre111:9510,tre112:9510 -Dtc.install-root=/opt/terracotta/terracotta-ee-3.4.1-patch1 -Dcom.sun.management.jmxremote.port=6666 -Dcom.sun.management.jmxremote.password.file=/opt/projects/tomcat/instance_1/management/jmxremote.password -Dcom.sun.management.jmxremote.access.file=/opt/projects/tomcat/instance_1/management/jmxremote.access -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Djava.rmi.server.hostname=lrprdtme113.iggroup.local -Xms2048m -Xmx2048m -XX:MaxPermSize=256m -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+UseCompressedOops -XX:NewRatio=3 -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCD
Assuming you are using ssh_jstat.pl, change the line

Code: Select all

$pidcmd="$sshcmd $JAVA_HOME/bin/jps | grep $jproc | cut -d\" \" -f1";
to

Code: Select all

$pidcmd="$sshcmd $JAVA_HOME/bin/jps -v | grep $jproc | cut -d\" \" -f1";
Hope this helps.

Ed.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests