List of usage examples for java.lang.management ManagementFactory getOperatingSystemMXBean
public static OperatingSystemMXBean getOperatingSystemMXBean()
From source file:gridool.util.system.SystemUtils.java
/** return in nano-seconds */ @Deprecated/*from ww w.ja v a 2s .c o m*/ public static long getProcessCpuTime() { if (preferSigar) { throw new UnsupportedOperationException( "SystemUtils#getProcessCpuTime() is not supported when using Hyperic Sigar"); } else { OperatingSystemMXBean mx = ManagementFactory.getOperatingSystemMXBean(); com.sun.management.OperatingSystemMXBean sunmx = (com.sun.management.OperatingSystemMXBean) mx; return sunmx.getProcessCpuTime(); } }
From source file:xbird.util.system.SystemUtils.java
public static double getCpuLoadAverage() { if (preferSigar) { final Double cpuload; try {/* w ww.j a va2 s. c o m*/ cpuload = (Double) sigarCpuCombinedMtd.invoke(sigarCpuPercMtd.invoke(sigarInstance)); } catch (Exception e) { LogFactory.getLog(SystemUtils.class).error("Failed to obtain CPU load via Hyperic Sigar", e); return -1d; } return cpuload.doubleValue(); } else if (useSunJdk6) { OperatingSystemMXBean mx = ManagementFactory.getOperatingSystemMXBean(); com.sun.management.OperatingSystemMXBean sunmx = (com.sun.management.OperatingSystemMXBean) mx; double d = sunmx.getSystemLoadAverage(); if (d > 0) { return d / NPROCS; } return d; } else { return -1d; } }
From source file:com.searchbox.framework.web.SystemController.java
@ModelAttribute("systemInfo") private Map<String, Object> getSystemInfo() { Map<String, Object> info = new HashMap<String, Object>(); OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); info.put("name", os.getName()); info.put("version", os.getVersion()); info.put("arch", os.getArch()); info.put("systemLoadAverage", os.getSystemLoadAverage()); // com.sun.management.OperatingSystemMXBean addGetterIfAvaliable(os, "committedVirtualMemorySize", info); addGetterIfAvaliable(os, "freePhysicalMemorySize", info); addGetterIfAvaliable(os, "freeSwapSpaceSize", info); addGetterIfAvaliable(os, "processCpuTime", info); addGetterIfAvaliable(os, "totalPhysicalMemorySize", info); addGetterIfAvaliable(os, "totalSwapSpaceSize", info); // com.sun.management.UnixOperatingSystemMXBean addGetterIfAvaliable(os, "openFileDescriptorCount", info); addGetterIfAvaliable(os, "maxFileDescriptorCount", info); try {/*from w w w. j av a 2 s .c o m*/ if (!os.getName().toLowerCase(Locale.ROOT).startsWith("windows")) { // Try some command line things info.put("uname", execute("uname -a")); info.put("uptime", execute("uptime")); } } catch (Exception ex) { ex.printStackTrace(); } return info; }
From source file:xbird.util.system.SystemUtils.java
/** return in nano-seconds */ @Deprecated/*from w ww.j a v a2 s. c om*/ public static long getProcessCpuTime() { if (preferSigar) { throw new UnsupportedOperationException( "SystemUtils#getProcessCpuTime() is not supported when using Hyperic Sigar"); } else if (useSunJdk6) { OperatingSystemMXBean mx = ManagementFactory.getOperatingSystemMXBean(); com.sun.management.OperatingSystemMXBean sunmx = (com.sun.management.OperatingSystemMXBean) mx; return sunmx.getProcessCpuTime(); } else { return _getProcessCpuTime() * 1000000L; /* milli to nano (10^6) */ } }
From source file:it.isislab.dmason.util.SystemManagement.Worker.Updater.java
public static URL getSimulationJar(StartUpData data) { setSeparator();/*from w w w . j ava 2 s. c o 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:net.bull.javamelody.internal.model.JavaInformations.java
private static long buildProcessCpuTimeMillis() { final OperatingSystemMXBean operatingSystem = ManagementFactory.getOperatingSystemMXBean(); if (isSunOsMBean(operatingSystem)) { // nano-secondes converties en milli-secondes return MemoryInformations.getLongFromOperatingSystem(operatingSystem, "getProcessCpuTime") / 1000000; }//from w w w. ja v a 2s.c o m return -1; }
From source file:com.ethercamp.harmony.service.BlockchainInfoService.java
@Scheduled(fixedRate = 5000) private void doUpdateMachineInfoStatus() { final OperatingSystemMXBean bean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); machineInfo.set(new MachineInfoDTO(((Double) (bean.getSystemCpuLoad() * 100)).intValue(), bean.getFreePhysicalMemorySize(), bean.getTotalPhysicalMemorySize(), getFreeDiskSpace())); clientMessageService.sendToTopic("/topic/machineInfo", machineInfo.get()); }
From source file:net.bull.javamelody.internal.model.JavaInformations.java
private static long buildOpenFileDescriptorCount() { final OperatingSystemMXBean operatingSystem = ManagementFactory.getOperatingSystemMXBean(); if (isSunOsMBean(operatingSystem) && isSunUnixMBean(operatingSystem)) { try {// w w w. jav a 2 s . com return MemoryInformations.getLongFromOperatingSystem(operatingSystem, "getOpenFileDescriptorCount"); } catch (final Error e) { // pour issue 16 (using jsvc on ubuntu or debian) return -1; } } return -1; }
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:com.eurelis.opencms.admin.systeminformation.CmsSystemInformationOverviewDialog.java
/** * Initializes the infos object.<p> *///from www .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(); //JVM uptime Date date = new Date(runtimeBean.getUptime()); java.text.SimpleDateFormat simpleFormatH = new java.text.SimpleDateFormat("HH"); java.text.SimpleDateFormat simpleFormatM = new java.text.SimpleDateFormat("mm"); java.text.SimpleDateFormat simpleFormatS = new java.text.SimpleDateFormat("ss"); String jvmuptimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min " + simpleFormatS.format(date) + "s "; //JVM start time date = new Date(runtimeBean.getStartTime()); String jvmstarttimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min " + simpleFormatS.format(date) + "s "; //OpenCms runtime date = new Date(OpenCms.getSystemInfo().getRuntime()); String opencmsruntimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min " + simpleFormatS.format(date) + "s "; //OpenCms startup time date = new Date(OpenCms.getSystemInfo().getStartupTime()); String opencmsstartuptimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min " + simpleFormatS.format(date) + "s "; setOperatingSystem("" + osBean.getName()); setJavaVersion(System.getProperty("java.version")); setJvmUptime("" + jvmuptimestring); setJvmStarttime("" + jvmstarttimestring); setOpenCmsVersion(OpenCms.getSystemInfo().getVersionNumber()); setOpenCmsRuntime("" + opencmsruntimestring); setOpenCmsStartupTime("" + opencmsstartuptimestring); 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; } }