You could write a small Java service like the following to get certain heap size values. It would take no inputs and have 3 outputs (freeMemory, maxMemory, and totalMemory):
Here’s what the 3 values mean, taken from the Java Doc for JDK 1.5:
free memory - the amount of free memory in the Java Virtual Machine. Calling the gc method may result in increasing the value returned by freeMemory.
max memory - the maximum amount of memory that the Java virtual machine will attempt to use.
total memory - the total amount of memory in the Java virtual machine. The value returned by this method may vary over time, depending on the host environment.