Example usage for java.lang.management OperatingSystemMXBean getAvailableProcessors

List of usage examples for java.lang.management OperatingSystemMXBean getAvailableProcessors

Introduction

In this page you can find the example usage for java.lang.management OperatingSystemMXBean getAvailableProcessors.

Prototype

public int getAvailableProcessors();

Source Link

Document

Returns the number of processors available to the Java virtual machine.

Usage

From source file:org.liferayhub.pc.service.impl.PowerConsoleServiceImpl.java

public String runCommand(long userId, long companyId, String mode, String command) {
    String response = "";
    Date startDate = new Date();
    if ("server".equalsIgnoreCase(mode)) {
        if ("help".equalsIgnoreCase(command)) {
            response = "Commands:\n" + "help\t\t\tShow this help message\n"
                    + "version\t\t Display the version of the Liferay Portal\n"
                    + "date\t\t\tDisplay the date and time of the database server\n"
                    + "uptime\t\t  Display the uptime of the portal\n" + "adduser\t\t Add a new user";
        } else if ("version".equalsIgnoreCase(command)) {
            response = ReleaseInfo.getReleaseInfo() + " running on "
                    + StringUtil.upperCaseFirstLetter(ServerDetector.getServerId());
        } else if ("date".equalsIgnoreCase(command)) {
            response = new Date().toString();
        } else if ("uptime".equalsIgnoreCase(command)) {
            response = getUptime(PortalUtil.getUptime().getTime());
        } else if (command.toLowerCase().startsWith("adduser")) {
            response = handleAddUser(userId, companyId, command);
        }/* ww  w  . jav  a 2  s .  c o  m*/
    } else if ("db".equalsIgnoreCase(mode)) {
        if ("help".equalsIgnoreCase(command)) {
            response = "Commands:\n" + "help\t\t\tShow this help message\n"
                    + "version\t\t Display the version of the database\n"
                    + "date\t\t\tDisplay the date and time of the database server\n"
                    + "<sql query>\t Display result of any SQL query";
        } else if ("date".equalsIgnoreCase(command)) {
            response = runSQLQuery("select now() \"\"");
        } else if ("version".equalsIgnoreCase(command)) {
            response = runSQLQuery(
                    "select '" + DBFactoryUtil.getDBFactory().getDB().getType() + "' as '', version() ''");
        } else
            response = runSQLQuery(command);
    } else if ("jvm".equalsIgnoreCase(mode)) {
        if ("help".equalsIgnoreCase(command)) {
            response = "Commands:\n" + "help\t\tShow this help message\n"
                    + "mem\t\t Display memory usage of the JVM\n"
                    + "osinfo\t  Display operating system info of the running JVM\n"
                    + "vminfo\t  Display VM info";
        } else if ("mem".equalsIgnoreCase(command)) {
            MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
            response = "Heap        : " + mem.getHeapMemoryUsage().toString();
            response += "\nNon Heap    : " + mem.getNonHeapMemoryUsage().toString();
            response += "\nFinalization: " + mem.getObjectPendingFinalizationCount() + " objects pending";
        } else if ("osinfo".equalsIgnoreCase(command)) {
            OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
            response = os.getName() + "[" + os.getArch() + "] " + os.getVersion() + " ("
                    + os.getAvailableProcessors() + " processors)";
            response += "\nLoad Average: " + os.getSystemLoadAverage();
        } else if ("vminfo".equalsIgnoreCase(command)) {
            RuntimeMXBean vm = ManagementFactory.getRuntimeMXBean();
            response = vm.getVmName() + " " + vm.getVmVersion() + " by " + vm.getVmVendor();
            response += "\n" + vm.getSpecName() + " " + vm.getSpecVersion() + " by " + vm.getSpecVendor();
            response += "\nStarted at: " + DateFormat.getInstance().format(new Date(vm.getStartTime()));
            response += "\nUptime    : " + getUptime(vm.getStartTime());
        } else {
            response = UNRECOGNIZED_COMMAND;
        }
    }
    // save command to database if it is not 'help'
    if (!command.startsWith("help")) {
        try {
            // add to history
            Date endDate = new Date();
            long id = CounterLocalServiceUtil.increment(CommandHistory.class.getName());
            CommandHistory history = CommandHistoryLocalServiceUtil.createCommandHistory(id);
            history.setCommand(command);
            history.setExecutionDate(startDate);
            history.setExecutionTime(endDate.getTime() - startDate.getTime());
            history.setMode(mode);
            history.setUserId(userId);
            CommandHistoryLocalServiceUtil.updateCommandHistory(history);
            // TODO: delete the oldest entry > MAX_HISTORY_SIZE
            // get the history size
            long historySize = 100;
            List<CommandHistory> historyList = CommandHistoryLocalServiceUtil
                    .findCommandHistoryByUserId(userId);
            if (historyList.size() >= historySize) {
                CommandHistoryLocalServiceUtil.deleteCommandHistory(historyList.get(0));
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }
    return response;
}

From source file:org.pepstock.jem.node.swarm.Swarm.java

/**
 * Initializes the nodeInfo that will be store in the SWARM NODES MAP
 * /*from w  ww.  j  av  a2  s  .  c o m*/
 * @see org.pepstock.jem.gwt.server.swarm.SwarmQueues#NODES_MAP
 * @param member this hazelcast member of the swarm environment
 */
private void initNodeInfo(Member member) {
    // set uuid of member of hazelcast as key
    nodeInfo.setKey(member.getUuid());
    // set port and ip address
    InetSocketAddress address = member.getInetSocketAddress();
    nodeInfo.setPort(address.getPort());
    nodeInfo.setIpaddress(address.getAddress().getHostAddress());
    // sets label to be displayed by GRS
    nodeInfo.setLabel(nodeInfo.getIpaddress() + ":" + nodeInfo.getPort());
    // use JMX to extract current process id
    nodeInfo.setProcessId(ManagementFactory.getRuntimeMXBean().getName());
    // set hostname
    String hostname = StringUtils.substringAfter(nodeInfo.getProcessId(), "@");
    nodeInfo.setHostname(hostname);
    OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean();
    nodeInfo.getNodeInfoBean().setSystemArchitecture(bean.getArch());
    nodeInfo.getNodeInfoBean().setAvailableProcessors(bean.getAvailableProcessors());
    nodeInfo.getNodeInfoBean().setSystemName(bean.getName());
    ExecutionEnvironment executionEnvironment = new ExecutionEnvironment();
    // the environment will be that of jem one not the swarm one.
    executionEnvironment.setEnvironment(Main.EXECUTION_ENVIRONMENT.getEnvironment());
    nodeInfo.setExecutionEnvironment(executionEnvironment);
    nodeInfo.setJemVersion(Main.getNode().getJemVersion());
}

From source file:com.aol.advertising.qiao.management.metrics.StatsCalculator.java

@SuppressWarnings("restriction")
public void init() {
    OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean();
    if (bean instanceof com.sun.management.OperatingSystemMXBean) {
        availProcessors = bean.getAvailableProcessors();
        osMxBean = (com.sun.management.OperatingSystemMXBean) bean;
    }//from ww w  .  j a  va 2  s  . co  m

}

From source file:com.alibaba.otter.node.etl.OtterController.java

public String getNodeSystemInfo() {
    OperatingSystemMXBean mbean = ManagementFactory.getOperatingSystemMXBean();
    StringBuilder buf = new StringBuilder();
    buf.append("").append(mbean.getName()).append(' ').append(mbean.getVersion()).append(' ')
            .append(mbean.getArch());//from   w ww  .  ja va2  s. co m
    buf.append(" @ ").append(mbean.getAvailableProcessors()).append(" cores");
    buf.append(" , ? load average:").append(mbean.getSystemLoadAverage()).append(" ");
    return buf.toString();
}

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  w w.j  a  v  a2s  . com
    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:org.apache.syncope.core.logic.SyncopeLogic.java

private void initSystemInfo() {
    if (SYSTEM_INFO == null) {
        OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
        RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();

        SYSTEM_INFO = new SystemInfo();
        try {//from   ww w  .j a  v a  2  s. co  m
            SYSTEM_INFO.setHostname(InetAddress.getLocalHost().getHostName());
        } catch (UnknownHostException e) {
            LOG.error("Could not get host name", e);
        }

        SYSTEM_INFO.setOs(operatingSystemMXBean.getName() + " " + operatingSystemMXBean.getVersion() + " "
                + operatingSystemMXBean.getArch());
        SYSTEM_INFO.setAvailableProcessors(operatingSystemMXBean.getAvailableProcessors());
        SYSTEM_INFO.setJvm(runtimeMXBean.getVmName() + " " + System.getProperty("java.version") + " "
                + runtimeMXBean.getVmVendor());
        SYSTEM_INFO.setStartTime(runtimeMXBean.getStartTime());
    }
}

From source file:edu.usu.sdl.openstorefront.web.rest.service.Application.java

@GET
@RequireAdmin//from w  w  w.  java 2  s. com
@APIDescription("Gets the application system status")
@Produces({ MediaType.APPLICATION_JSON })
@DataType(ApplicationStatus.class)
@Path("/status")
public Response getApplicationStatus() {
    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();

    ApplicationStatus applicationStatus = new ApplicationStatus();
    applicationStatus.setApplicationVersion(PropertiesManager.getApplicationVersion());
    applicationStatus.setProcessorCount(operatingSystemMXBean.getAvailableProcessors());
    applicationStatus.setSystemLoad(operatingSystemMXBean.getSystemLoadAverage());
    applicationStatus.setSystemProperties(runtimeMXBean.getSystemProperties());

    applicationStatus.getHeapMemoryStatus().setName("Heap");
    applicationStatus.getHeapMemoryStatus().setDetails(memoryMXBean.getHeapMemoryUsage().toString());
    applicationStatus.getHeapMemoryStatus()
            .setInitKb(memoryMXBean.getHeapMemoryUsage().getInit() != 0
                    ? memoryMXBean.getHeapMemoryUsage().getInit() / 1024
                    : 0);
    applicationStatus.getHeapMemoryStatus()
            .setUsedKb(memoryMXBean.getHeapMemoryUsage().getUsed() != 0
                    ? memoryMXBean.getHeapMemoryUsage().getUsed() / 1024
                    : 0);
    applicationStatus.getHeapMemoryStatus()
            .setMaxKb(memoryMXBean.getHeapMemoryUsage().getMax() != 0
                    ? memoryMXBean.getHeapMemoryUsage().getMax() / 1024
                    : 0);
    applicationStatus.getHeapMemoryStatus()
            .setCommitedKb(memoryMXBean.getHeapMemoryUsage().getCommitted() != 0
                    ? memoryMXBean.getHeapMemoryUsage().getCommitted() / 1024
                    : 0);

    applicationStatus.getNonHeapMemoryStatus().setName("Non-Heap");
    applicationStatus.getNonHeapMemoryStatus().setDetails(memoryMXBean.getNonHeapMemoryUsage().toString());
    applicationStatus.getNonHeapMemoryStatus()
            .setInitKb(memoryMXBean.getNonHeapMemoryUsage().getInit() != 0
                    ? memoryMXBean.getNonHeapMemoryUsage().getInit() / 1024
                    : 0);
    applicationStatus.getNonHeapMemoryStatus()
            .setUsedKb(memoryMXBean.getNonHeapMemoryUsage().getUsed() != 0
                    ? memoryMXBean.getNonHeapMemoryUsage().getUsed() / 1024
                    : 0);
    applicationStatus.getNonHeapMemoryStatus()
            .setMaxKb(memoryMXBean.getNonHeapMemoryUsage().getMax() != 0
                    ? memoryMXBean.getNonHeapMemoryUsage().getMax() / 1024
                    : 0);
    applicationStatus.getNonHeapMemoryStatus()
            .setCommitedKb(memoryMXBean.getNonHeapMemoryUsage().getCommitted() != 0
                    ? memoryMXBean.getNonHeapMemoryUsage().getCommitted() / 1024
                    : 0);

    applicationStatus.setLiveThreadCount(threadMXBean.getThreadCount());
    applicationStatus.setTotalThreadCount(threadMXBean.getTotalStartedThreadCount());

    applicationStatus.setStartTime(new Date(runtimeMXBean.getStartTime()));
    applicationStatus.setUpTime(TimeUtil.millisToString(runtimeMXBean.getUptime()));

    for (GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMXBeans) {
        applicationStatus.getGarbageCollectionInfos()
                .add(TimeUtil.millisToString(garbageCollectorMXBean.getCollectionTime()) + " - ("
                        + garbageCollectorMXBean.getCollectionCount() + ")");
    }

    for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
        MemoryPoolStatus memoryPoolStatus = new MemoryPoolStatus();
        memoryPoolStatus.setName(memoryPoolMXBean.getName() + " - " + memoryPoolMXBean.getType());
        memoryPoolStatus.setDetails(memoryPoolMXBean.getUsage().toString());
        memoryPoolStatus.setInitKb(
                memoryPoolMXBean.getUsage().getInit() != 0 ? memoryPoolMXBean.getUsage().getInit() / 1024 : 0);
        memoryPoolStatus.setUsedKb(
                memoryPoolMXBean.getUsage().getUsed() != 0 ? memoryPoolMXBean.getUsage().getUsed() / 1024 : 0);
        memoryPoolStatus.setMaxKb(
                memoryPoolMXBean.getUsage().getMax() != 0 ? memoryPoolMXBean.getUsage().getMax() / 1024 : 0);
        memoryPoolStatus.setCommitedKb(memoryPoolMXBean.getUsage().getCommitted() != 0
                ? memoryPoolMXBean.getUsage().getCommitted() / 1024
                : 0);

        applicationStatus.getMemoryPools().add(memoryPoolStatus);
    }

    return sendSingleEntityResponse(applicationStatus);
}

From source file:sce.JobStoreTXCustom.java

public boolean checkConstraints(JobDataMap jobDataMap) {
    try {// w  w  w .ja  v  a2 s  .  c o m
        if (jobDataMap.containsKey("#jobConstraints")) {
            OperatingSystemMXBean omx = ManagementFactory.getOperatingSystemMXBean();
            com.sun.management.OperatingSystemMXBean osMxBean = null;
            if (omx instanceof com.sun.management.OperatingSystemMXBean) {
                osMxBean = (com.sun.management.OperatingSystemMXBean) omx;
            }
            if (osMxBean != null) {
                //read json from request
                JSONParser parser = new JSONParser();
                Object obj = parser.parse(jobDataMap.getString("#jobConstraints"));
                JSONArray jsonArray = (JSONArray) obj;
                String ipAddress = getIpAddress();
                for (int i = 0; i < jsonArray.size(); i++) {
                    JSONObject jsonobject = (JSONObject) jsonArray.get(i);
                    String systemParameterName = (String) jsonobject.get("systemParameterName"); //system parameter name (osArch, availableProcessors, freePhysicalMemorySize etc.)
                    String operator = (String) jsonobject.get("operator"); // ==, !=, <, >, <=, >=
                    String value = (String) jsonobject.get("value"); //value of the system parameter that must be satisfied
                    String systemParameterValue; //system parameter actual value
                    boolean ipAddressConstraint = false; //set ip address constraint as not satisfied by default

                    switch (systemParameterName) {
                    case "osArch":
                        systemParameterValue = osMxBean.getArch();
                        break;
                    case "availableProcessors":
                        systemParameterValue = Integer.toString(osMxBean.getAvailableProcessors());
                        break;
                    case "osName":
                        systemParameterValue = osMxBean.getArch();
                        break;
                    case "systemLoadAverage":
                        systemParameterValue = Double.toString(osMxBean.getSystemLoadAverage());
                        break;
                    case "osVersion":
                        systemParameterValue = osMxBean.getArch();
                        break;
                    case "committedVirtualMemorySize":
                        systemParameterValue = Long.toString(osMxBean.getCommittedVirtualMemorySize());
                        break;
                    case "freePhysicalMemorySize":
                        systemParameterValue = Long.toString(osMxBean.getFreePhysicalMemorySize());
                        break;
                    case "freeSwapSpaceSize":
                        systemParameterValue = Long.toString(osMxBean.getFreeSwapSpaceSize());
                        break;
                    case "processCpuLoad":
                        systemParameterValue = Double.toString(osMxBean.getProcessCpuLoad());
                        break;
                    case "processCpuTime":
                        systemParameterValue = Long.toString(osMxBean.getProcessCpuTime());
                        break;
                    case "systemCpuLoad":
                        systemParameterValue = Double.toString(osMxBean.getSystemCpuLoad());
                        break;
                    case "totalPhysicalMemorySize":
                        systemParameterValue = Long.toString(osMxBean.getTotalPhysicalMemorySize());
                        break;
                    case "totalSwapSpaceSize":
                        systemParameterValue = Long.toString(osMxBean.getTotalSwapSpaceSize());
                        break;
                    default:
                        systemParameterValue = null;
                    }

                    //if systemParameterName is ipAddress, and there is one ip address that is equal/not equal (depending on the operator) to the scheduler's ip address, then set the ipAddressConstraint to true
                    if (systemParameterName.equals("ipAddress")) {
                        String[] ipAddressesArray = value.split(";");
                        for (String tmp : ipAddressesArray) {
                            if ((operator.equals("==") && ipAddress.equals(tmp))
                                    || (operator.equals("!=") && !ipAddress.equals(tmp))) {
                                ipAddressConstraint = true;
                                break;
                            }
                        }
                        //if the ipAddressConstraint is false, the return false
                        if (!ipAddressConstraint) {
                            return false;
                        }
                    }

                    //if the constraint is not satisfied, then return false
                    //if systemParameterName = ipAddress, then systemParameterValue is null (default switch case) and this if condition is not satisfied
                    if (systemParameterValue != null && ((operator.equals("==")
                            && !isNumeric(systemParameterValue) && !isNumeric(value)
                            && !value.equalsIgnoreCase(systemParameterValue))
                            || (operator.equals("!=") && !isNumeric(systemParameterValue) && !isNumeric(value)
                                    && value.equalsIgnoreCase(systemParameterValue))
                            || (operator.equals("==") && isNumeric(systemParameterValue) && isNumeric(value)
                                    && Double.parseDouble(systemParameterValue) != Double.parseDouble(value))
                            || (operator.equals("!=") && isNumeric(systemParameterValue) && isNumeric(value)
                                    && Double.parseDouble(systemParameterValue) == Double.parseDouble(value))
                            || (operator.equals("<") && isNumeric(systemParameterValue) && isNumeric(value)
                                    && Double.parseDouble(systemParameterValue) >= Double.parseDouble(value))
                            || (operator.equals(">") && isNumeric(systemParameterValue) && isNumeric(value)
                                    && Double.parseDouble(systemParameterValue) <= Double.parseDouble(value))
                            || (operator.equals("<=") && isNumeric(systemParameterValue) && isNumeric(value)
                                    && Double.parseDouble(systemParameterValue) > Double.parseDouble(value))
                            || (operator.equals(">=") && isNumeric(systemParameterValue) && isNumeric(value)
                                    && Double.parseDouble(systemParameterValue) < Double.parseDouble(value)))) {
                        return false;
                    }
                }
            }
        }
        return true;
    } catch (ParseException e) {
        e.printStackTrace();
        return true;
    }
}

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;/*w  w w. j  a  va2 s. c o  m*/
    }

    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:sce.Main.java

public String getSystemStatus() {
    String result;/*from  w w w  .  j  av a  2 s.co  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;
}