Search code examples
javacassandracpu-usagejmxmbeans

Monitoring Cassandra CPU usage with JMX/MBeans


I want to write a simple Java code to monitor a Cassandra database with JMX. Now I'm stuck with retrieving the CPU usage of the database. As far as I figured out, a possible MBean would be the java.lang:type=OperatingSystem with attribute ProcessCpuLoad.

However, it seems in this case the result would be the CPU usage of all processes running in the JVM, not only the Cassandra threads. Is this assumption correct?

I also wonder what data is shown as CPU usage when connecting with JConsole to the database. Is it possible to get direct access to these values(I mean without JConsole)? Or is there another Mbean which gives exactly the desired values?

Thanks, Nico


Solution

  • ProcessCpuLoad in the OS mbean is correct. Its not all JVMs, just the one JVM thats reporting it. You do not have multiple processes running within a single JVM, the JVM runs as a single process per java application.

    You can use java.lang:type=Threading to monitor cpu time spent on individual threads but there are a ton of threads in Cassandra and it will probably never be totally right (miss things like GC time).

    If dont want to use jconsole you can check:

    ps -p <whatever-your-cassandra-pid-is> -o %cpu
    
    # or depending on OS/installer 
    
    ps -p `cat /var/run/cassandra.pid` -o %cpu