List of usage examples for java.lang.management ManagementFactory getRuntimeMXBean
public static RuntimeMXBean getRuntimeMXBean()
From source file:org.springframework.boot.devtools.restart.ChangeableUrls.java
private static URL[] urlsFromClassLoader(ClassLoader classLoader) { if (classLoader instanceof URLClassLoader) { return ((URLClassLoader) classLoader).getURLs(); }//from w w w . ja va 2s .com return Stream.of(ManagementFactory.getRuntimeMXBean().getClassPath().split(File.pathSeparator)) .map(ChangeableUrls::toURL).toArray(URL[]::new); }
From source file:io.gravitee.common.node.AbstractNode.java
@Override protected void doStart() throws Exception { LOGGER.info("{} is now starting...", name()); long startTime = System.currentTimeMillis(); // Get the start Time List<Class<? extends LifecycleComponent>> components = getLifecycleComponents(); for (Class<? extends LifecycleComponent> componentClass : components) { LOGGER.info("\tStarting component: {}", componentClass.getSimpleName()); try {/*from w w w. j ava 2s .co m*/ LifecycleComponent lifecyclecomponent = applicationContext.getBean(componentClass); lifecyclecomponent.start(); } catch (Exception e) { LOGGER.error("An error occurs while starting component {}", componentClass.getSimpleName(), e); throw e; } } long endTime = System.currentTimeMillis(); // Get the end Time String processId = ManagementFactory.getRuntimeMXBean().getName(); if (processId.contains("@")) { processId = processId.split("@")[0]; } LOGGER.info("{} id[{}] version[{}] pid[{}] build[{}#{}] jvm[{}/{}/{}] started in {} ms.", name(), id(), Version.RUNTIME_VERSION.MAJOR_VERSION, processId, Version.RUNTIME_VERSION.BUILD_NUMBER, Version.RUNTIME_VERSION.REVISION, ManagementFactory.getRuntimeMXBean().getVmVendor(), ManagementFactory.getRuntimeMXBean().getVmName(), ManagementFactory.getRuntimeMXBean().getVmVersion(), (endTime - startTime)); }
From source file:com.smartmarmot.orabbix.Orabbixmon.java
@Override public void run() { try {//from w ww . j a va 2s . c o m Configurator cfg = null; try { cfg = new Configurator(configFile); } catch (Exception e) { SmartLogger.logThis(Level.ERROR, "Error while creating configurator with " + configFile + " " + e); } RuntimeMXBean rmxb = ManagementFactory.getRuntimeMXBean(); String pid = rmxb.getName(); SmartLogger.logThis(Level.INFO, Constants.PROJECT_NAME + " started with pid:" + pid.split("@")[0].toString()); // System.out.print("pid: "+pid.split("@")[0].toString()); String pidfile = cfg.getPidFile(); try { Utility.writePid(pid.split("@")[0].toString(), pidfile); } catch (Exception e) { SmartLogger.logThis(Level.ERROR, "Error while trying to write pidfile " + e); } Locale.setDefault(Locale.US); DBConn[] myDBConn = cfg.getConnections(); if (myDBConn == null) { SmartLogger.logThis(Level.ERROR, "ERROR on main - Connections is null"); throw new Exception("ERROR on main - Connections is null"); } else if (myDBConn.length == 0) { SmartLogger.logThis(Level.ERROR, "ERROR on main - Connections is empty"); throw new Exception("ERROR on main - Connections is empty"); } /** * retrieve maxThread */ Integer maxThread = 0; try { maxThread = cfg.getMaxThread(); } catch (Exception e) { SmartLogger.logThis(Level.WARN, "MaxThread not defined calculated maxThread = " + myDBConn.length * 3); } if (maxThread == null) maxThread = 0; if (maxThread == 0) { maxThread = myDBConn.length * 3; } ExecutorService executor = Executors.newFixedThreadPool(maxThread.intValue()); /** * populate qbox */ Hashtable<String, Querybox> qbox = new Hashtable<String, Querybox>(); for (int i = 0; i < myDBConn.length; i++) { Querybox qboxtmp = Configurator.buildQueryBoxbyDBName(myDBConn[i].getName()); qbox.put(myDBConn[i].getName(), qboxtmp); } // for (int i = 0; i < myDBConn.length; i++) { cfg = null; /** * daemon begin here */ while (running) { /** * istantiate a new configurator */ Configurator c = new Configurator(configFile); /* * here i rebuild DB's List */ if (!c.isEqualsDBList(myDBConn)) { // rebuild connections DBConn[] myDBConn = c.rebuildDBList(myDBConn); for (int i = 1; i < myDBConn.length; i++) { if (!qbox.containsKey(myDBConn[i].getName())) { Querybox qboxtmp = Configurator.buildQueryBoxbyDBName(myDBConn[i].getName()); qbox.put(myDBConn[i].getName(), qboxtmp); } } } // if (!c.isEqualsDBList(myDBConn)) { /* * ready to run query */ for (int i = 0; i < myDBConn.length; i++) { Querybox actqb = qbox.get(myDBConn[i].getName()); actqb.refresh(); Query[] q = actqb.getQueries(); SharedPoolDataSource spds = myDBConn[i].getSPDS(); Hashtable<String, Integer> zabbixServers = c.getZabbixServers(); SmartLogger.logThis(Level.DEBUG, "Ready to run DBJob for dbname ->" + myDBConn[i].getName()); Runnable runner = new DBJob(spds, q, Constants.QUERY_LIST, zabbixServers, myDBConn[i].getName()); executor.execute(runner); } // for (int i = 0; i < myDBConn.length; i++) { Thread.sleep(60 * 1000); SmartLogger.logThis(Level.DEBUG, "Waking up Goood Morning"); } } catch (Exception e1) { // TODO Auto-generated catch block System.out.println("Stopping"); e1.printStackTrace(); stopped = true; } }
From source file:com.handu.open.dubbo.monitor.controller.SystemController.java
@RequestMapping(method = RequestMethod.GET) public String system(Model model) { List<String[]> rows = new ArrayList<String[]>(); rows.add(new String[] { "Version", "2.8.4" }); String address = NetUtils.getLocalHost(); rows.add(new String[] { "Host", NetUtils.getHostName(address) + "/" + address }); rows.add(new String[] { "OS", System.getProperty("os.name") + " " + System.getProperty("os.version") }); rows.add(new String[] { "JVM", System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version") + ",<br/>" + System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version") + " " + System.getProperty("java.vm.info", "") }); rows.add(new String[] { "CPU", System.getProperty("os.arch", "") + ", " + String.valueOf(Runtime.getRuntime().availableProcessors()) + " cores" }); rows.add(new String[] { "Locale", Locale.getDefault().toString() + "/" + System.getProperty("file.encoding") }); rows.add(new String[] { "Uptime", formatUptime(ManagementFactory.getRuntimeMXBean().getUptime()) }); rows.add(new String[] { "Time", formatter.format(new Date()) }); model.addAttribute("rows", rows); return "system"; }
From source file:org.apache.pulsar.common.stats.JvmMetrics.java
private static String detectGCType() { RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); Set<String> arguments = Sets.newHashSet(runtimeMxBean.getInputArguments()); for (Entry<String, Class<? extends JvmGCMetricsLogger>> gc : gcLoggerMap.entrySet()) { if (arguments.contains(gc.getKey())) { return gc.getValue().getName(); }/*from w w w .j a va 2 s . c o m*/ } return null; }
From source file:com.snowstore.mercury.core.metric.SystemPublicMetrics.java
/** * Add metrics from ManagementFactory if possible. Note that * ManagementFactory is not available on Google App Engine. *//*from w w w .jav a 2s. c o m*/ private void addManagementMetrics(Collection<Metric<?>> result) { try { // Add JVM up time in ms result.add(new Metric<Long>("uptime", ManagementFactory.getRuntimeMXBean().getUptime())); result.add(new Metric<Double>("systemload.average", ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage())); addHeapMetrics(result); addNoHeapMetrics(result); addThreadMetrics(result); addClassLoadingMetrics(result); addGarbageCollectionMetrics(result); } catch (NoClassDefFoundError ex) { // Expected on Google App Engine } }
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. j av a 2 s . c om*/ * @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.dita.dost.util.DitaUtil.java
public static ILaunch publish(IFile ditaMapFile, String antTargets, String ditavalFileName) throws IOException, CoreException, URISyntaxException { IProject ditaProject = ditaMapFile.getProject(); IFolder ditaFolder = ditaProject.getFolder(new Path("dita")); IFile ditaValFile = ditaFolder.getFile(ditavalFileName); StringBuffer jvmArguments = new StringBuffer(); for (String arg : ManagementFactory.getRuntimeMXBean().getInputArguments()) { if (arg.startsWith("-X")) { jvmArguments.append(arg);/* ww w .j ava2 s.c o m*/ jvmArguments.append(" "); } } jvmArguments.append("-Dfile.encoding=UTF-8 "); String[] segments = ditaMapFile.getName().split("\\."); String ditaMapFileRoot = segments[0]; Bundle bundle = Platform.getBundle("org.dita.dost"); Path path = new Path("META-INF/MANIFEST.MF"); URL fileURL = FileLocator.find(bundle, path, null); Path ditadirPath = new Path("DITA-OT"); URL ditadirURL = FileLocator.find(bundle, ditadirPath, null); ditadirURL = FileLocator.toFileURL(ditadirURL); InputStream in = fileURL.openStream(); Manifest ditaPluginManifest = new Manifest(in); Attributes attributes = ditaPluginManifest.getMainAttributes(); String ditaClassPath = attributes.getValue("Bundle-ClassPath"); List<String> classpath = new ArrayList<String>(); String ditaRequiredBundles = attributes.getValue("Require-Bundle"); for (String requiredBundleSymbolicName : ditaRequiredBundles.split(",")) { // get before ; Bundle requiredBundle = Platform.getBundle(requiredBundleSymbolicName.split(";")[0]); // Assume the bundle is optional if null if (requiredBundle != null) { File file = FileLocator.getBundleFile(requiredBundle); IRuntimeClasspathEntry requiredBundleEntry = JavaRuntime .newArchiveRuntimeClasspathEntry(new Path(file.getPath())); requiredBundleEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); classpath.add(requiredBundleEntry.getMemento()); } } for (String classPath : ditaClassPath.split(",")) { if (".".equals(classPath)) { URL url = FileLocator.find(bundle, new Path(""), null); url = FileLocator.toFileURL(url); IRuntimeClasspathEntry pluginEntry = JavaRuntime.newRuntimeContainerClasspathEntry( new Path(url.getPath()), IRuntimeClasspathEntry.USER_CLASSES); classpath.add(pluginEntry.getMemento()); } else { URL url = FileLocator.find(bundle, new Path(classPath), null); url = FileLocator.toFileURL(url); IRuntimeClasspathEntry toolsEntry = JavaRuntime .newArchiveRuntimeClasspathEntry(new Path(url.getPath())); toolsEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); classpath.add(toolsEntry.getMemento()); } } ContributedClasspathEntriesEntry ccee = new ContributedClasspathEntriesEntry(); AntHomeClasspathEntry ace = new AntHomeClasspathEntry(); classpath.add(ace.getMemento()); classpath.add(ccee.getMemento()); ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); ILaunchConfigurationType type = launchManager .getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE); URL ditaPublishBuildFileURL = fileURL = FileLocator.find(bundle, new Path("dita-publish.xml"), null); ditaPublishBuildFileURL = FileLocator.toFileURL(ditaPublishBuildFileURL); String name = launchManager.generateLaunchConfigurationName("Publish DITA"); ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, name); workingCopy.setAttribute("org.eclipse.ui.externaltools.ATTR_LOCATION", ditaPublishBuildFileURL.getPath()); IVMInstall jre = JavaRuntime.getDefaultVMInstall(); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, jre.getName()); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "-Djavax.xml.transform.TransformerFactory=net.sf.saxon.TransformerFactoryImpl"); Map<String, String> antProperties = new HashMap<String, String>(); antProperties.put("dita.dir", ditadirURL.getPath()); antProperties.put("ditaMapFile", ditaMapFile.getLocation().toOSString()); if (ditaValFile != null) { antProperties.put("args.filter", ditaValFile.getLocation().toOSString()); } antProperties.put("ditaMapFileName", ditaMapFile.getName().substring(0, ditaMapFile.getName().length() - ditaMapFile.getFileExtension().length())); // antProperties.put("outputLocation", ditaProject.getLocation().toOSString()); antProperties.put("dita.output", ditaProject.getLocation().append(antTargets).toOSString()); antProperties.put("ditaMapFileRoot", ditaMapFileRoot); String fileName = getFileNameFromMap(ditaMapFile.getLocation().toOSString()); if (StringUtils.isEmpty(fileName)) { fileName = ditaMapFile.getName().replace("." + ditaMapFile.getFileExtension(), ""); } antProperties.put("fileName", fileName); antProperties.put("args.debug", "no"); antProperties.put("ditaFilePath", ditaFolder.getLocation().toOSString()); antProperties.put("tempFilePath", org.dita.dost.internal.Activator.getDefault().getStateLocation().append("temp").toOSString()); antProperties.put("docProject", ditaProject.getLocation().toOSString()); String pdfFileLocation = ditaMapFile.getName(); pdfFileLocation = pdfFileLocation.replaceFirst(".ditamap", ".pdf"); antProperties.put("pdflocation", pdfFileLocation); workingCopy.setAttribute("process_factory_id", "org.eclipse.ant.ui.remoteAntProcessFactory"); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.eclipse.ant.internal.ui.antsupport.InternalAntRunner"); workingCopy.setAttribute( org.eclipse.core.externaltools.internal.IExternalToolConstants.ATTR_WORKING_DIRECTORY, ditaProject.getLocation().toOSString()); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, jvmArguments.toString()); workingCopy.setAttribute(org.eclipse.ant.launching.IAntLaunchConstants.ATTR_ANT_TARGETS, antTargets); workingCopy.setAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTIES, antProperties); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false); workingCopy.setAttribute(IDebugUIConstants.ATTR_CONSOLE_PROCESS, false); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, "org.eclipse.ant.ui.AntClasspathProvider"); workingCopy.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true); workingCopy.setAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, "UTF-8"); workingCopy.migrate(); return workingCopy.launch(ILaunchManager.RUN_MODE, null, false, true); }
From source file:org.kantega.notsoserial.WithDryRunWhitelistAndTraceIT.java
private void attachAgent() throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { String name = ManagementFactory.getRuntimeMXBean().getName(); String pid = name.substring(0, name.indexOf("@")); System.out.println(name);//w ww . jav a 2s. co m final VirtualMachine m = VirtualMachine.attach(pid); m.loadAgent("target/notsoserial-1.0-SNAPSHOT.jar"); }
From source file:org.springframework.boot.StartupInfoLogger.java
private StringBuilder getStartedMessage(StopWatch stopWatch) { StringBuilder message = new StringBuilder(); message.append("Started "); message.append(getApplicationName()); message.append(" in "); message.append(stopWatch.getTotalTimeSeconds()); try {// w w w. j a v a 2 s . c om double uptime = ManagementFactory.getRuntimeMXBean().getUptime() / 1000.0; message.append(" seconds (JVM running for " + uptime + ")"); } catch (Throwable ex) { // No JVM time available } return message; }