public static double getCpuUsage(long time) throws ApplicationException { if (time < 1) throw new ApplicationException("time has to be bigger than 0"); if (jsm == null) jsm = new JavaSysMon(); CpuTimes cput = jsm.cpuTimes(); if (cput == null) throw new ApplicationException("CPU information are not available for this OS"); CpuTimes previous = new CpuTimes(cput.getUserMillis(), cput.getSystemMillis(), cput.getIdleMillis()); sleep(time); return jsm.cpuTimes().getCpuUsage(previous) * 100D; }
private static synchronized MemoryStats physical() throws ApplicationException { if (jsm == null) jsm = new JavaSysMon(); MemoryStats p = jsm.physical(); if (p == null) throw new ApplicationException("Memory information are not available for this OS"); return p; }