Reputation: 248
I want to moniter cpu usage of some java application. I don't want to use tools like jconsole (JMX)
if there is any way to check by java code?
Upvotes: 0
Views: 8872
Reputation: 1215
You should retrieve the MX Bean ThreadMXBean
from the Java class itself and use the methods get*CpuTime()
.
Otherwise, you can use good old top
and grep on your Java process PID.
If you are brave enough, there is also perf
tool in linux-tools
package.
Hope that helps !
Upvotes: 0
Reputation: 5223
Use JavaSysMon
Currently it reports:
Also you can use jmx mbeans or get PID using Runtime.exec() and using that call platform-specific command like ps.
Upvotes: 1
Reputation: 68915
One way would be to use
Runtime.getRuntime().exec(command);
and run top | grep java
command.
Upvotes: 0