public int getTotalCpuPercent ( ) { if ( invalidMonitor . get ( ) ) { return 0 ; } long now = System . currentTimeMillis ( ) ; int cpu ; synchronized ( Monitor . class ) { if ( now - cpuDetectedAt > cacheTimeout ) { try { cachedCPU = detectTotalCpuPercent ( ) ; } catch ( Throwable cause ) { logger . info ( "Unable to detect CPU usage!" , cause ) ; invalidMonitor . set ( true ) ; } cpuDetectedAt = now ; } cpu = cachedCPU ; } return cpu ; }
Returns the cached system CPU usage in percents between 0 and 100 .