Example usage for java.lang.management OperatingSystemMXBean getArch

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

Introduction

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

Prototype

public String getArch();

Source Link

Document

Returns the operating system architecture.

Usage

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

/**
 * Initializes the nodeInfo that will be store in the SWARM NODES MAP
 * //from  w  w w. ja v  a2  s .c  om
 * @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.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());
    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 a  2 s . co  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: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 {/* www  .jav  a  2s  .c o  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:sce.JobStoreTXCustom.java

public boolean checkConstraints(JobDataMap jobDataMap) {
    try {//  ww  w. j  a v a  2 s .  c om
        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:sce.Main.java

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