List of usage examples for java.lang.management ManagementFactory getRuntimeMXBean
public static RuntimeMXBean getRuntimeMXBean()
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 ww . j ava 2s . 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:org.apache.hadoop.hbase.regionserver.Memcache.java
/** * Code to help figure if our approximation of object heap sizes is close * enough. See hbase-900. Fills memcaches then waits so user can heap * dump and bring up resultant hprof in something like jprofiler which * allows you get 'deep size' on objects. * @param args/*from w w w .j a v a 2s . c o m*/ * @throws InterruptedException * @throws IOException */ public static void main(String[] args) throws InterruptedException, IOException { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); LOG.info("vmName=" + runtime.getVmName() + ", vmVendor=" + runtime.getVmVendor() + ", vmVersion=" + runtime.getVmVersion()); LOG.info("vmInputArguments=" + runtime.getInputArguments()); Memcache memcache1 = new Memcache(); // TODO: x32 vs x64 long size = 0; final int count = 10000; byte[] column = Bytes.toBytes("col:umn"); for (int i = 0; i < count; i++) { // Give each its own ts size += memcache1.put(new KeyValue(Bytes.toBytes(i), column, i), false); } LOG.info("memcache1 estimated size=" + size); for (int i = 0; i < count; i++) { size += memcache1.put(new KeyValue(Bytes.toBytes(i), column, i), false); } LOG.info("memcache1 estimated size (2nd loading of same data)=" + size); // Make a variably sized memcache. Memcache memcache2 = new Memcache(); for (int i = 0; i < count; i++) { size += memcache2.put(new KeyValue(Bytes.toBytes(i), column, i, new byte[i]), false); } LOG.info("memcache2 estimated size=" + size); final int seconds = 30; LOG.info("Waiting " + seconds + " seconds while heap dump is taken"); for (int i = 0; i < seconds; i++) { // Thread.sleep(1000); } LOG.info("Exiting."); }
From source file:pl.edu.icm.visnow.system.main.VisNow.java
private static void startupInfo() { LOGGER.info(""); LOGGER.info(""); LOGGER.info("-------- VisNow startup info --------"); if (debug) {/* w w w . jav a2 s .co m*/ RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean(); List<String> aList = RuntimemxBean.getInputArguments(); LOGGER.info(" * JVM startup flags:"); for (int i = 0; i < aList.size(); i++) { LOGGER.info(" " + aList.get(i)); } LOGGER.info(""); Set<String> p = System.getProperties().stringPropertyNames(); Iterator<String> ip = p.iterator(); LOGGER.info(" * System properties:"); String key; while (ip.hasNext()) { key = ip.next(); LOGGER.info(" " + key + " = " + System.getProperty(key)); } LOGGER.info(""); Map<String, String> env = System.getenv(); Set<String> envKeys = env.keySet(); Iterator<String> envKeysI = envKeys.iterator(); LOGGER.info(" * Environment variables:"); while (envKeysI.hasNext()) { key = envKeysI.next(); LOGGER.info(" " + key + " = " + env.get(key)); } LOGGER.info(" "); LOGGER.info("------ Java Advanced Imaging info -------"); String[] formats = ImageIO.getReaderFormatNames(); String readerDescription, readerVendorName, readerVersion; ImageReader reader; ImageReaderSpi spi; for (int i = 0; i < formats.length; i++) { Iterator<ImageReader> tmpReaders = ImageIO.getImageReadersByFormatName(formats[i]); while (tmpReaders.hasNext()) { reader = tmpReaders.next(); spi = reader.getOriginatingProvider(); readerDescription = spi.getDescription(Locale.US); readerVendorName = spi.getVendorName(); readerVersion = spi.getVersion(); LOGGER.info(" " + formats[i] + ": " + readerDescription + " " + readerVendorName + " " + readerVersion); } } LOGGER.info("-----------------------------------------"); } else { LOGGER.info(" * System properties:"); LOGGER.info(" java.runtime.name = " + System.getProperty("java.runtime.name")); LOGGER.info(" java.vm.version = " + System.getProperty("java.vm.version")); LOGGER.info(" java.vm.vendor = " + System.getProperty("java.vm.vendor")); LOGGER.info(" java.vm.name = " + System.getProperty("java.vm.name")); LOGGER.info(" java.specification.version = " + System.getProperty("java.specification.version")); LOGGER.info(" java.runtime.version = " + System.getProperty("java.runtime.version")); LOGGER.info(" os.arch = " + System.getProperty("os.arch")); LOGGER.info(" os.name = " + System.getProperty("os.name")); LOGGER.info(" os.version = " + System.getProperty("os.version")); LOGGER.info(" java.library.path = " + System.getProperty("java.library.path")); LOGGER.info(" java.class.path = " + System.getProperty("java.class.path")); LOGGER.info(" java.ext.dirs = " + System.getProperty("java.ext.dirs")); LOGGER.info(""); LOGGER.info(" * Environment variables:"); LOGGER.info(" JAVA_HOME = " + System.getenv("JAVA_HOME")); LOGGER.info(" PATH = " + System.getenv("PATH")); LOGGER.info(" LD_LIBRARY_PATH = " + System.getenv("LD_LIBRARY_PATH")); LOGGER.info(" CLASSPATH = " + System.getenv("CLASSPATH")); LOGGER.info("-------------------------------------"); } LOGGER.info(""); LOGGER.info(""); }
From source file:de.xirp.plugin.PluginManager.java
/** * Gets the library path used on startup of this application. * /*from w w w. j a va2 s . com*/ * @return the first entry of the library path. */ private static String getLibraryPath() { String path = ManagementFactory.getRuntimeMXBean().getLibraryPath(); // String path = System.getProperty("java.library.path"); // //$NON-NLS-1$ return path.split(File.pathSeparator)[0]; }
From source file:org.apache.hadoop.hdfs.server.namenode.TestCheckpoint.java
/** * Test that, an attempt to lock a storage that is already locked by nodename, * logs error message that includes JVM name of the namenode that locked it. *//*w ww. j ava 2 s .co m*/ @Test public void testStorageAlreadyLockedErrorMessage() throws Exception { Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = null; StorageDirectory savedSd = null; try { cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); NNStorage storage = cluster.getNameNode().getFSImage().getStorage(); for (StorageDirectory sd : storage.dirIterable(null)) { assertLockFails(sd); savedSd = sd; } LogCapturer logs = GenericTestUtils.LogCapturer.captureLogs(LogFactory.getLog(Storage.class)); try { // try to lock the storage that's already locked savedSd.lock(); fail("Namenode should not be able to lock a storage" + " that is already locked"); } catch (IOException ioe) { // cannot read lock file on Windows, so message cannot get JVM name String lockingJvmName = Path.WINDOWS ? "" : " " + ManagementFactory.getRuntimeMXBean().getName(); String expectedLogMessage = "It appears that another node " + lockingJvmName + " has already locked the storage directory"; assertTrue("Log output does not contain expected log message: " + expectedLogMessage, logs.getOutput().contains(expectedLogMessage)); } } finally { cleanup(cluster); cluster = null; } }
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 {//from www . j a v a2s . c o m cpuUsage = 0; } session.setAttribute(PARAM_PROCESS_CPU_TIME, processCpuTime); session.setAttribute(PARAM_TIMESTAMP, upTime); return cpuUsage; }
From source file:pl.edu.icm.visnow.system.main.VisNow.java
private void initMemory() { RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean(); List<String> aList = RuntimemxBean.getInputArguments(); for (int i = 0; i < aList.size(); i++) { String str = aList.get(i); if (debug) { LOGGER.info("JVM input argument #" + i + ": " + str); }//from w w w . jav a2 s . co m if (str.startsWith("-Xmx")) { String amount = str.substring(4, str.length() - 1); String unit = str.substring(str.length() - 1); try { memoryMax = Long.parseLong(amount); if (unit.equalsIgnoreCase("k")) { memoryMax *= 1024L; } else if (unit.equalsIgnoreCase("m")) { memoryMax *= 1024L * 1024L; } else if (unit.equalsIgnoreCase("g")) { memoryMax *= 1024L * 1024L * 1024L; } } catch (NumberFormatException ex) { memoryMax = Long.MAX_VALUE; return; } if (debug) { LOGGER.info("VisNow started with maximum memory: " + memoryMax + " bytes"); } } } }
From source file:com.vangent.hieos.xutil.atna.XATNALogger.java
/** * *///w w w . j av a 2 s.c o m private void setContextVariables(String targetEndpoint) { try { InetAddress addr = InetAddress.getLocalHost(); this.targetEndpoint = targetEndpoint; this.hostAddress = addr.getHostAddress(); this.pid = ManagementFactory.getRuntimeMXBean().getName(); if (targetEndpoint != null) { MessageContext messageContext = this.getCurrentMessageContext(); this.endpoint = messageContext.getTo().toString(); //this.fromAddress = messageContext.getFrom().toString(); this.fromAddress = (String) messageContext.getProperty(MessageContext.REMOTE_ADDR); this.replyTo = messageContext.getReplyTo().toString(); } else { // A startup/shutdown scenario. this.endpoint = null; this.fromAddress = null; this.replyTo = null; } /* // The endpoint for the current web service running. AxisEndpoint axisEndPoint = (AxisEndpoint) messageContext.getProperty("endpoint"); this.endpoint = axisEndPoint.getEndpointURL(); // IP Address from the caller. this.fromAddress = (String) messageContext.getProperty("REMOTE_ADDR"); */ // DEBUG: /* System.out.println("--- AUDIT VARIABLES ---"); System.out.println("hostname: " + this.hostname); System.out.println("pid:" + this.pid); System.out.println("endpoint: " + this.endpoint); System.out.println("fromAddress: " + this.fromAddress); System.out.println("getFrom().getAddress(): " + messageContext.getFrom().getAddress().toString()); System.out.println("replyTo:" + messageContext.getReplyTo().toString()); System.out.println("replyToAddress: " + messageContext.getReplyTo().getAddress().toString()); System.out.println("-----------------------"); */ } catch (Exception e) { logger.error("Exception in XATNALogger", e); } }
From source file:com.eurelis.opencms.admin.systeminformation.CmsDBPoolsOverviewDialog.java
/** * Initializes the infos object.<p> */// w w w . ja v a2s .co 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:com.cnaude.purpleirc.PurpleIRC.java
/** * * @return//from w w w . ja va 2s. c o m */ public String getMCUptime() { long jvmUptime = ManagementFactory.getRuntimeMXBean().getUptime(); String msg = "Server uptime: " + (int) (jvmUptime / 86400000L) + " days" + " " + (int) (jvmUptime / 3600000L % 24L) + " hours" + " " + (int) (jvmUptime / 60000L % 60L) + " minutes" + " " + (int) (jvmUptime / 1000L % 60L) + " seconds."; return msg; }