Java Code Examples for java.lang.management.OperatingSystemMXBean#getSystemLoadAverage()
The following examples show how to use
java.lang.management.OperatingSystemMXBean#getSystemLoadAverage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DasServerStatusMonitor.java From das with Apache License 2.0 | 6 votes |
public DasServerStatus getStatues() { DasServerStatus status = new DasServerStatus(); status.online = true; status.avgResponse = totalCount.longValue() == 0 ? 0 : totalCost.longValue() / totalCount.longValue(); status.avgThroughput = totalCount.longValue()/((System.currentTimeMillis() - serverStartTime)/1000); status.transactionCount = transServer.getCurrentCount(); OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean(); double load = osBean.getSystemLoadAverage(); status.cpuRate = (int) Math.round(load); status.memRate = Math.round(100 - ((float)Runtime.getRuntime().freeMemory() / (float)Runtime.getRuntime().totalMemory()) * 100 ); status.clientCount = clientConnection.get(); //TODO //status.healthyPoint = ?; return status; }
Example 2
Source File: SystemUsage.java From Plan with GNU Lesser General Public License v3.0 | 6 votes |
/** * Check how active the system is (CPU) or if not available, using system load average. * <p> * - On some OSes CPU usage information is not available, and system load average is used instead. * - On some OSes system load average is not available. * * @return 0.0 to 100.0 if CPU, or system load average, or -1 if nothing is available. */ public static double getAverageSystemLoad() { double averageUsage; OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean(); if (osBean instanceof com.sun.management.OperatingSystemMXBean) { com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean; averageUsage = nativeOsBean.getSystemCpuLoad(); } else { int availableProcessors = osBean.getAvailableProcessors(); averageUsage = osBean.getSystemLoadAverage() / availableProcessors; } if (averageUsage < 0) { averageUsage = -1; // If unavailable, getSystemLoadAverage() returns -1 } return averageUsage * 100.0; }
Example 3
Source File: GetStatusServlet.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private static void getSystemInfo( SlaveServerStatus serverStatus ) { OperatingSystemMXBean operatingSystemMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean(); RuntimeMXBean runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); int cores = Runtime.getRuntime().availableProcessors(); long freeMemory = Runtime.getRuntime().freeMemory(); long totalMemory = Runtime.getRuntime().totalMemory(); String osArch = operatingSystemMXBean.getArch(); String osName = operatingSystemMXBean.getName(); String osVersion = operatingSystemMXBean.getVersion(); double loadAvg = operatingSystemMXBean.getSystemLoadAverage(); int threadCount = threadMXBean.getThreadCount(); long allThreadsCpuTime = 0L; long[] threadIds = threadMXBean.getAllThreadIds(); for ( int i = 0; i < threadIds.length; i++ ) { allThreadsCpuTime += threadMXBean.getThreadCpuTime( threadIds[ i ] ); } long uptime = runtimeMXBean.getUptime(); serverStatus.setCpuCores( cores ); serverStatus.setCpuProcessTime( allThreadsCpuTime ); serverStatus.setUptime( uptime ); serverStatus.setThreadCount( threadCount ); serverStatus.setLoadAvg( loadAvg ); serverStatus.setOsName( osName ); serverStatus.setOsVersion( osVersion ); serverStatus.setOsArchitecture( osArch ); serverStatus.setMemoryFree( freeMemory ); serverStatus.setMemoryTotal( totalMemory ); }
Example 4
Source File: GetStatusServlet.java From hop with Apache License 2.0 | 5 votes |
private static void getSystemInfo( HopServerStatus serverStatus ) { OperatingSystemMXBean operatingSystemMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean(); RuntimeMXBean runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); int cores = Runtime.getRuntime().availableProcessors(); long freeMemory = Runtime.getRuntime().freeMemory(); long totalMemory = Runtime.getRuntime().totalMemory(); String osArch = operatingSystemMXBean.getArch(); String osName = operatingSystemMXBean.getName(); String osVersion = operatingSystemMXBean.getVersion(); double loadAvg = operatingSystemMXBean.getSystemLoadAverage(); int threadCount = threadMXBean.getThreadCount(); long allThreadsCpuTime = 0L; long[] threadIds = threadMXBean.getAllThreadIds(); for ( int i = 0; i < threadIds.length; i++ ) { allThreadsCpuTime += threadMXBean.getThreadCpuTime( threadIds[ i ] ); } long uptime = runtimeMXBean.getUptime(); serverStatus.setCpuCores( cores ); serverStatus.setCpuProcessTime( allThreadsCpuTime ); serverStatus.setUptime( uptime ); serverStatus.setThreadCount( threadCount ); serverStatus.setLoadAvg( loadAvg ); serverStatus.setOsName( osName ); serverStatus.setOsVersion( osVersion ); serverStatus.setOsArchitecture( osArch ); serverStatus.setMemoryFree( freeMemory ); serverStatus.setMemoryTotal( totalMemory ); }
Example 5
Source File: ServerStatus.java From hop with Apache License 2.0 | 5 votes |
public ServerStatus() { OperatingSystemMXBean operatingSystemMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean(); RuntimeMXBean runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); int cores = Runtime.getRuntime().availableProcessors(); long freeMemory = Runtime.getRuntime().freeMemory(); long totalMemory = Runtime.getRuntime().totalMemory(); String osArch = operatingSystemMXBean.getArch(); String osName = operatingSystemMXBean.getName(); String osVersion = operatingSystemMXBean.getVersion(); double loadAvg = operatingSystemMXBean.getSystemLoadAverage(); int threadCount = threadMXBean.getThreadCount(); long allThreadsCpuTime = 0L; long[] threadIds = threadMXBean.getAllThreadIds(); for ( int i = 0; i < threadIds.length; i++ ) { allThreadsCpuTime += threadMXBean.getThreadCpuTime( threadIds[ i ] ); } long uptime = runtimeMXBean.getUptime(); setCpuCores( cores ); setCpuProcessTime( allThreadsCpuTime ); setUptime( uptime ); setThreadCount( threadCount ); setLoadAvg( loadAvg ); setOsName( osName ); setOsVersion( osVersion ); setOsArchitecture( osArch ); setMemoryFree( freeMemory ); setMemoryTotal( totalMemory ); }
Example 6
Source File: Performance.java From bidder with Apache License 2.0 | 5 votes |
/** * Get CPU performance as a String, adjusted by cores * * @return String. Returns a cpu percentage string */ public static String getCpuPerfAsString() { OperatingSystemMXBean mx = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); int cores = Runtime.getRuntime().availableProcessors(); double d = mx.getSystemLoadAverage() * 100 / cores; return formatter.format(d); }
Example 7
Source File: SystemUsage.java From DeconvolutionLab2 with GNU General Public License v3.0 | 5 votes |
public static double getLoad() { try { OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); return os.getSystemLoadAverage(); } catch (Exception ex) { } return 0; }
Example 8
Source File: SystemLoadHealthCheck.java From watcher with Apache License 2.0 | 5 votes |
@Override protected Result check() throws Exception { OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); double load = operatingSystemMXBean.getSystemLoadAverage(); int cpu = operatingSystemMXBean.getAvailableProcessors(); if (load < cpu) { return Result.healthy(); } else { return Result.unhealthy("load:%s,cpu:%s", load, cpu); } }
Example 9
Source File: JavaInformations.java From javamelody with Apache License 2.0 | 5 votes |
private static double buildSystemLoadAverage() { // System load average for the last minute. // The system load average is the sum of // the number of runnable entities queued to the available processors // and the number of runnable entities running on the available processors // averaged over a period of time. final OperatingSystemMXBean operatingSystem = ManagementFactory.getOperatingSystemMXBean(); if (operatingSystem.getSystemLoadAverage() >= 0) { // systemLoadAverage n'existe qu'à partir du jdk 1.6 return operatingSystem.getSystemLoadAverage(); } return -1; }
Example 10
Source File: Performance.java From XRTB with Apache License 2.0 | 5 votes |
/** * Get CPU performance as a String, adjusted by cores * * @return String. Returns a cpu percentage string */ public static String getCpuPerfAsString() { OperatingSystemMXBean mx = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); int cores = Runtime.getRuntime().availableProcessors(); double d = mx.getSystemLoadAverage() * 100 / cores; return formatter.format(d); }
Example 11
Source File: DiagnosticAnalysisTask.java From nifi with Apache License 2.0 | 5 votes |
private void analyzeCpuUsage(final List<String> details) { final OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); final double loadAverage = os.getSystemLoadAverage(); final int availableProcs = os.getAvailableProcessors(); if (loadAverage > availableProcs) { details.add(String.format("1-minute CPU Load Average is %1$.2f, which exceeds the %2$d available cores. CPU is over-utilized.", loadAverage, availableProcs)); } else if (loadAverage > 0.9 * availableProcs) { details.add(String.format("1-minute CPU Load Average is %1$.2f, which exceeds 90%% of the %2$d available cores. CPU may struggle to keep up.", loadAverage, availableProcs)); } }
Example 12
Source File: ServerStatus.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public ServerStatus() { OperatingSystemMXBean operatingSystemMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean(); RuntimeMXBean runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); int cores = Runtime.getRuntime().availableProcessors(); long freeMemory = Runtime.getRuntime().freeMemory(); long totalMemory = Runtime.getRuntime().totalMemory(); String osArch = operatingSystemMXBean.getArch(); String osName = operatingSystemMXBean.getName(); String osVersion = operatingSystemMXBean.getVersion(); double loadAvg = operatingSystemMXBean.getSystemLoadAverage(); int threadCount = threadMXBean.getThreadCount(); long allThreadsCpuTime = 0L; long[] threadIds = threadMXBean.getAllThreadIds(); for ( int i = 0; i < threadIds.length; i++ ) { allThreadsCpuTime += threadMXBean.getThreadCpuTime( threadIds[i] ); } long uptime = runtimeMXBean.getUptime(); setCpuCores( cores ); setCpuProcessTime( allThreadsCpuTime ); setUptime( uptime ); setThreadCount( threadCount ); setLoadAvg( loadAvg ); setOsName( osName ); setOsVersion( osVersion ); setOsArchitecture( osArch ); setMemoryFree( freeMemory ); setMemoryTotal( totalMemory ); }