script to check Heap size grows beyond 80%

Viewed 44

I am using ubuntu where OpenJDK is installed , and I want to check if heap size goes beyond 80% an alert should be sent

I know command which is

jcmd GC.heap_info

, but the problem is process id will be continuously get change on ubuntu.

so can any one suggest script for this.

1 Answers

You can use jps to find your java process:

jps -l
2770 org.netbeans.Main
5144 jdk.jcmd/sun.tools.jps.Jps

So when you want the process id of NetBeans for example. You can do something like:

jps -l | grep org.netbeans.Main | cut -f1 -d ' '

This information you can pass to jcmd:

jcmd `jps -l | grep org.netbeans.Main | cut -f1 -d ' '` GC.heap_info
Related