List of usage examples for java.lang.management ManagementFactory getRuntimeMXBean
public static RuntimeMXBean getRuntimeMXBean()
From source file:org.apache.cassandra.utils.HeapUtils.java
/** * Retrieves the value of the <code>HeapDumpPath</code> JVM option. * @return the value of the <code>HeapDumpPath</code> JVM option or <code>null</code> if the value has not been * specified./*w w w. j a v a 2s . co m*/ */ private static String getHeapDumpPathOption() { RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); List<String> inputArguments = runtimeMxBean.getInputArguments(); String heapDumpPathOption = null; for (String argument : inputArguments) { if (argument.startsWith("-XX:HeapDumpPath=")) { heapDumpPathOption = argument; // We do not break in case the option has been specified several times. // In general it seems that JVMs use the right-most argument as the winner. } } if (heapDumpPathOption == null) return null; return heapDumpPathOption.substring(17, heapDumpPathOption.length()); }
From source file:org.diorite.impl.CoreMain.java
public static InitResult init(final OptionSet options, final boolean client) { CoreMain.client = client;//from www .j a v a 2s . c om if (options.has("version")) { return InitResult.VERSION; } if (options.has("?")) { return InitResult.HELP; } final String path = new File(".").getAbsolutePath(); if (path.contains("!") || path.contains("+")) { System.err.println( "Cannot run server in a directory with ! or + in the pathname. Please rename the affected folders and try again."); return InitResult.STOP; } try { CoreMain.enabledDebug = options.has("debug"); CoreMain.debug("===> Debug is enabled! <==="); try { final String lvl = options.valueOf("rld").toString(); if (lvl.length() == 1) { ResourceLeakDetector .setLevel(ResourceLeakDetector.Level.values()[DioriteMathUtils.asInt(lvl, 0)]); } else { ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.valueOf(lvl)); } } catch (final Exception e) { e.printStackTrace(); } if (options.has("noconsole")) { CoreMain.consoleEnabled = false; } int maxPermGen = 0; for (final String s : ManagementFactory.getRuntimeMXBean().getInputArguments()) { if (s.startsWith("-XX:MaxPermSize")) { maxPermGen = DioriteMathUtils.asInt(PERM_GEN_PAT.matcher(s).replaceAll(""), 0); maxPermGen <<= 10 * "kmg".indexOf(Character.toLowerCase(s.charAt(s.length() - 1))); } } if ((Float.parseFloat(System.getProperty("java.class.version")) < JAVA_8) && (maxPermGen < MB_128)) { System.out.println( "Warning, your max perm gen size is not set or less than 128mb. It is recommended you restart Java with the following argument: -XX:MaxPermSize=128M"); } System.out.println("Starting server, please wait..."); registerNbt(); // register all packet classes. RegisterPackets.init(); // TODO: load "magic values" // never remove this line (Material.values), it's needed even if it don't do anything for you. // it will force load all material classes, loading class of one material before "Material" is loaded will throw error. Material.values(); System.out.println("Registered " + Material.getBlockMaterialsCount() + " (" + Material.getAllBlockMaterialsCount() + " with sub-types) diorite blocks."); System.out.println("Registered " + Material.getItemMaterialsCount() + " (" + Material.getAllItemMaterialsCount() + " with sub-types) diorite items."); System.out.println("Registered " + Material.getMaterialsCount() + " (" + Material.getAllMaterialsCount() + " with sub-types) diorite blocks and items."); } catch (final Throwable t) { t.printStackTrace(); } return InitResult.RUN; }
From source file:org.brutusin.instrumentation.logging.LoggingInterceptor.java
private File getFile(Object source, String executionId) { String loggingFolderPath = "JVM-" + ManagementFactory.getRuntimeMXBean().getStartTime() + "/" + Thread.currentThread().getName() + "-" + Thread.currentThread().getId() + "/" + executionId + "-"; if (source instanceof Method) { Method m = (Method) source; loggingFolderPath += m.getDeclaringClass().getName() + "." + m.getName() + "()"; } else if (source instanceof Constructor) { Constructor c = (Constructor) source; String className = c.getDeclaringClass().getName(); if (className != null && className.length() > 0) { loggingFolderPath += className + ".init()"; } else {/*from w w w. j a v a 2s. c om*/ loggingFolderPath += "init()"; } } else { loggingFolderPath += source; } loggingFolderPath += ".log"; loggingFolderPath = loggingFolderPath.replaceAll("[<>:]", "-"); File ret = new File(rootFile, loggingFolderPath); try { FileUtils.forceMkdir(ret.getParentFile()); } catch (IOException ex) { throw new RuntimeException(ex); } return ret; }
From source file:org.yamj.common.model.YamjInfo.java
@SuppressWarnings("rawtypes") public YamjInfo(Class myClass) { // YAMJ Stuff this.projectName = myClass.getPackage().getImplementationVendor(); this.projectVersion = myClass.getPackage().getImplementationVersion(); this.moduleName = myClass.getPackage().getImplementationTitle(); this.moduleDescription = myClass.getPackage().getSpecificationTitle(); if (myClass.getPackage().getSpecificationVendor() != null) { this.buildDateTime = DateTimeTools.parseDate(myClass.getPackage().getSpecificationVendor(), DateTimeTools.BUILD_FORMAT); } else {//from w w w . j a va2 s . com this.buildDateTime = new DateTime(); } this.buildRevision = myClass.getPackage().getSpecificationVersion(); // System Stuff this.processorCores = Runtime.getRuntime().availableProcessors(); this.javaVersion = SystemUtils.JAVA_VERSION; this.osArch = SystemUtils.OS_ARCH; this.osName = SystemUtils.OS_NAME; this.osVersion = SystemUtils.OS_VERSION; // Times this.startUpDateTime = new DateTime(ManagementFactory.getRuntimeMXBean().getStartTime()); // Counts this.counts = new EnumMap<MetaDataType, Long>(MetaDataType.class); // IP Address this.coreIp = SystemTools.getIpAddress(Boolean.TRUE); // Core Port this.corePort = 8888; // TODO: Get this from jetty! // Database IP & Name findDatabaseInfo(); this.baseArtworkUrl = buildBaseUrl(PropertyTools.getProperty("yamj3.file.storage.artwork", "")); this.baseMediainfoUrl = buildBaseUrl(PropertyTools.getProperty("yamj3.file.storage.mediainfo", "")); this.basePhotoUrl = buildBaseUrl(PropertyTools.getProperty("yamj3.file.storage.photo", "")); this.skinDir = buildBaseUrl(PropertyTools.getProperty("yamj3.file.storage.skins", "./skins/")); }
From source file:org.springframework.xd.dirt.container.XDContainer.java
public String getJvmName() { synchronized (this) { if (this.jvmName == null) { this.jvmName = ManagementFactory.getRuntimeMXBean().getName(); }//from w w w . j a v a 2s . c o m } return this.jvmName; }
From source file:fr.ens.biologie.genomique.eoulsan.Main.java
/** * Get JVM arguments./*from w ww . ja v a 2s . c o m*/ * @return the JVM arguments as an array */ public List<String> getJVMArgs() { return ManagementFactory.getRuntimeMXBean().getInputArguments(); }
From source file:edu.usu.sdl.openstorefront.web.rest.service.Application.java
@GET @RequireAdmin// ww w .j a v a 2 s . co m @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:org.terracotta.management.entity.tms.TmsAgentTest.java
@Before public void setUp() throws Exception { PassthroughServer activeServer = new PassthroughServer(); activeServer.setServerName("server-1"); activeServer.setBindPort(9510);//w w w.jav a2 s.com activeServer.setGroupPort(9610); activeServer.registerServerEntityService(new TmsAgentEntityServerService()); activeServer.registerClientEntityService(new TmsAgentEntityClientService()); activeServer.registerClientEntityService(new ManagementAgentEntityClientService()); activeServer.registerServerEntityService(new ManagementAgentEntityServerService()); stripeControl = new PassthroughClusterControl("server-1", activeServer); clientIdentifier = ClientIdentifier.create( Long.parseLong(ManagementFactory.getRuntimeMXBean().getName().split("@")[0]), InetAddress.getLocalHost().getHostAddress(), "UNKNOWN", "uuid"); expectedCluster = Cluster.create() .addStripe(Stripe.create("stripe-1") .addServer(Server.create("server-1").setBindAddress("0.0.0.0").setBindPort(9510) .setGroupPort(9610).setHostName("localhost").setStartTime(0).setActivateTime(0) .setHostAddress("127.0.0.1").setVersion("Version Passthrough 5.0.0-SNAPSHOT") .setBuildId("Build ID").setState(Server.State.ACTIVE) .addServerEntity(ServerEntity.create(getClass().getSimpleName(), TmsAgentEntity.class.getName(), 1)))) .addClient(Client.create(clientIdentifier).setHostName(InetAddress.getLocalHost().getHostName())); client = expectedCluster.getClients().values().iterator().next(); connection = Connection.create("uuid", expectedCluster.getStripe("stripe-1").get().getServerByName("server-1").get(), Endpoint.create(InetAddress.getLocalHost().getHostAddress(), -1) // values set by passthrough system ); client.addConnection(connection); assertTrue(connection.fetchServerEntity(getClass().getSimpleName(), TmsAgentConfig.ENTITY_TYPE)); }
From source file:com.acmutv.ontoqa.tool.runtime.RuntimeManager.java
/** * Returns the current JVM name./*from w w w .ja v a2 s . c om*/ * @return the JVM name. */ public static String getJvmName() { return ManagementFactory.getRuntimeMXBean().getName(); }
From source file:org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore.java
@JmxExport(description = "generate charts for all measurements") public List<String> generateCharts(final int width, final int height) throws IOException { long startTime = ManagementFactory.getRuntimeMXBean().getStartTime(); long endTime = System.currentTimeMillis(); return generateCharts(startTime, endTime, width, height); }