title: Using Sigar API to get JVM CPU usage
body: <p>I'm using Sigar to get the CPU usage of the current running JVM in an application server and store it for historical view of this data, but I always get 0% CPU percentage.</p>
  
  <p>In the meanwhile, I keep my visualVM open to monitor CPU usage, and I get to see the CPU % changing periodically in visualVM while it always reports 0% using Sigar.</p>
  
  <p>Here is the code I m running periodically:</p>
  
  <pre><code>Sigar sigar = new Sigar();
  ProcCpu cpu = null;
  long pId = sigar.getPid(); // This one gives me the same process ID that I see in visualVM
  try {
      cpu = sigar.getProcCpu(pId);
  
  } 
  catch (SigarException se) {
      se.printStackTrace();
  }
  System.out.print(cpu.getPercent());
  </code></pre>
  
  <p>This code always gives 0%.</p>
  
  <p>What am I doing wrong it this case? How can I get Sigar to display CPU usage similar to the usage displayed in VisualVM?</p>
  
  <p>I tried adding</p>
  
  <pre><code>cpu.gather(sigar, pId);
  </code></pre>
  
  <p>after calling getProcCpu(pid), but I keep getting only two values (0.0 and 9.08729312E-315) even if I keep increasing and decreasing load on the server...</p>