List of usage examples for java.lang.management RuntimeMXBean getInputArguments
public java.util.List<String> getInputArguments();
From source file:Main.java
public static void main(String args[]) throws Exception { RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean(); System.out.println(mx.getInputArguments()); }
From source file:Main.java
public static void main(String args[]) throws Exception { RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean(); System.out.println(mx.getBootClassPath()); System.out.println(mx.getClassPath()); System.out.println(mx.getInputArguments()); System.out.println(mx.getSystemProperties()); System.out.println(new Date(mx.getStartTime())); System.out.println(mx.getUptime() + " ms"); }
From source file:net.centro.rtb.monitoringcenter.infos.JvmInfo.java
public static JvmInfo create() { JvmInfo jvmInfo = new JvmInfo(); jvmInfo.specVersion = SystemUtils.JAVA_SPECIFICATION_VERSION; jvmInfo.classVersion = SystemUtils.JAVA_CLASS_VERSION; jvmInfo.jreVersion = SystemUtils.JAVA_VERSION; jvmInfo.jreVendor = SystemUtils.JAVA_VENDOR; jvmInfo.vmName = SystemUtils.JAVA_VM_NAME; jvmInfo.vmVendor = SystemUtils.JAVA_VM_VENDOR; jvmInfo.vmVersion = SystemUtils.JAVA_VM_VERSION; RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); jvmInfo.inputArguments = new ArrayList<>(runtimeMXBean.getInputArguments()); jvmInfo.startedTimestamp = new Date(runtimeMXBean.getStartTime()); jvmInfo.defaultTimeZone = TimeZone.getDefault().getID(); jvmInfo.defaultCharset = Charset.defaultCharset().displayName(); return jvmInfo; }
From source file:com.alibaba.wasp.util.ServerCommandLine.java
/** * Log information about the currently running JVM. *//*ww w. ja v a 2 s . c o m*/ public static void logJVMInfo() { // Print out vm stats before starting up. RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); if (runtime != null) { LOG.info("vmName=" + runtime.getVmName() + ", vmVendor=" + runtime.getVmVendor() + ", vmVersion=" + runtime.getVmVersion()); LOG.info("vmInputArguments=" + runtime.getInputArguments()); } }
From source file:info.novatec.inspectit.util.UnderlyingSystemInfo.java
/** * Tests if the compressed pointers are used. Note that this method will return true only if the * JVM is 64bit, ignoring the fact that the 32bit JVM can also have * <code>+UseCompressedOops</code> argument. This method has been tested with Sun & IBM virtual * machine, and behavior with different providers is unknown. * <p>// w w w .j a v a 2s .c om * IMPORTANT (SUN & ORACLE): Compressed oops is supported and enabled by default in Java SE 6u23 * and later. In Java SE 7, use of compressed oops is the default for 64-bit JVM processes when * -Xmx isn't specified and for values of -Xmx less than 32 gigabytes. For JDK 6 before the 6u23 * release, use the -XX:+UseCompressedOops flag with the java command to enable the feature. * <p> * IMPORTANT (IBM): From Java 6 SR 5, 64-bit JVMs recognize the following Oracle JVM options: * -XX:+UseCompressedOops This enables compressed references in 64-bit JVMs. It is identical to * specifying the -Xcompressedrefs option. -XX:-UseCompressedOops This prevents use of * compressed references in 64-bit JVMs. * * @return True only if JVM is 64bit and compressed oops are used. */ private static boolean isCompressedOops() { if (IS_64BIT) { RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); if (null != runtimeMXBean) { List<String> arguments = runtimeMXBean.getInputArguments(); for (String argument : arguments) { if (argument.indexOf("+UseCompressedOops") != -1 || argument.indexOf("compressedrefs") != -1) { return true; } else if (argument.indexOf("-UseCompressedOops") != -1) { return false; } } } switch (getJvmProvider()) { case SUN: case ORACLE: if (getJavaVersion() == JavaVersion.JAVA_1_7) { long max = Runtime.getRuntime().maxMemory(); return max == Long.MAX_VALUE || max < MAX_COMPRESSED_OOPS_JAVA7_MEMORY; } else if (getJavaVersion() == JavaVersion.JAVA_1_6) { try { int subversionIndexStart = JAVA_VERSION_TRIMMED.indexOf('_'); boolean isAbove6u23 = Integer .parseInt(JAVA_VERSION_TRIMMED.substring(subversionIndexStart + 1)) >= 23; return isAbove6u23; } catch (NumberFormatException e) { break; } } break; default: break; } } return false; }
From source file:com.searchbox.framework.web.SystemController.java
@ModelAttribute("jvmInfo") public static Map<String, Object> getJvmInfo() { Map<String, Object> jvm = new HashMap<String, Object>(); final String javaVersion = System.getProperty("java.specification.version", "unknown"); final String javaVendor = System.getProperty("java.specification.vendor", "unknown"); final String javaName = System.getProperty("java.specification.name", "unknown"); final String jreVersion = System.getProperty("java.version", "unknown"); final String jreVendor = System.getProperty("java.vendor", "unknown"); final String vmVersion = System.getProperty("java.vm.version", "unknown"); final String vmVendor = System.getProperty("java.vm.vendor", "unknown"); final String vmName = System.getProperty("java.vm.name", "unknown"); // Summary Info jvm.put("version", jreVersion + " " + vmVersion); jvm.put("name", jreVendor + " " + vmName); // details/*from w w w. j a va2 s . co m*/ Map<String, Object> java = new HashMap<String, Object>(); java.put("vendor", javaVendor); java.put("name", javaName); java.put("version", javaVersion); jvm.put("spec", java); Map<String, Object> jre = new HashMap<String, Object>(); jre.put("vendor", jreVendor); jre.put("version", jreVersion); jvm.put("jre", jre); Map<String, Object> vm = new HashMap<String, Object>(); vm.put("vendor", vmVendor); vm.put("name", vmName); vm.put("version", vmVersion); jvm.put("vm", vm); Runtime runtime = Runtime.getRuntime(); jvm.put("processors", runtime.availableProcessors()); // not thread safe, but could be thread local DecimalFormat df = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.ROOT)); Map<String, Object> mem = new HashMap<String, Object>(); Map<String, Object> raw = new HashMap<String, Object>(); long free = runtime.freeMemory(); long max = runtime.maxMemory(); long total = runtime.totalMemory(); long used = total - free; double percentUsed = ((double) (used) / (double) max) * 100; raw.put("free", free); mem.put("free", humanReadableUnits(free, df)); raw.put("total", total); mem.put("total", humanReadableUnits(total, df)); raw.put("max", max); mem.put("max", humanReadableUnits(max, df)); raw.put("used", used); mem.put("used", humanReadableUnits(used, df) + " (%" + df.format(percentUsed) + ")"); raw.put("used%", percentUsed); mem.put("raw", raw); jvm.put("memory", mem); // JMX properties -- probably should be moved to a different handler Map<String, Object> jmx = new HashMap<String, Object>(); try { RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean(); jmx.put("bootclasspath", mx.getBootClassPath()); jmx.put("classpath", mx.getClassPath()); // the input arguments passed to the Java virtual machine // which does not include the arguments to the main method. jmx.put("commandLineArgs", mx.getInputArguments()); jmx.put("startTime", new Date(mx.getStartTime())); jmx.put("upTimeMS", mx.getUptime()); } catch (Exception e) { LOGGER.warn("Error getting JMX properties", e); } jvm.put("jmx", jmx); return jvm; }
From source file:co.aikar.timings.TimingsExport.java
/** * Checks if any pending reports are being requested, and builds one if needed. *//* w w w . ja v a 2 s . c om*/ static void reportTimings() { if (requestingReport.isEmpty()) { return; } TimingsReportListener listeners = new TimingsReportListener(requestingReport); listeners.addConsoleIfNeeded(); requestingReport.clear(); long now = System.currentTimeMillis(); final long lastReportDiff = now - lastReport; if (lastReportDiff < 60000) { listeners.sendMessage(ChatColor.RED + "Please wait at least 1 minute in between Timings reports. (" + (int) ((60000 - lastReportDiff) / 1000) + " seconds)"); listeners.done(); return; } final long lastStartDiff = now - TimingsManager.timingStart; if (lastStartDiff < 180000) { listeners.sendMessage(ChatColor.RED + "Please wait at least 3 minutes before generating a Timings report. Unlike Timings v1, v2 benefits from longer timings and is not as useful with short timings. (" + (int) ((180000 - lastStartDiff) / 1000) + " seconds)"); listeners.done(); return; } listeners.sendMessage(ChatColor.GREEN + "Preparing Timings Report..."); lastReport = now; Map parent = createObject( // Get some basic system details about the server pair("version", Bukkit.getVersion()), pair("maxplayers", Bukkit.getMaxPlayers()), pair("start", TimingsManager.timingStart / 1000), pair("end", System.currentTimeMillis() / 1000), pair("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000)); if (!TimingsManager.privacy) { appendObjectData(parent, pair("server", Bukkit.getServerName()), pair("motd", Bukkit.getServer().getMotd()), pair("online-mode", Bukkit.getServer().getOnlineMode()), pair("icon", Bukkit.getServer().getServerIcon().getData())); } final Runtime runtime = Runtime.getRuntime(); RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); parent.put("system", createObject(pair("timingcost", getCost()), pair("name", System.getProperty("os.name")), pair("version", System.getProperty("os.version")), pair("jvmversion", System.getProperty("java.version")), pair("arch", System.getProperty("os.arch")), pair("maxmem", runtime.maxMemory()), pair("cpu", runtime.availableProcessors()), pair("runtime", ManagementFactory.getRuntimeMXBean().getUptime()), pair("flags", StringUtils.join(runtimeBean.getInputArguments(), " ")), pair("gc", toObjectMapper(ManagementFactory.getGarbageCollectorMXBeans(), input -> pair(input.getName(), toArray(input.getCollectionCount(), input.getCollectionTime())))))); Set<Material> tileEntityTypeSet = Sets.newHashSet(); Set<EntityType> entityTypeSet = Sets.newHashSet(); int size = HISTORY.size(); TimingHistory[] history = new TimingHistory[size + 1]; int i = 0; for (TimingHistory timingHistory : HISTORY) { tileEntityTypeSet.addAll(timingHistory.tileEntityTypeSet); entityTypeSet.addAll(timingHistory.entityTypeSet); history[i++] = timingHistory; } history[i] = new TimingHistory(); // Current snapshot tileEntityTypeSet.addAll(history[i].tileEntityTypeSet); entityTypeSet.addAll(history[i].entityTypeSet); Map handlers = createObject(); for (TimingIdentifier.TimingGroup group : TimingIdentifier.GROUP_MAP.values()) { for (TimingHandler id : group.handlers) { if (!id.isTimed() && !id.isSpecial()) { continue; } handlers.put(id.id, toArray(group.id, id.name)); } } parent.put("idmap", createObject( pair("groups", toObjectMapper( TimingIdentifier.GROUP_MAP.values(), group -> pair(group.id, group.name))), pair("handlers", handlers), pair( "worlds", toObjectMapper(TimingHistory.worldMap.entrySet(), input -> pair(input.getValue(), input.getKey()))), pair("tileentity", toObjectMapper(tileEntityTypeSet, input -> pair(input.getId(), input.name()))), pair("entity", toObjectMapper(entityTypeSet, input -> pair(input.getTypeId(), input.name()))))); // Information about loaded plugins parent.put("plugins", toObjectMapper(Bukkit.getPluginManager().getPlugins(), plugin -> pair(plugin.getName(), createObject(pair("version", plugin.getDescription().getVersion()), pair("description", String.valueOf(plugin.getDescription().getDescription()).trim()), pair("website", plugin.getDescription().getWebsite()), pair("authors", StringUtils.join(plugin.getDescription().getAuthors(), ", ")))))); // Information on the users Config parent.put("config", createObject(pair("bukkit", mapAsJSON(Bukkit.spigot().getConfig(), null)))); new TimingsExport(listeners, parent, history).start(); }
From source file:com.gemstone.gemfire.test.dunit.standalone.ProcessManager.java
/** * Get the java agent passed to this process and pass it to the child VMs. * This was added to support jacoco code coverage reports */// w w w. j ava2s .c om private String getAgentString() { RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); if (runtimeBean != null) { for (String arg : runtimeBean.getInputArguments()) { if (arg.contains("-javaagent:")) { //HACK for gradle bug GRADLE-2859. Jacoco is passing a relative path //That won't work when we pass this to dunit VMs in a different //directory arg = arg.replace("-javaagent:..", "-javaagent:" + System.getProperty("user.dir") + File.separator + ".."); arg = arg.replace("destfile=..", "destfile=" + System.getProperty("user.dir") + File.separator + ".."); return arg; } } } return "-DdummyArg=true"; }
From source file:net.centro.rtb.monitoringcenter.metrics.system.jvm.GarbageCollectorMetricSet.java
GarbageCollectorMetricSet() { this.garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans(); this.minorGcTimer = new Timer(); this.majorGcTimer = new Timer(); // Determine the location of the gc log file (note that there's not support for rolling gc logs) String gcLogFilePath = null;// w ww . j av a2 s . c om RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); List<String> inputArguments = runtimeMXBean.getInputArguments(); for (String argument : inputArguments) { if (argument.startsWith(LOG_GC_JVM_PARAM)) { gcLogFilePath = argument.substring(LOG_GC_JVM_PARAM.length()); break; } } if (gcLogFilePath != null && !gcLogFilePath.trim().isEmpty()) { final File gcLogFile = new File(gcLogFilePath); if (gcLogFile.exists()) { this.fullCollectionsCounter = new AtomicLong(); this.gcLogTailer = Tailer.create(gcLogFile, new TailerListenerAdapter() { @Override public void handle(String line) { if (line != null && line.contains(FULL_GC_LOG_STRING)) { fullCollectionsCounter.incrementAndGet(); } } }, GC_LOG_FILE_TAIL_DELAY_IN_MILLIS); } } // Attach a listener to the GarbageCollectorMXBeans this.gcEventListener = new NotificationListener() { @Override public void handleNotification(Notification notification, Object handback) { String notificationType = notification.getType(); if (notificationType.equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) { CompositeData compositeData = CompositeData.class.cast(notification.getUserData()); GarbageCollectionNotificationInfo gcNotificationInfo = GarbageCollectionNotificationInfo .from(compositeData); if (GC_NOTIFICATION_MINOR_GC_ACTION_STRING.equals(gcNotificationInfo.getGcAction())) { minorGcTimer.update(gcNotificationInfo.getGcInfo().getDuration(), TimeUnit.MILLISECONDS); } else if (GC_NOTIFICATION_MAJOR_GC_ACTION_STRING.equals(gcNotificationInfo.getGcAction())) { majorGcTimer.update(gcNotificationInfo.getGcInfo().getDuration(), TimeUnit.MILLISECONDS); } } } }; for (final GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMXBeans) { if (NotificationEmitter.class.isInstance(garbageCollectorMXBean)) { NotificationEmitter emitter = NotificationEmitter.class.cast(garbageCollectorMXBean); emitter.addNotificationListener(gcEventListener, null, null); } } // Set up metrics Map<String, Metric> metricsByNames = new HashMap<>(); if (fullCollectionsCounter != null) { this.fullCollectionsGauge = new Gauge<Long>() { @Override public Long getValue() { return fullCollectionsCounter.get(); } }; metricsByNames.put("fullCollections", fullCollectionsGauge); } metricsByNames.put("majorGcTimer", majorGcTimer); metricsByNames.put("minorGcTimer", minorGcTimer); List<GarbageCollectorStatus> garbageCollectorStatuses = new ArrayList<>(); for (final GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMXBeans) { final String garbageCollectorName = garbageCollectorMXBean.getName(); final String garbageCollectorNamespace = MetricNamingUtil.join("collectors", MetricNamingUtil.sanitize(garbageCollectorName)); final Gauge<Long> collectionsGauge; if (garbageCollectorMXBean.getCollectionCount() >= 0) { collectionsGauge = new Gauge<Long>() { @Override public Long getValue() { return garbageCollectorMXBean.getCollectionCount(); } }; metricsByNames.put(MetricNamingUtil.join(garbageCollectorNamespace, "collections"), collectionsGauge); } else { collectionsGauge = null; } final Gauge<Long> totalCollectionDurationInMillisGauge; if (garbageCollectorMXBean.getCollectionTime() >= 0) { totalCollectionDurationInMillisGauge = new Gauge<Long>() { @Override public Long getValue() { return garbageCollectorMXBean.getCollectionTime(); } }; metricsByNames.put( MetricNamingUtil.join(garbageCollectorNamespace, "totalCollectionDurationInMillis"), totalCollectionDurationInMillisGauge); } else { totalCollectionDurationInMillisGauge = null; } garbageCollectorStatuses.add(new GarbageCollectorStatus() { @Override public String getName() { return garbageCollectorName; } @Override public Gauge<Long> getCollectionsGauge() { return collectionsGauge; } @Override public Gauge<Long> getTotalCollectionDurationInMillisGauge() { return totalCollectionDurationInMillisGauge; } }); } this.garbageCollectorStatuses = garbageCollectorStatuses; this.metricsByNames = metricsByNames; }
From source file:com.evolveum.midpoint.web.page.admin.configuration.PageAbout.java
private void initLayout() { Label revision = new Label(ID_REVISION, createStringResource("PageAbout.midPointRevision")); revision.setRenderBodyOnly(true);//from w w w . j a v a2 s . c om add(revision); ListView<SystemItem> listSystemItems = new ListView<SystemItem>(ID_LIST_SYSTEM_ITEMS, getItems()) { @Override protected void populateItem(ListItem<SystemItem> item) { SystemItem systemItem = item.getModelObject(); Label property = new Label(ID_PROPERTY, systemItem.getProperty()); property.setRenderBodyOnly(true); item.add(property); Label value = new Label(ID_VALUE, systemItem.getValue()); value.setRenderBodyOnly(true); item.add(value); } }; add(listSystemItems); addLabel(ID_IMPLEMENTATION_SHORT_NAME, "implementationShortName"); addLabel(ID_IMPLEMENTATION_DESCRIPTION, "implementationDescription"); addLabel(ID_IS_EMBEDDED, "isEmbedded"); addLabel(ID_DRIVER_SHORT_NAME, "driverShortName"); addLabel(ID_DRIVER_VERSION, "driverVersion"); addLabel(ID_REPOSITORY_URL, "repositoryUrl"); ListView<LabeledString> additionalDetails = new ListView<LabeledString>(ID_ADDITIONAL_DETAILS, new PropertyModel<List<? extends LabeledString>>(repoDiagModel, "additionalDetails")) { @Override protected void populateItem(ListItem<LabeledString> item) { LabeledString labeledString = item.getModelObject(); Label property = new Label(ID_DETAIL_NAME, labeledString.getLabel()); property.setRenderBodyOnly(true); item.add(property); Label value = new Label(ID_DETAIL_VALUE, labeledString.getData()); value.setRenderBodyOnly(true); item.add(value); } }; add(additionalDetails); ListView<LabeledString> provisioningAdditionalDetails = new ListView<LabeledString>( ID_PROVISIONING_ADDITIONAL_DETAILS, new PropertyModel<List<? extends LabeledString>>(provisioningDiagModel, "additionalDetails")) { @Override protected void populateItem(ListItem<LabeledString> item) { LabeledString labeledString = item.getModelObject(); Label property = new Label(ID_PROVISIONING_DETAIL_NAME, labeledString.getLabel()); property.setRenderBodyOnly(true); item.add(property); Label value = new Label(ID_PROVISIONING_DETAIL_VALUE, labeledString.getData()); value.setRenderBodyOnly(true); item.add(value); } }; add(provisioningAdditionalDetails); Label jvmProperties = new Label(ID_JVM_PROPERTIES, new LoadableModel<String>(false) { @Override protected String load() { try { RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); List<String> arguments = runtimeMxBean.getInputArguments(); return StringUtils.join(arguments, "<br/>"); } catch (Exception ex) { return PageAbout.this.getString("PageAbout.message.couldntObtainJvmParams"); } } }); jvmProperties.setEscapeModelStrings(false); add(jvmProperties); initButtons(); }