JVM Statistics
Moderators: Developers, Moderators
JVM Statistics
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 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.
MD5: dda8fc50eaad68983cb2e0c8ff986666
Thanks,
Ed.
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 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.
MD5: dda8fc50eaad68983cb2e0c8ff986666
Thanks,
Ed.
Last edited by equick on Sat Aug 13, 2011 11:41 am, edited 19 times in total.
Re: JVM Statistics
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.
Re: JVM Statistics
Uploaded jstat cacti template v1.1 (download above).
The graphs are hopefully looking a bit better now and the capacity graphs show utilization too.
The graphs are hopefully looking a bit better now and the capacity graphs show utilization too.
Re: JVM Statistics
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.
Re: JVM Statistics
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.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.
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.
* 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.
Re: JVM Statistics
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: and expected output:
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.
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: 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
Cheers,
Ed.
Re: JVM Statistics
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.
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.
The script is invoked with the following arguments:
This is the expected output. Note that the filenames are all similar except for the digits, and the sizes are all the same too:
If you don't want to proceed, or if the output looks wrong, just type 'n' and the program will exit as follows:
If you try rerunning the script, it should report that the consolidation has already been done:
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.
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.
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 #####################
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
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.
Code: Select all
Answer [y/n]: n
Exiting. No database or file changes made.
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.
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.
Re: JVM Statistics
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.
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.
-
- Posts: 2
- Joined: Mon Oct 11, 2010 2:34 am
Re: JVM Statistics
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 !
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 !
Re: JVM Statistics
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:
Assuming you are using ssh_jstat.pl, change the line
to
Hope this helps.
Ed.
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
Code: Select all
$pidcmd="$sshcmd $JAVA_HOME/bin/jps | grep $jproc | cut -d\" \" -f1";
Code: Select all
$pidcmd="$sshcmd $JAVA_HOME/bin/jps -v | grep $jproc | cut -d\" \" -f1";
Ed.
Who is online
Users browsing this forum: No registered users and 6 guests