monitoring memory usage of a JVM

I have been tasked with writing a monitoring script for our servers. It needs to monitor cpu usage, memory usage of the machine, and memory usage of the jvm that runs our main applications. I was going to write a simple script to do this, but google has been unforgiving when it comes to a way to get the memory usage of a particular jvm. Any ideas?