4

I want to find out CPU usage (in Percentage) of an Apache Tomcat Server(6.x) using JMX.
There is an attribute ProcessCpuTime of MBean java.lang:OperatingSystem. But, how to calculate usage percentage from it?

Thanks.

Nikunj
  • 3,100
  • 2
  • 20
  • 19

2 Answers2

7

Take the difference of two samples and divide by the time between samples.

To get a percentage, multiply by 100.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • 2
    +1 Might also want to divide by the number of processors. There's a code example at http://stackoverflow.com/questions/25552/using-java-to-get-os-level-system-information/61727#61727 – WhiteFang34 Apr 19 '11 at 11:30
0

Since you will probably want to do this over time, you can use a tool like http://jmxtrans.googlecode.com/ to query Tomcat via JMX and then graph it with Graphite.

Public Profile
  • 1,817
  • 1
  • 21
  • 20
  • Also check jmx2graphite (https://github.com/logzio/jmx2graphite) to dump JMX into Graphite in one command line without installation nor hefty configuration – Asaf Mesika Nov 28 '15 at 10:43