Example usage for java.lang.management OperatingSystemMXBean getName

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

Introduction

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

Prototype

public String getName();

Source Link

Document

Returns the operating system name.

Usage

From source file:Test.java

public static void main(String[] args) {
    RuntimeMXBean mxBean = ManagementFactory.getPlatformMXBean(RuntimeMXBean.class);

    System.out.println("JVM Name: " + mxBean.getName());
    System.out.println("JVM Specification Name: " + mxBean.getSpecName());
    System.out.println("JVM Specification Version: " + mxBean.getSpecVersion());
    System.out.println("JVM Implemenation Name: " + mxBean.getVmName());
    System.out.println("JVM Implemenation Vendor: " + mxBean.getVmVendor());
    System.out.println("JVM Implemenation Version: " + mxBean.getVmVersion());

    // Using the getPlatformMXBeans method
    List<OperatingSystemMXBean> list = ManagementFactory.getPlatformMXBeans(OperatingSystemMXBean.class);
    System.out.println("size: " + list.size());
    for (OperatingSystemMXBean bean : list) {
        System.out.println("Operating System Name: " + bean.getName());
        System.out.println("Operating System Architecture: " + bean.getArch());
        System.out.println("Operating System Version: " + bean.getVersion());
    }//from   www  .j  a  va2  s  .  co  m

}

From source file:api.Status.java

public static Result getMeta() {
    ObjectNode meta = Json.newObject();/*from  www.jav  a  2s  .c  o  m*/

    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    meta.put("osName", os.getName());
    meta.put("osVersion", os.getVersion());
    meta.put("arch", os.getArch());
    meta.put("cpus", os.getAvailableProcessors());

    return ok(meta.toString());
}

From source file:ro.nextreports.server.web.debug.InfoUtil.java

public static List<Info> getGeneralJVMInfo() {
    List<Info> infos = new ArrayList<Info>();

    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    infos.add(new Info("uptime", "" + Duration.milliseconds(runtimeBean.getUptime()).toString()));
    infos.add(new Info("name", runtimeBean.getName()));
    infos.add(new Info("pid", runtimeBean.getName().split("@")[0]));

    OperatingSystemMXBean systemBean = ManagementFactory.getOperatingSystemMXBean();
    infos.add(new Info("os name", "" + systemBean.getName()));
    infos.add(new Info("os version", "" + systemBean.getVersion()));
    infos.add(new Info("system load average", "" + systemBean.getSystemLoadAverage()));
    infos.add(new Info("available processors", "" + systemBean.getAvailableProcessors()));

    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    infos.add(new Info("thread count", "" + threadBean.getThreadCount()));
    infos.add(new Info("peak thread count", "" + threadBean.getPeakThreadCount()));

    MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
    infos.add(new Info("heap memory used",
            FileUtils.byteCountToDisplaySize(memoryBean.getHeapMemoryUsage().getUsed())));
    infos.add(new Info("non-heap memory used",
            FileUtils.byteCountToDisplaySize(memoryBean.getNonHeapMemoryUsage().getUsed())));

    return infos;
}

From source file:net.centro.rtb.monitoringcenter.infos.OperatingSystemInfo.java

public static OperatingSystemInfo create() {
    OperatingSystemInfo operatingSystemInfo = new OperatingSystemInfo();

    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();

    operatingSystemInfo.name = operatingSystemMXBean.getName();
    operatingSystemInfo.version = operatingSystemMXBean.getVersion();

    if (SystemUtils.IS_OS_LINUX) {
        operatingSystemInfo.distributionName = resolveLinuxDistributionName();
    }/*from   w w w.j a v a  2  s  .  com*/

    operatingSystemInfo.architecture = operatingSystemMXBean.getArch();
    operatingSystemInfo.numberOfLogicalProcessors = operatingSystemMXBean.getAvailableProcessors();

    if (com.sun.management.OperatingSystemMXBean.class.isAssignableFrom(operatingSystemMXBean.getClass())) {
        com.sun.management.OperatingSystemMXBean sunOsMxBean = com.sun.management.OperatingSystemMXBean.class
                .cast(operatingSystemMXBean);
        operatingSystemInfo.physicalMemorySizeInBytes = sunOsMxBean.getTotalPhysicalMemorySize();
        operatingSystemInfo.swapSpaceSizeInBytes = sunOsMxBean.getTotalSwapSpaceSize();
    }

    Map<String, Long> diskSpaceInBytesByRootPaths = new HashMap<>();
    for (File rootFile : File.listRoots()) {
        diskSpaceInBytesByRootPaths.put(rootFile.getAbsolutePath(), rootFile.getTotalSpace());
    }
    operatingSystemInfo.diskSpaceInBytesByRootPaths = diskSpaceInBytesByRootPaths;

    return operatingSystemInfo;
}

From source file:org.apache.solr.handler.admin.SystemInfoHandler.java

/**
 * Get system info//from  www. ja v  a 2s  .  c o  m
 */
public static SimpleOrderedMap<Object> getSystemInfo() throws Exception {
    SimpleOrderedMap<Object> info = new SimpleOrderedMap<Object>();

    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    info.add("name", os.getName());
    info.add("version", os.getVersion());
    info.add("arch", os.getArch());

    // Java 1.6
    addGetterIfAvaliable(os, "systemLoadAverage", info);

    // com.sun.management.UnixOperatingSystemMXBean
    addGetterIfAvaliable(os, "openFileDescriptorCount", info);
    addGetterIfAvaliable(os, "maxFileDescriptorCount", info);

    // com.sun.management.OperatingSystemMXBean
    addGetterIfAvaliable(os, "committedVirtualMemorySize", info);
    addGetterIfAvaliable(os, "totalPhysicalMemorySize", info);
    addGetterIfAvaliable(os, "totalSwapSpaceSize", info);
    addGetterIfAvaliable(os, "processCpuTime", info);

    try {
        if (!os.getName().toLowerCase(Locale.ENGLISH).startsWith("windows")) {
            // Try some command line things
            info.add("uname", execute("uname -a"));
            info.add("ulimit", execute("ulimit -n"));
            info.add("uptime", execute("uptime"));
        }
    } catch (Throwable ex) {
    } // ignore
    return info;
}

From source file:org.fluentd.jvmwatcher.data.JvmWatchState.java

/**
 * @param clientPrixy/*from ww w . ja va 2  s .co m*/
 * @return
 */
public static JvmWatchState makeJvmWatchState(JvmClientProxy clientProxy) {
    // null check
    if (null == clientProxy) {
        return null;
    }
    if (null == clientProxy.getLocalJvmInfo()) {
        return null;
    }

    // create data object
    JvmWatchState ret = new JvmWatchState();

    // set Local JVM Information
    ret.commandLine_ = clientProxy.getLocalJvmInfo().getCommandLine_();
    ret.displayName_ = clientProxy.getLocalJvmInfo().getDisplayName();
    ret.jvmId_ = clientProxy.getLocalJvmInfo().getJvmid();
    ret.shortName_ = clientProxy.getLocalJvmInfo().getShortName();

    // create log line array
    ret.stateLog_ = new ArrayList<JvmStateLog>();

    // set JVM information
    try {
        // CompilationMXBean
        CompilationMXBean compilationBean = clientProxy.getCompilationMXBean();
        if (null != compilationBean) {
            ret.jitName_ = compilationBean.getName();
        }

        // OperatingSystemMXBean
        OperatingSystemMXBean OpeSysBean = clientProxy.getOperatingSystemMXBean();
        if (null != OpeSysBean) {
            ret.osArch_ = OpeSysBean.getArch();
            ret.osName_ = OpeSysBean.getName();
            ret.osVersion_ = OpeSysBean.getVersion();
        }

        // RuntimeMXBean
        RuntimeMXBean runtimeBean = clientProxy.getRuntimeMXBean();
        if (null != runtimeBean) {
            ret.jvmStartTime_ = runtimeBean.getStartTime();
            ret.jvmRuntimeName_ = runtimeBean.getName();
            ret.vmName_ = runtimeBean.getVmName();
            ret.vmVender_ = runtimeBean.getVmVendor();
            ret.vmVersion_ = runtimeBean.getVmVersion();
            ret.specName_ = runtimeBean.getSpecName();
            ret.specVender_ = runtimeBean.getSpecVendor();
            ret.specVersion_ = runtimeBean.getSpecVersion();
        }
    } catch (IOException ex) {
        log.error("get MXBean error.", ex);
        // close JvmClientProxy
        clientProxy.disconnect();
    } catch (Exception ex) {
        log.error("get MXBean error.", ex);
        // close JvmClientProxy
        clientProxy.disconnect();
    }

    return ret;
}

From source file:it.isislab.dmason.util.SystemManagement.Worker.Updater.java

private static void setSeparator() {
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();

    if (os.getName().contains("Windows"))
        SEPARATOR = "\\";
    if (os.getName().contains("Linux") || os.getName().contains("OS X"))
        SEPARATOR = "/";
}

From source file:it.isislab.dmason.util.SystemManagement.Worker.Updater.java

public static URL getSimulationJar(StartUpData data) {
    setSeparator();//  www .j a  va 2s .  co  m
    FTPIP = data.getFTPAddress().getIPaddress();
    FTPPORT = data.getFTPAddress().getPort();

    //System.out.println("FTP IP: "+FTPIP+"FTP PORT: "+FTPPORT);

    downloadJar(data.getJarName(), "sim");

    File f = new File(DOWNLOADED_JAR_PATH + SEPARATOR + data.getJarName());

    //System.out.println("file:"+File.separator+f.getAbsolutePath());
    URL url = null;
    try {
        OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();

        if (os.getName().contains("Linux") || os.getName().contains("OSX"))
            url = new URL("file:" + File.separator + File.separator + f.getAbsolutePath());
        else
            url = new URL("file:" + File.separator + f.getAbsolutePath());

    } catch (MalformedURLException e) {
        System.out.println("Invalid URL: ");
    }
    return url;

}

From source file:org.pepstock.jem.node.NodeInfoUtility.java

/**
  * Factory creates a NodeInfo copying a set of information from Member
  * object of Hazelcast framework. NodeInfo will use Uuid of Member as the
  * key.//  ww w .  j av a 2 s  . c  om
  * 
  * @see org.pepstock.jem.node.NodeInfo
  * @param member member object of Hazelcast framework
  * @param info node info to load
  * @throws NodeException if any exception occurs
  */
public static final void loadNodeInfo(Member member, NodeInfo info) throws NodeException {
    String jemVersion = getManifestAttribute(ConfigKeys.JEM_MANIFEST_VERSION);
    // sets the version
    if (jemVersion != null) {
        info.setJemVersion(jemVersion);
    }
    // set uuid of member of hazelcast as key
    info.setKey(member.getUuid());
    // set status starting at the beginning
    info.setStatus(Status.STARTING);
    // sets boolean if has affinity loader

    // for net info of member, loads all info inside of nodeinfo
    // port of RMI will be set later
    InetSocketAddress address = member.getInetSocketAddress();
    info.setPort(address.getPort());
    info.setIpaddress(address.getAddress().getHostAddress());

    // sets label to be displayed by GRS
    info.setLabel(info.getIpaddress() + ":" + info.getPort());

    // sets execution environment
    info.setExecutionEnvironment(Main.EXECUTION_ENVIRONMENT);
    // use JMX to extract current process id
    info.setProcessId(ManagementFactory.getRuntimeMXBean().getName());

    // extracts the name using the MXBean result
    String hostname = StringUtils.substringAfter(info.getProcessId(), "@");
    info.setHostname(hostname);

    // extracts from operating ssytem MXbean all info about the ssytem
    OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean();
    info.getNodeInfoBean().setSystemArchitecture(bean.getArch());
    info.getNodeInfoBean().setAvailableProcessors(bean.getAvailableProcessors());
    info.getNodeInfoBean().setSystemName(bean.getName());

    // uses SIGAR to get total memory and the user used by JEM to start
    try {
        info.getNodeInfoBean().setTotalMemory(SIGAR.getMem().getTotal());
        ProcCredName cred = SIGAR.getProcCredName(SIGAR.getPid());
        info.setUser(cred.getUser());
    } catch (SigarException e) {
        throw new NodeException(e.getMessage(), e);
    }
    // informs the node itself that it has been loaded
    info.loaded();
}

From source file:org.craftercms.commons.monitoring.VersionMonitor.java

private void initOS() {
    OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
    operating_system = os.getName() + "-" + os.getVersion();
    os_architecture = os.getArch();// w  w w  .  j a v a 2 s.  c o  m
    system_encoding = System.getProperty(FILE_ENCODING_SYSTEM_PROP_KEY);
}