Monitoring JVM memory performance of GlassFish 3.1.2

Environment: GlassFish OSE, Oracle Linux 6.3

In this blog post I will explain how you can enable and monitor the memory statistics of the Java Virtual Machine in GlassFish 3.1.2.

1) Enable monitoring for the JVM module

There are 2 ways to enable JVM monitoring: by using the graphical admin console, or from the command line by running the asadmin command.

From the graphical admin console

Start up the admin console (by default this runs on port 4848), log in as admin and click on “Monitoring Data” in the left menu. Now click on “Configure Monitoring” in the right menu for the instance you want to monitor. You should now see the screen with the list of configurable components (see screenshot below). Set the Monitoring Level of the JVM component to “Low” and click on Save. No instance restart is needed for this change.

From the command line

Start up the asadmin command (under the ../glassfish/bin folder). Use the subcommand “enable-monitoring” or “disable-monitoring” to enable/disable monitoring for a specific component. To specify the instance that you want to configure, add the “–target” option.

asadmin> enable-monitoring --modules jvm=LOW --target myinstance
Command enable-monitoring executed successfully.

2) View JVM memory statistics

From the graphical admin console

Click on “Monitoring Data” in the left menu and then on “Server” (under “View Monitoring Data”) in the right menu. You should now see the Server Monitoring screen (see screenshot below). To view the JVM memory statistics, click on the blue arrow next to “JVM: Memory Statistics”.

From the command line

Start up the asadmin command. Use the “get –monitor” subcommand to retrieve the required monitoring statistics.

asadmin> get --monitor myinstance.jvm.memory.usedheapsize.*
myinstance.jvm.memory.dotted-name = myinstance.jvm.memory
myinstance.jvm.memory.usedheapsize-count-count = 119150920
myinstance.jvm.memory.usedheapsize-count-description = Amount of used memory in bytes
myinstance.jvm.memory.usedheapsize-count-lastsampletime = 1346166888774
myinstance.jvm.memory.usedheapsize-count-name = UsedHeapSize
myinstance.jvm.memory.usedheapsize-count-starttime = 1346144878093
myinstance.jvm.memory.usedheapsize-count-unit = bytes

Command get executed successfully.

3) Schedule monitoring

To schedule the monitoring of memory statistics, you could easily add a command line entry to your crontab file. The following example will execute every 10 minutes and write the datetime and the usedheapsize to a log file.

>crontab -l
*/10 * * * * echo `date`>>/tmp/glassfish_memory.log;/u01/app/glassfish/bin/asadmin get --monitor myinstance.jvm.memory.usedheapsize-count-count>>/tmp/glassfish_memory.log



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: