Script to monitor process on Linux

Environment: Oracle Linux 6.2

Sometimes you want to monitor a process on your Linux server and do some alerting when the process is not running anymore.

The following shell script can be used as an example. It will monitor the “dbconsole” process (database control) and send a e-mail message when the process is not running anymore.

$ vi



if [ `ps ax|grep -v grep|grep -ic $PROCESSFILE` -gt 0 ]
        echo "$PROCESSFILE is running, everything is fine"
        echo "$PROCESSFILE is not running on `hostname -s`!" | mail -s "$PROCESSFILE down!"


$ chmod u+x

To schedule the script, you can add it to cron. For example, this script will run every day at 10:00AM:

$ crontab -e

# Monitoring dbconsole process
00 10 * * * /home/oracle/scripts/ 1>/dev/null 2>&1




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