List of usage examples for java.lang.management ManagementFactory getOperatingSystemMXBean
public static OperatingSystemMXBean getOperatingSystemMXBean()
From source file:sce.JobStoreTXCustom.java
public Map<String, String> getSystemStatus() { OperatingSystemMXBean omx = ManagementFactory.getOperatingSystemMXBean(); com.sun.management.OperatingSystemMXBean osMxBean = null; if (omx instanceof com.sun.management.OperatingSystemMXBean) { osMxBean = (com.sun.management.OperatingSystemMXBean) omx; }/*from w ww .j a va 2 s .c o m*/ Map<String, String> statusMap = new HashMap<>(); if (osMxBean != null) { statusMap.put("osArch", osMxBean.getArch()); statusMap.put("availableProcessors", Integer.toString(osMxBean.getAvailableProcessors())); statusMap.put("osName", osMxBean.getName()); statusMap.put("systemLoadAverage", Double.toString(osMxBean.getSystemLoadAverage())); statusMap.put("osVersion", osMxBean.getVersion()); statusMap.put("committedVirtualMemorySize", Long.toString(osMxBean.getCommittedVirtualMemorySize())); statusMap.put("freePhysicalMemorySize", Long.toString(osMxBean.getFreePhysicalMemorySize())); statusMap.put("freeSwapSpaceSize", Long.toString(osMxBean.getFreeSwapSpaceSize())); statusMap.put("processCpuLoad", Double.toString(osMxBean.getProcessCpuLoad())); statusMap.put("processCpuTime", Long.toString(osMxBean.getProcessCpuTime())); statusMap.put("systemCpuLoad", Double.toString(osMxBean.getSystemCpuLoad())); statusMap.put("totalPhysicalMemorySize", Long.toString(osMxBean.getTotalPhysicalMemorySize())); statusMap.put("totalSwapSpaceSize", Long.toString(osMxBean.getTotalSwapSpaceSize())); } return statusMap; }
From source file:com.eurelis.opencms.admin.systeminformation.CmsMemoryOverviewDialog.java
/** * Initializes the infos object.<p> */// w ww. j av a 2 s .c o m protected void initInfosObject() { com.sun.management.OperatingSystemMXBean sunOsBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); java.lang.management.OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean(); java.lang.management.ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); java.lang.management.RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); java.lang.management.ClassLoadingMXBean classesBean = ManagementFactory.getClassLoadingMXBean(); for (java.lang.management.MemoryPoolMXBean item : ManagementFactory.getMemoryPoolMXBeans()) { java.lang.management.MemoryUsage mu = item.getUsage(); String name = item.getName(); if (name.toLowerCase().contains("perm")) { setMemPermMax("" + mu.getMax()); setMemPermTotal("" + mu.getCommitted()); setMemPermUsed("" + mu.getUsed()); } else if (name.toLowerCase().contains("old")) { setMemOldMax("" + mu.getMax()); setMemOldTotal("" + mu.getCommitted()); setMemOldUsed("" + mu.getUsed()); } else if (name.toLowerCase().contains("eden")) { setMemEdenMax("" + mu.getMax()); setMemEdenTotal("" + mu.getCommitted()); setMemEdenUsed("" + mu.getUsed()); } else if (name.toLowerCase().contains("survivor")) { setMemSurvivorMax("" + mu.getMax()); setMemSurvivorTotal("" + mu.getCommitted()); setMemSurvivorUsed("" + mu.getUsed()); } else { //LOG.debug("MemoryPoolMXBean name = " + name.toLowerCase()); } } Object o; if (CmsStringUtil.isEmpty(getParamAction())) { o = new CmsAdminSettings(getSession()); } else { // this is not the initial call, get the job object from session o = getDialogObject(); } if (!(o instanceof CmsAdminSettings)) { // create a new history settings handler object m_adminSettings = new CmsAdminSettings(getSession()); } else { // reuse html import handler object stored in session m_adminSettings = (CmsAdminSettings) o; } setParamCloseLink(getJsp() .link("/system/workplace/views/admin/admin-main.jsp?path=/eurelis_system_information/memory.jsp")); }
From source file:com.evolveum.midpoint.web.util.WebMiscUtil.java
public static double getSystemLoad() { com.sun.management.OperatingSystemMXBean operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); int availableProcessors = operatingSystemMXBean.getAvailableProcessors(); long prevUpTime = runtimeMXBean.getUptime(); long prevProcessCpuTime = operatingSystemMXBean.getProcessCpuTime(); try {//from w w w . j a v a2 s .c o m Thread.sleep(150); } catch (Exception ignored) { //ignored } operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); long upTime = runtimeMXBean.getUptime(); long processCpuTime = operatingSystemMXBean.getProcessCpuTime(); long elapsedCpu = processCpuTime - prevProcessCpuTime; long elapsedTime = upTime - prevUpTime; double cpuUsage = Math.min(99F, elapsedCpu / (elapsedTime * 10000F * availableProcessors)); return cpuUsage; }
From source file:org.jwebsocket.plugins.system.SystemPlugIn.java
private void getJVMInfo(WebSocketConnector aConnector, Token aToken) { // check if user is allowed to run 'getjvminfo' command if (!hasAuthority(aConnector, NS_SYSTEM + ".getjvminfo")) { sendToken(aConnector, aConnector, createAccessDenied(aToken)); return;// ww w . j ava 2 s. c om } Token lResponse = createResponse(aToken); RuntimeMXBean lBean = ManagementFactory.getRuntimeMXBean(); MemoryMXBean lMemory = ManagementFactory.getMemoryMXBean(); OperatingSystemMXBean lOS = ManagementFactory.getOperatingSystemMXBean(); lResponse.setMap("data", new MapAppender().append("inputArguments", lBean.getInputArguments()) .append("libraryPath", lBean.getLibraryPath()) .append("managementSpecVersion", lBean.getManagementSpecVersion()).append("name", lBean.getName()) .append("specName", lBean.getSpecName()).append("specVendor", lBean.getSpecVendor()) .append("specVersion", lBean.getSpecVersion()).append("startTime", lBean.getStartTime()) .append("systemProperties", lBean.getSystemProperties()).append("uptime", lBean.getUptime()) .append("vmName", lBean.getVmName()).append("vmVendor", lBean.getVmVendor()) .append("vmVersion", lBean.getVmVersion()).append("classPath", lBean.getClassPath()) .append("osArch", lOS.getArch()).append("osAvailableProcessors", lOS.getAvailableProcessors()) .append("osName", lOS.getName()).append("osVersion", lOS.getVersion()) .append("osLoadAverage", lOS.getSystemLoadAverage()) .append("heapMemoryUsed", lMemory.getHeapMemoryUsage().getUsed()) .append("heapMemoryMax", lMemory.getHeapMemoryUsage().getMax()) .append("heapMemoryInit", lMemory.getHeapMemoryUsage().getInit()) .append("nonheapMemoryInit", lMemory.getNonHeapMemoryUsage().getInit()) .append("nonheapMemoryMax", lMemory.getNonHeapMemoryUsage().getMax()) .append("nonheapMemoryUsed", lMemory.getNonHeapMemoryUsage().getUsed()).getMap()); sendToken(aConnector, lResponse); }
From source file:com.eurelis.opencms.admin.systeminformation.CmsCPUThreadsClassesOverviewDialog.java
public static double getCPUUsage(HttpSession session) { OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); int availableProcessors = operatingSystemMXBean.getAvailableProcessors(); Long prevUpTime = (Long) session.getAttribute(PARAM_TIMESTAMP); Long prevProcessCpuTime = (Long) session.getAttribute(PARAM_PROCESS_CPU_TIME); double cpuUsage; operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); long upTime = runtimeMXBean.getUptime(); long processCpuTime = operatingSystemMXBean.getProcessCpuTime(); if (prevProcessCpuTime != null || prevUpTime != null) { long elapsedCpu = processCpuTime - prevProcessCpuTime.longValue(); long elapsedTime = upTime - prevUpTime.longValue(); cpuUsage = Math.min(99F, elapsedCpu / (elapsedTime * 10000F * availableProcessors)); } else {/*ww w. j a va2 s .c o m*/ cpuUsage = 0; } session.setAttribute(PARAM_PROCESS_CPU_TIME, processCpuTime); session.setAttribute(PARAM_TIMESTAMP, upTime); return cpuUsage; }
From source file:com.eurelis.opencms.admin.systeminformation.CmsDBPoolsOverviewDialog.java
/** * Initializes the infos object.<p> *///from w w w .j a v a2 s. c o m protected void initInfosObject() { com.sun.management.OperatingSystemMXBean sunOsBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); java.lang.management.OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean(); java.lang.management.ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); java.lang.management.RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); java.lang.management.ClassLoadingMXBean classesBean = ManagementFactory.getClassLoadingMXBean(); initPools(); Object o; if (CmsStringUtil.isEmpty(getParamAction())) { o = new CmsAdminSettings(getSession()); } else { // this is not the initial call, get the job object from session o = getDialogObject(); } if (!(o instanceof CmsAdminSettings)) { // create a new history settings handler object m_adminSettings = new CmsAdminSettings(getSession()); } else { // reuse html import handler object stored in session m_adminSettings = (CmsAdminSettings) o; } setParamCloseLink(getJsp().link( "/system/workplace/views/admin/admin-main.jsp?path=/eurelis_system_information/database_pools.jsp")); }
From source file:org.apache.zeppelin.zeppelin_spark_monitoring.SparkMonitoringInterpreter.java
private InterpreterResult getCpuUsage() { StringBuffer result = new StringBuffer(); OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); return new InterpreterResult(InterpreterResult.Code.SUCCESS, InterpreterResult.Type.TABLE, result.toString());// w w w. j a va 2s . c o m }
From source file:sce.Main.java
public String getSystemStatus() { String result;// www . j a v a 2 s. c o m OperatingSystemMXBean omx = ManagementFactory.getOperatingSystemMXBean(); com.sun.management.OperatingSystemMXBean osMxBean = null; if (omx instanceof com.sun.management.OperatingSystemMXBean) { osMxBean = (com.sun.management.OperatingSystemMXBean) omx; } JSONObject results_obj = new JSONObject(); JSONArray jsonList1 = new JSONArray(); String arch = ""; if (osMxBean != null) { arch = osMxBean.getArch(); } jsonList1.add(arch != null ? arch : ""); jsonList1.add("Returns the operating system architecture"); results_obj.put("Operating System architecture", jsonList1); JSONArray jsonList2 = new JSONArray(); int availableProcessors = -1; if (osMxBean != null) { availableProcessors = osMxBean.getAvailableProcessors(); } jsonList2.add(Integer.toString(availableProcessors)); jsonList2.add("Reports the number of processors available to the Java virtual machine"); results_obj.put("Number of processors", jsonList2); JSONArray jsonList3 = new JSONArray(); String name = ""; if (osMxBean != null) { name = osMxBean.getName(); } jsonList3.add(name != null ? name : ""); jsonList3.add("Reports the operating system name"); results_obj.put("Operating System name", jsonList3); JSONArray jsonList4 = new JSONArray(); double systemLoadAverage = -1; if (osMxBean != null) { systemLoadAverage = osMxBean.getSystemLoadAverage(); } jsonList4.add(Double.toString(systemLoadAverage)); jsonList4.add( "Reports the 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. The way in which the load average is calculated is operating system specific but is typically a damped time-dependent average.\n" + "\n" + "If the load average is not available, a negative value is returned." + "\n" + "This value is designed to provide a hint about the system load and may be queried frequently. The load average may be unavailable on some platform where it is expensive to implement this method"); results_obj.put("System Load average", jsonList4); JSONArray jsonList5 = new JSONArray(); String version = ""; if (osMxBean != null) { version = osMxBean.getVersion(); } jsonList5.add(version != null ? version : ""); jsonList5.add("Reports the operating system version"); results_obj.put("Operating System version", jsonList5); JSONArray jsonList6 = new JSONArray(); long committedVirtualMemorySize = -1; if (osMxBean != null) { committedVirtualMemorySize = osMxBean.getCommittedVirtualMemorySize(); } jsonList6.add(Long.toString(committedVirtualMemorySize)); jsonList6.add( "Reports the amount of virtual memory that is guaranteed to be available to the running process in bytes, or -1 if this operation is not supported"); results_obj.put("Committed virtual memory", jsonList6); JSONArray jsonList7 = new JSONArray(); long freePhysicalMemorySize = -1; if (osMxBean != null) { freePhysicalMemorySize = osMxBean.getFreePhysicalMemorySize(); } jsonList7.add(Long.toString(freePhysicalMemorySize)); jsonList7.add("Reports the amount of free physical memory in bytes"); results_obj.put("Free physical memory", jsonList7); JSONArray jsonList8 = new JSONArray(); long freeSwapSpaceSize = -1; if (osMxBean != null) { freeSwapSpaceSize = osMxBean.getFreeSwapSpaceSize(); } jsonList8.add(Long.toString(freeSwapSpaceSize)); jsonList8.add("Reports the amount of free swap space in bytes"); results_obj.put("Free swap space", jsonList8); JSONArray jsonList9 = new JSONArray(); double processCpuLoad = -1; if (osMxBean != null) { processCpuLoad = osMxBean.getProcessCpuLoad(); } jsonList9.add(Double.toString(processCpuLoad)); jsonList9.add( "Returns the recent cpu usage for the Java Virtual Machine process. This value is a double in the [0.0, 1.0] interval. A value of 0.0 means that none of the CPUs were running threads from the JVM process during the recent period of time observed, while a value of 1.0 means that all CPUs were actively running threads from the JVM 100% of the time during the recent period being observed. Threads from the JVM include the application threads as well as the JVM internal threads. All values between 0.0 and 1.0 are possible depending of the activities going on in the JVM process and the whole system. If the Java Virtual Machine recent CPU usage is not available, the value reports a negative value"); results_obj.put("CPU load (JVM)", jsonList9); JSONArray jsonList10 = new JSONArray(); long processCpuTime = -1; if (osMxBean != null) { processCpuTime = osMxBean.getProcessCpuTime(); } jsonList10.add(Long.toString(processCpuTime)); jsonList10.add( "Returns the cpu time used by the process on which the Java virtual machine is running in nanoseconds. The returned value is of nanoseconds precision but not necessarily nanoseconds accuracy. This value reports -1 if the platform does not support this operation"); results_obj.put("Process CPU time", jsonList10); JSONArray jsonList11 = new JSONArray(); double systemCpuLoad = -1; if (osMxBean != null) { systemCpuLoad = osMxBean.getSystemCpuLoad(); } jsonList11.add(Double.toString(systemCpuLoad)); jsonList11.add( "Returns the recent cpu usage for the whole system. This value is a double in the [0.0, 1.0] interval. A value of 0.0 means that all CPUs were idle during the recent period of time observed, while a value of 1.0 means that all CPUs were actively running 100% of the time during the recent period being observed. All values between 0.0 and 1.0 are possible depending of the activities going on in the system. If the system recent cpu usage is not available, the value reports a negative value"); results_obj.put("CPU load", jsonList11); JSONArray jsonList12 = new JSONArray(); double totalPhysicalMemorySize = -1; if (osMxBean != null) { totalPhysicalMemorySize = osMxBean.getTotalPhysicalMemorySize(); } jsonList12.add(Double.toString(totalPhysicalMemorySize)); jsonList12.add("Returns the total amount of physical memory in bytes"); results_obj.put("Total physical memory", jsonList12); JSONArray jsonList13 = new JSONArray(); double totalSwapSpaceSize = -1; if (osMxBean != null) { totalSwapSpaceSize = osMxBean.getTotalSwapSpaceSize(); } jsonList13.add(Double.toString(totalSwapSpaceSize)); jsonList13.add("Returns the total amount of swap space in bytes"); results_obj.put("Total swap space", jsonList13); result = results_obj.toJSONString(); jsonList1.clear(); jsonList2.clear(); jsonList3.clear(); jsonList4.clear(); jsonList5.clear(); jsonList6.clear(); jsonList7.clear(); jsonList8.clear(); jsonList9.clear(); jsonList10.clear(); jsonList11.clear(); jsonList12.clear(); jsonList13.clear(); return result; }
From source file:com.evolveum.midpoint.gui.api.util.WebComponentUtil.java
public static double getSystemLoad() { com.sun.management.OperatingSystemMXBean operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); int availableProcessors = operatingSystemMXBean.getAvailableProcessors(); long prevUpTime = runtimeMXBean.getUptime(); long prevProcessCpuTime = operatingSystemMXBean.getProcessCpuTime(); try {// w w w. ja va 2s . c om Thread.sleep(150); } catch (Exception ignored) { // ignored } operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); long upTime = runtimeMXBean.getUptime(); long processCpuTime = operatingSystemMXBean.getProcessCpuTime(); long elapsedCpu = processCpuTime - prevProcessCpuTime; long elapsedTime = upTime - prevUpTime; double cpuUsage = Math.min(99F, elapsedCpu / (elapsedTime * 10000F * availableProcessors)); return cpuUsage; }