How to get CPU usage (not TPS)

Discussion in 'Spigot Plugin Development' started by HydroTekZ, Jun 23, 2015.

  1. How can I get the total system CPU usage and the CPU usage that the application (Spigot) uses? I am not sure if this even is possible. This would be very helpful for me, I want to monitor the performance closer.
  2. What are you using for your server operating systems?
  3. Windows Server 2008 R2 Standard 64-bit
    • Funny Funny x 2
  4. Java does not provide a lot of profiling tools by default. You can look at using the SIGAR API (it's pretty nice!), which gives you a huge set of tools to profile the system you are running on and your application.

    That being said, there's still some information you can grab without adding any extra dependencies. Check out this stackoverflow answer for CPU load of your Java process (although that won't tell you the overall system usage of a particular, physical core).

    Also, Windows server is a pain to work with. I really suggest using Linux, for the sake of freeware and having better support when it comes to profiling and just about anything else server related on this forum.
    • Winner Winner x 1
  5. @HydroTekZ You need to use CentOS or Ubuntu server but I like CentOS a lot more.
  6. CentOS for lyf.
  7. Use ThreadMXBean, add up the cpu times, and then you can calculate the usage (time used / time elapsed = usage).
  8. Maximvdw




    use system queries
    • Funny Funny x 1
  9. Tux


    People like CentOS? Anyway, the fact is that $preferred_linux_distro is in no way related to this question.
    • Agree Agree x 2
  10. eeem, spigot from 1.8 (?) contains "oshi" lib, you should be able to use it to get all needed data

    But for profiling, you should use some profiling app, this is if you want get CPU usage from plugin, just to make command like /perf
  11. what you want to check ? the CPU Usage for minecraft or all at your system ?