public Iterable<ObjectName> queryNames(MBeanServerConnection mbeanServer) throws IOException { return mbeanServer.queryNames(objectName, null); }
public Set<ObjectName> queryNames(ObjectName name, QueryExp query) { try { return delegate.queryNames(name, query); } catch(IOException e) { throw new RuntimeException(e); } }
String host = "localhost"; // or some A.B.C.D int port = 1234; String url = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"; JMXServiceURL serviceUrl = new JMXServiceURL(url); JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceUrl, null); try { MBeanServerConnection mbeanConn = jmxConnector.getMBeanServerConnection(); // now query to get the beans or whatever Set<ObjectName> beanSet = mbeanConn.queryNames(null, null); ... } finally { jmxConnector.close(); }
private void initTrackers() { try { for(ObjectName name: connection.queryNames(null, null)) { if (name.getDomain().equals("java.lang") && "GarbageCollector".equals(name.getKeyProperty("type"))) { CollectorTracker tracker = new CollectorTracker(connection, name); trackers.put(tracker.name, tracker); } } } catch (Exception e) { throw new RuntimeException(e); } }
private ObjectName getObjectName() throws IOException { if (objectName.isPattern()) { Set<ObjectName> foundNames = mBeanServerConn.queryNames(objectName, null); if (foundNames.size() == 1) { return foundNames.iterator().next(); } } return objectName; } }
private Set<ObjectName> resolveSingleBean(MBeanServerConnection conn) throws Exception { ObjectName name = new ObjectName(mbean); Set<ObjectName> beans = conn.queryNames(name, null); if (beans.isEmpty()) { host.fail("MBean not found: " + mbean); } if (!all && beans.size() > 1) { StringBuilder sb = new StringBuilder(); for(ObjectName n: beans) { sb.append('\n').append(n); } host.fail("Ambiguous MBean selection. Use '-all' param for process all matched MBeans" + sb.toString()); } return beans; }
public MemoryPoolPoller(MBeanServerConnection mserver, MemoryPoolEventConsumer consumer) { this.consumer = consumer; try { ObjectName name = new ObjectName("java.lang:type=MemoryPool,name=*"); for(ObjectName on: mserver.queryNames(name, null)) { MemoryPoolMXBean mpool = JMX.newMXBeanProxy(mserver, on, MemoryPoolMXBean.class); MemPoolTracker tracker = init(mpool); trackers.put(tracker.poolName, tracker); } } catch (Exception e) { throw new RuntimeException(e); } }
public static Collection<String> allCollectedPools(MBeanServerConnection conn) throws IOException { Set<String> pools = new LinkedHashSet<String>(); for(ObjectName gcn: conn.queryNames(COLLECTORS_PATTERN, null)) { GarbageCollectorMXBean gc = JMX.newMXBeanProxy(conn, gcn, GarbageCollectorMXBean.class); for(String pool: gc.getMemoryPoolNames()) { pools.add(pool); } } return pools; }
private void initTrackers() { try { for(ObjectName name: mserver.queryNames(null, null)) { if (name.getDomain().equals("java.lang") && "GarbageCollector".equals(name.getKeyProperty("type"))) { GcTracker tracker = new GcTracker(name, name.getKeyProperty("name")); initTracker(tracker); trackers.add(tracker); tracker.capture(); } } } catch (Exception e) { throw new RuntimeException(e); } }
List<VirtualMachineDescriptor> vms = VirtualMachine.list(); for (VirtualMachineDescriptor desc : vms) { VirtualMachine vm; try { vm = VirtualMachine.attach(desc); } catch (AttachNotSupportedException e) { continue; } Properties props = vm.getAgentProperties(); String connectorAddress = props.getProperty("com.sun.management.jmxremote.localConnectorAddress"); if (connectorAddress == null) { continue; } JMXServiceURL url = new JMXServiceURL(connectorAddress); JMXConnector connector = JMXConnectorFactory.connect(url); try { MBeanServerConnection mbeanConn = connector.getMBeanServerConnection(); Set<ObjectName> beanSet = mbeanConn.queryNames(null, null); ... } finally { jmxConnector.close(); } }
public static void dump() throws IOException { LOG.info("JMXEnv.dump() follows"); Set<ObjectName> beans; try { beans = conn().queryNames( new ObjectName(CommonNames.DOMAIN + ":*"), null); } catch (MalformedObjectNameException e) { throw new RuntimeException(e); } for (ObjectName bean : beans) { LOG.info("bean:" + bean.toString()); } }
public void walkTree(MBeanServerConnection connection) throws Exception { // key here is null, null returns everything! Set<ObjectName> mbeans = connection.queryNames(null, null); for (ObjectName name : mbeans) { MBeanInfo info = connection.getMBeanInfo(name); MBeanAttributeInfo[] attrs = info.getAttributes(); String[] attrNames = new String[attrs.length]; for (int i = 0; i < attrs.length; i++) { attrNames[i] = attrs[i].getName(); } try { AttributeList attributes = connection.getAttributes(name, attrNames); for (Attribute attribute : attributes.asList()) { output(name.getCanonicalName() + "%" + attribute.getName(), attribute.getValue()); } } catch (Exception e) { log.error("error getting " + name + ":" + e.getMessage(), e); } } }
@Override public Set<ObjectName> queryNames(final ObjectName objectName, final QueryExp queryExpression) { try { return getMBeanServerConnection().queryNames(objectName, queryExpression); } catch (IOException e) { throw new JMXInvocationException(String .format("Failed to communicate with the remote MBean server at (%1$s)!", toString()), e); } }
public static Map<PoolType, Collection<String>> classifyMemoryPools(MBeanServerConnection conn) throws IOException { RuntimeMXBean rtmx = JMX.newMXBeanProxy(conn, RUNTIME_MXBEAN, RuntimeMXBean.class); boolean jrockit = rtmx.getVmName().toUpperCase().contains("JROCKIT"); Map<PoolType, Collection<String>> map = new HashMap<GcKnowledgeBase.PoolType, Collection<String>>(); for(ObjectName gcn: conn.queryNames(COLLECTORS_PATTERN, null)) { GarbageCollectorMXBean gc = JMX.newMXBeanProxy(conn, gcn, GarbageCollectorMXBean.class); String gcName = jrockit ? "JRockit" : gc.getName(); for(String pool: gc.getMemoryPoolNames()) { PoolType type = classify(gcName, pool); if (type != null) { add(map, type, pool); } } } return map; }
public static List<ObjectName> getServerBeans() throws IOException { ArrayList<ObjectName> serverBeans = new ArrayList<>(); Set<ObjectName> beans; try { beans = conn().queryNames( new ObjectName(CommonNames.DOMAIN + ":*"), null); } catch (MalformedObjectNameException e) { throw new RuntimeException(e); } for (ObjectName bean : beans) { String name = bean.toString(); LOG.info("bean:" + name); for (Pattern pattern : beanPatterns) { if (pattern.matcher(name).find()) { serverBeans.add(bean); } } } return serverBeans; }
@Override public void handle(DataInput input, int correlationId) throws IOException { log.trace("QueryNames"); byte paramType = input.readByte(); if (paramType != OBJECT_NAME) { throw new IOException("Unexpected paramType"); } ObjectName objectName; QueryExp query; try { Unmarshaller unmarshaller = prepareForUnMarshalling(input); objectName = unmarshaller.readObject(ObjectName.class); paramType = unmarshaller.readByte(); if (paramType != QUERY_EXP) { throw new IOException("Unexpected paramType"); } query = unmarshaller.readObject(QueryExp.class); } catch (ClassNotFoundException cnfe) { throw new IOException(cnfe); } Set<ObjectName> instances = server.getMBeanServerConnection().queryNames(objectName, query); writeResponse(instances, SET_OBJECT_NAME, QUERY_NAMES, correlationId); log.tracef("[%d] QueryNames - Success Response Sent", correlationId); } }
public void walkTree(MBeanServerConnection connection, Server server) throws Exception { // key here is null, null returns everything! Set<ObjectName> mbeans = connection.queryNames(null, null); for (ObjectName name : mbeans) { MBeanInfo info = connection.getMBeanInfo(name); MBeanAttributeInfo[] attrs = info.getAttributes(); Query.Builder queryBuilder = Query.builder() .setObj(name.getCanonicalName()) .addOutputWriterFactory(new StdOutWriter(ImmutableList.<String>of(), false, false, null, Collections.<String, Object>emptyMap())); for (MBeanAttributeInfo attrInfo : attrs) { queryBuilder.addAttr(attrInfo.getName()); } Query query = queryBuilder.build(); try { Iterable<Result> results = server.execute(query); query.runOutputWritersForQuery(server, results); } catch (AttributeNotFoundException anfe) { log.error("Error", anfe); } } } }
beans = conn().queryNames( new ObjectName(CommonNames.DOMAIN + ":*"), null); } catch (MalformedObjectNameException e) {
beans = conn().queryNames( new ObjectName(CommonNames.DOMAIN + ":*"), null); } catch (MalformedObjectNameException e) {
@Test public void testListDomain() throws Exception { Set<ObjectName> names = server.queryNames(ObjectName.getInstance("java.lang:type=Runtime,*"), null); System.err.println(names); assertTrue(names.size() == 1); MBeanMap result = new MBeanMap(server, names.iterator().next()); @SuppressWarnings("unchecked") Map<String,String> properties = (Map<String, String>) result.get("system_properties"); assertTrue(properties.containsKey("java.vm.version")); }