List of usage examples for java.lang.management ManagementFactory RUNTIME_MXBEAN_NAME
String RUNTIME_MXBEAN_NAME
To view the source code for java.lang.management ManagementFactory RUNTIME_MXBEAN_NAME.
Click Source Link
From source file:de.unisb.cs.st.javalanche.mutation.runtime.jmx.MutationMxClient.java
public static boolean connect(int i) { JMXConnector jmxc = null;//w ww . j av a 2s . c om JMXServiceURL url = null; try { url = new JMXServiceURL(MXBeanRegisterer.ADDRESS + i); jmxc = JMXConnectorFactory.connect(url, null); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { return false; // System.out.println("Could not connect to address: " + url); // e.printStackTrace(); } if (jmxc != null) { try { MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName objectName = new ObjectName(MXBeanRegisterer.OBJECT_NAME); Object numberOfMutations = mbsc.getAttribute(objectName, "NumberOfMutations"); Object currentTest = mbsc.getAttribute(objectName, "CurrentTest"); Object currentMutation = mbsc.getAttribute(objectName, "CurrentMutation"); Object allMutations = mbsc.getAttribute(objectName, "Mutations"); Object mutationsDuration = mbsc.getAttribute(objectName, "MutationDuration"); Object testDuration = mbsc.getAttribute(objectName, "TestDuration"); // Object mutationSummary = mbsc.getAttribute(objectName, // "MutationSummary"); final RuntimeMXBean remoteRuntime = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); final MemoryMXBean remoteMemory = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class); System.out.print("Connection: " + i + " "); System.out.println("Target VM: " + remoteRuntime.getName() + " - " + remoteRuntime.getVmVendor() + " - " + remoteRuntime.getSpecVersion() + " - " + remoteRuntime.getVmVersion()); System.out.println( "Running for: " + DurationFormatUtils.formatDurationHMS(remoteRuntime.getUptime())); System.out .println("Memory usage: Heap - " + formatMemory(remoteMemory.getHeapMemoryUsage().getUsed()) + " Non Heap - " + formatMemory(remoteMemory.getNonHeapMemoryUsage().getUsed())); String mutationDurationFormatted = DurationFormatUtils .formatDurationHMS(Long.parseLong(mutationsDuration.toString())); String testDurationFormatted = DurationFormatUtils .formatDurationHMS(Long.parseLong(testDuration.toString())); if (DEBUG_ADD) { System.out.println("Classpath: " + remoteRuntime.getClassPath()); System.out.println("Args: " + remoteRuntime.getInputArguments()); System.out.println("All Mutations: " + allMutations); } // System.out.println(mutationSummary); System.out.println( "Current mutation (Running for: " + mutationDurationFormatted + "): " + currentMutation); System.out.println("Mutations tested: " + numberOfMutations); System.out.println("Current test: (Running for: " + testDurationFormatted + "): " + currentTest); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (MalformedObjectNameException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } catch (AttributeNotFoundException e) { e.printStackTrace(); } catch (InstanceNotFoundException e) { e.printStackTrace(); } catch (MBeanException e) { e.printStackTrace(); } catch (ReflectionException e) { e.printStackTrace(); } finally { try { jmxc.close(); } catch (IOException e) { e.printStackTrace(); } } } return true; }
From source file:org.apache.cassandra.tools.NodeProbe.java
/** * Create a connection to the JMX agent and setup the M[X]Bean proxies. * * @throws IOException on connection failures *//*from ww w . j a v a 2 s . c om*/ private void connect() throws IOException { JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port)); Map<String, Object> env = new HashMap<String, Object>(); if (username != null) { String[] creds = { username, password }; env.put(JMXConnector.CREDENTIALS, creds); } env.put("com.sun.jndi.rmi.factory.socket", getRMIClientSocketFactory()); jmxc = JMXConnectorFactory.connect(jmxUrl, env); mbeanServerConn = jmxc.getMBeanServerConnection(); try { ObjectName name = new ObjectName(ssObjName); ssProxy = JMX.newMBeanProxy(mbeanServerConn, name, StorageServiceMBean.class); name = new ObjectName(MessagingService.MBEAN_NAME); msProxy = JMX.newMBeanProxy(mbeanServerConn, name, MessagingServiceMBean.class); name = new ObjectName(StreamManagerMBean.OBJECT_NAME); streamProxy = JMX.newMBeanProxy(mbeanServerConn, name, StreamManagerMBean.class); name = new ObjectName(CompactionManager.MBEAN_OBJECT_NAME); compactionProxy = JMX.newMBeanProxy(mbeanServerConn, name, CompactionManagerMBean.class); name = new ObjectName(FailureDetector.MBEAN_NAME); fdProxy = JMX.newMBeanProxy(mbeanServerConn, name, FailureDetectorMBean.class); name = new ObjectName(CacheService.MBEAN_NAME); cacheService = JMX.newMBeanProxy(mbeanServerConn, name, CacheServiceMBean.class); name = new ObjectName(StorageProxy.MBEAN_NAME); spProxy = JMX.newMBeanProxy(mbeanServerConn, name, StorageProxyMBean.class); name = new ObjectName(HintedHandOffManager.MBEAN_NAME); hhProxy = JMX.newMBeanProxy(mbeanServerConn, name, HintedHandOffManagerMBean.class); name = new ObjectName(GCInspector.MBEAN_NAME); gcProxy = JMX.newMBeanProxy(mbeanServerConn, name, GCInspectorMXBean.class); } catch (MalformedObjectNameException e) { throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e); } memProxy = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConn, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class); runtimeProxy = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConn, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); }
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 ww . j a v a 2 s.c om*/ "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.rhq.plugins.jmx.EmbeddedJMXServerDiscoveryComponent.java
@Nullable private EmsBean getRuntimeMXBean(ResourceDiscoveryContext<JMXComponent<?>> context) { EmsConnection emsConnection = context.getParentResourceComponent().getEmsConnection(); if (emsConnection == null) { log.debug("Parent EMS connection is null for [" + context.getParentResourceContext().getResourceKey() + "] " + context.getParentResourceContext().getResourceType() + " JVM."); return null; }/*from ww w. ja va 2s .c o m*/ // EmsConnection caches the list MBeans it previously found // See https://bugzilla.redhat.com/show_bug.cgi?id=924903 emsConnection.refresh(); EmsBean runtimeMBean = emsConnection.getBean(ManagementFactory.RUNTIME_MXBEAN_NAME); if (runtimeMBean == null) { log.debug("MBean [" + ManagementFactory.RUNTIME_MXBEAN_NAME + "] not found for [" + context.getParentResourceContext().getResourceKey() + "] " + context.getParentResourceContext().getResourceType() + " JVM."); } return runtimeMBean; }
From source file:org.rhq.plugins.jmx.JMXDiscoveryComponent.java
private String getJavaVersion(EmsConnection connection) { String version = null;// ww w. j a v a2 s . c o m EmsBean runtimeMXBean = connection.getBean(ManagementFactory.RUNTIME_MXBEAN_NAME); if (runtimeMXBean != null) { EmsAttribute systemPropertiesAttribute = runtimeMXBean.getAttribute("systemProperties"); if (systemPropertiesAttribute != null) { Map<String, String> systemProperties = (Map<String, String>) systemPropertiesAttribute.getValue(); version = systemProperties.get("java.version"); } } return version; }
From source file:org.rhq.plugins.jmx.JMXDiscoveryComponent.java
@Override public ResourceUpgradeReport upgrade(ResourceUpgradeContext inventoriedResource) { JvmResourceKey oldKey = JvmResourceKey.valueOf(inventoriedResource.getResourceKey()); JvmResourceKey.Type oldKeyType = oldKey.getType(); if (oldKeyType == JvmResourceKey.Type.Legacy || oldKeyType == JvmResourceKey.Type.JmxRemotingPort) { if (!inventoriedResource.getSystemInformation().isNative()) { log.warn("Cannot attempt to upgrade Resource key [" + inventoriedResource.getResourceKey() + "] of JVM Resource, because this Agent is not running with native system info support (i.e. SIGAR)."); return null; }/*from w ww. j av a 2 s.c o m*/ Configuration pluginConfig = inventoriedResource.getPluginConfiguration(); String connectorAddress = pluginConfig.getSimpleValue(CONNECTOR_ADDRESS_CONFIG_PROPERTY, null); JMXServiceURL jmxServiceURL; try { jmxServiceURL = new JMXServiceURL(connectorAddress); } catch (MalformedURLException e) { throw new RuntimeException("Failed to parse connector address: " + connectorAddress, e); } Long pid; try { JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceURL); MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection(); RuntimeMXBean runtimeMXBean = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConnection, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); pid = getJvmPid(runtimeMXBean); if (pid == null) { throw new RuntimeException("Failed to determine JVM pid by parsing JVM name."); } } catch (Exception e) { throw new RuntimeException("Failed to determine JVM pid.", e); } List<ProcessInfo> processes = inventoriedResource.getSystemInformation() .getProcesses("process|pid|match=" + pid); if (processes.size() != 1) { throw new IllegalStateException("Failed to find process with PID [" + pid + "]."); } ProcessInfo process = processes.get(0); String mainClassName = getJavaMainClassName(process); String explicitKeyValue = getSystemPropertyValue(process, SYSPROP_RHQ_RESOURCE_KEY); if (oldKeyType == JvmResourceKey.Type.Legacy || explicitKeyValue != null) { // We need to upgrade the key. JvmResourceKey newKey; if (explicitKeyValue != null) { newKey = JvmResourceKey.fromExplicitValue(mainClassName, explicitKeyValue); } else { newKey = JvmResourceKey.fromJmxRemotingPort(mainClassName, oldKey.getJmxRemotingPort()); } ResourceUpgradeReport resourceUpgradeReport = new ResourceUpgradeReport(); resourceUpgradeReport.setNewResourceKey(newKey.toString()); return resourceUpgradeReport; } } return null; }
From source file:org.rhq.plugins.jmx.JMXDiscoveryComponent.java
protected DiscoveredResourceDetails buildResourceDetails(ResourceDiscoveryContext context, ProcessInfo process, JMXServiceURL jmxServiceURL, Integer jmxRemotingPort) { JvmResourceKey key;// w ww . jav a2s.c om String mainClassName = getJavaMainClassName(process); String keyString = getSystemPropertyValue(process, SYSPROP_RHQ_RESOURCE_KEY); if (keyString != null && !keyString.equals("")) { log.debug("Using explicitly specified Resource key: [" + keyString + "]..."); key = JvmResourceKey.fromExplicitValue(mainClassName, keyString); } else { if (jmxRemotingPort != null) { log.debug("Using JMX remoting port [" + jmxRemotingPort + "] as Resource key..."); key = JvmResourceKey.fromJmxRemotingPort(mainClassName, jmxRemotingPort); } else { log.debug("Process [" + process.getPid() + "] with command line [" + Arrays.asList(process.getCommandLine()) + "] cannot be discovered, because it does not specify either of the following system properties: " + "-D" + SYSPROP_JMXREMOTE_PORT + "=12345, -D" + SYSPROP_RHQ_RESOURCE_KEY + "=UNIQUE_KEY"); return null; } } String name = buildResourceName(key); String version; try { JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceURL); MBeanServerConnection mbeanServerConnection = jmxConnector.getMBeanServerConnection(); RuntimeMXBean runtimeMXBean = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConnection, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); version = runtimeMXBean.getSystemProperties().get(SYSPROP_JAVA_VERSION); if (version == null) { throw new IllegalStateException("System property [" + SYSPROP_JAVA_VERSION + "] is not defined."); } } catch (Exception e) { log.error("Failed to determine JVM version for process [" + process.getPid() + "] with command line [" + Arrays.asList(process.getCommandLine()) + "].", e); version = null; } String description = "JVM, monitored via " + ((jmxRemotingPort != null) ? "JMX Remoting" : "Sun JVM Attach API"); Configuration pluginConfig = context.getDefaultPluginConfiguration(); pluginConfig.put(new PropertySimple(CONNECTION_TYPE, J2SE5ConnectionTypeDescriptor.class.getName())); if (jmxRemotingPort != null) { pluginConfig.put(new PropertySimple(CONNECTOR_ADDRESS_CONFIG_PROPERTY, jmxServiceURL)); } return new DiscoveredResourceDetails(context.getResourceType(), key.toString(), name, version, description, pluginConfig, process); }
From source file:org.wso2.carbon.cassandra.cluster.ClusterDataAccessMBeanImplementation.java
/** * Access the <code>RuntimeMXBean</code> * * @return <code>RuntimeMXBean</code> instance */// w ww. ja v a2 s .c om public RuntimeMXBean locateRuntimeMBean() { if (runtimeMXBean == null) { runtimeMXBean = locateManagementFactoryMBean(ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); } return runtimeMXBean; }