How to check the CPU usage for a particular process(like tomcat) and for how much time it is consuming the same CPU amount programmatically ?
The problem is 8 tomcats has been configured, out of which 4 runs while the other 4 are stopped. Any time when any of the 4 tomcats goes on using same CPU amount for much longer time the app. hangs and so manually I have to kill it and start any other one. So I have to constantly keep an eye on the tomcats which is actually a dumb process.
So I need a solution to detect the span of time and the amount of CPU usage, and as soon as there is a problem the process(like tomcat) should be stopped/killed programmatically.