List of usage examples for java.lang.management RuntimeMXBean getInputArguments
public java.util.List<String> getInputArguments();
From source file:org.geowebcache.util.HttpClientBuilder.java
/** * Instantiates a new http client builder * @param url The server url, or null if no authentication is required or if the client is going to be * used against a single server only * @param backendTimeout//ww w . ja va 2 s. c o m * @param httpUsername * @param httpPassword * @param proxyUrl * @param concurrency */ public HttpClientBuilder(URL url, Integer backendTimeout, String httpUsername, String httpPassword, URL proxyUrl, int concurrency) { if (url != null) { this.setHttpCredentials(httpUsername, httpPassword, new AuthScope(url.getHost(), url.getPort())); } else { this.setHttpCredentials(httpUsername, httpPassword, AuthScope.ANY); } RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); List<String> lst = runtimeMXBean.getInputArguments(); String proxyHost = null; String proxyPort = null; for (String arg : lst) { if (arg.startsWith("-Dhttp.proxyHost=")) { proxyHost = extractVMArg(arg); } else if (arg.startsWith("-Dhttp.proxyPort=")) { proxyPort = extractVMArg(arg); } } if (proxyHost != null) try { proxyUrl = new URL(proxyHost + ((proxyPort != null) ? (":" + proxyPort) : (""))); } catch (MalformedURLException e) { e.printStackTrace(); } this.setProxy(proxyUrl); this.setBackendTimeout(backendTimeout); this.concurrency = concurrency; }
From source file:org.icgc.dcc.generator.Main.java
private String formatArguments(String[] args) { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); List<String> inputArguments = runtime.getInputArguments(); return "java " + join(inputArguments, ' ') + " -jar " + getJarName() + " " + join(args, ' '); }
From source file:org.jbosson.plugins.amq.ArtemisServerDiscoveryComponent.java
protected ProcessInfo getJvmProcess(ResourceDiscoveryContext discoveryContext, EmsConnection connection, String connectorAddress) { // check whether native system is supported if (!discoveryContext.getSystemInformation().isNative()) { log.warn(/*from w w w.j a v a2 s.com*/ "Native layer is not available or has been disabled, process properties discovery not supported"); return null; } ProcessInfo processInfo; final String resourceTypeName = discoveryContext.getResourceType().getName(); try { final EmsBean runtimeEmsBean = connection.getBean(ManagementFactory.RUNTIME_MXBEAN_NAME); final RuntimeMXBean runtimeMXBean = runtimeEmsBean.getProxy(RuntimeMXBean.class); final String runtimeMXBeanName = runtimeMXBean != null ? runtimeMXBean.getName() : null; if (runtimeMXBeanName != null && runtimeMXBeanName.contains("@")) { final String pid = runtimeMXBeanName.substring(0, runtimeMXBeanName.indexOf('@')); processInfo = new ProcessInfo(Long.valueOf(pid)); // validate process info to make sure command line args are accessible // this can happen for processes running with a user id different than the agent if (processInfo.getCommandLine() == null || processInfo.getCommandLine().length == 0) { log.debug("Unable to get command line args for PID [" + pid + "] for [" + resourceTypeName + "], with connector address [" + connectorAddress + "], using java.lang.management.RuntimeMXBean to get JVM args"); final List<String> inputArguments = runtimeMXBean.getInputArguments(); final String[] args = inputArguments.toArray(new String[inputArguments.size()]); log.debug("JVM args for PID[" + pid + "] using java.lang.management.RuntimeMXBean: " + Arrays.toString(args)); processInfo = new ProcessInfoWithArgs(Long.valueOf(pid), args); } } else { throw new RuntimeException( "Unable to get Process PID using java.lang.management.RuntimeMXBean for [" + resourceTypeName + "] , with connector address [" + connectorAddress + "]"); } } catch (Exception e) { throw new RuntimeException("Error getting Process PID for resource [" + resourceTypeName + "] with JMX connector [" + connectorAddress + "]: " + e.getMessage(), e); } return processInfo; }
From source file:org.jumpmind.symmetric.util.SnapshotUtil.java
protected static void writeRuntimeStats(ISymmetricEngine engine, File tmpDir) { FileOutputStream fos = null;/*from w w w . j a v a 2 s . co m*/ try { fos = new FileOutputStream(new File(tmpDir, "runtime-stats.properties")); Properties runtimeProperties = new Properties(); runtimeProperties.setProperty("engine.is.started", Boolean.toString(engine.isStarted())); runtimeProperties.setProperty("server.time", new Date().toString()); runtimeProperties.setProperty("database.time", new Date(engine.getSymmetricDialect().getDatabaseTime()).toString()); runtimeProperties.setProperty("unrouted.data.count", Long.toString(engine.getRouterService().getUnroutedDataCount())); runtimeProperties.setProperty("outgoing.errors.count", Long.toString(engine.getOutgoingBatchService().countOutgoingBatchesInError())); runtimeProperties.setProperty("outgoing.tosend.count", Long.toString(engine.getOutgoingBatchService().countOutgoingBatchesUnsent())); runtimeProperties.setProperty("incoming.errors.count", Long.toString(engine.getIncomingBatchService().countIncomingBatchesInError())); List<DataGap> gaps = engine.getDataService().findDataGaps(); runtimeProperties.setProperty("data.gap.count", Long.toString(gaps.size())); if (gaps.size() > 0) { runtimeProperties.setProperty("data.gap.start.id", Long.toString(gaps.get(0).getStartId())); runtimeProperties.setProperty("data.gap.end.id", Long.toString(gaps.get(gaps.size() - 1).getEndId())); } RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); List<String> arguments = runtimeMxBean.getInputArguments(); runtimeProperties.setProperty("jvm.arguments", arguments.toString()); runtimeProperties.store(fos, "runtime-stats.properties"); } catch (IOException e) { log.warn("Failed to export runtime-stats information", e); } finally { IOUtils.closeQuietly(fos); } }
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 a v a2 s. c o m } 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.midonet.midolman.Midolman.java
private void initialize(String[] args) throws IOException { // log git commit info Properties properties = new Properties(); properties.load(getClass().getClassLoader().getResourceAsStream("git.properties")); log.info("MidoNet Agent main start... ---------"); log.info("branch: {}", properties.get("git.branch")); log.info("commit.time: {}", properties.get("git.commit.time")); log.info("commit.id: {}", properties.get("git.commit.id")); log.info("commit.user: {}", properties.get("git.commit.user.name")); log.info("build.time: {}", properties.get("git.build.time")); log.info("build.user: {}", properties.get("git.build.user.name")); log.info("-------------------------------------"); // log cmdline and JVM info log.info("Command-line arguments: {}", Arrays.toString(args)); RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); List<String> arguments = runtimeMxBean.getInputArguments(); log.info("JVM options: "); for (String a : arguments) { log.info(" {}", a); }/*from ww w. j a v a 2 s .c om*/ log.info("-------------------------------------"); log.info("Adding shutdown hook"); Runtime.getRuntime().addShutdownHook(new Thread("shutdown") { @Override public void run() { doServicesCleanup(); } }); }
From source file:org.noroomattheinn.utils.Utils.java
public static List<String> getJVMArgs() { RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); return runtimeMxBean.getInputArguments(); }
From source file:org.nuclos.common.startup.Startup.java
@Override public void afterPropertiesSet() throws Exception { final TimerTask task = new TimerTask() { @Override/*from w ww .jav a 2 s. c o m*/ public void run() { try { final RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean(); final List<String> arguments = RuntimemxBean.getInputArguments(); LOG.info("server started with " + arguments); final String version = IOUtils.toString(getClasspathResource("nuclos-version.properties"), ENCODING); LOG.info("version info\n:" + version); final String info = IOUtils.toString(getClasspathResource("info.txt"), ENCODING); LOG.info("SVN info\n:" + info); final String status = IOUtils.toString(getClasspathResource("status.txt"), ENCODING); LOG.info("SVN status\n:" + status); } catch (Exception e) { LOG.info("Startup timer task failed: " + e); } } }; timer.schedule(task, 500); }
From source file:org.tinymediamanager.core.Utils.java
/** * gets all the JVM parameters used for starting TMM<br> * like -Dfile.encoding=UTF8 or others<br> * needed for restarting tmm :)/* w w w. java2 s . co m*/ * * @return list of jvm parameters */ private static List<String> getJVMArguments() { RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); List<String> arguments = new ArrayList<>(runtimeMxBean.getInputArguments()); // fixtate some if (!arguments.contains("-Djava.net.preferIPv4Stack=true")) { arguments.add("-Djava.net.preferIPv4Stack=true"); } if (!arguments.contains("-Dfile.encoding=UTF-8")) { arguments.add("-Dfile.encoding=UTF-8"); } return arguments; }
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) {//from w w w . j a v a2 s . c om 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(""); }