JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:9999/jmxrmi"); JMXConnector jmxc = JMXConnectorFactory.connect(url, null); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName mbeanName = new ObjectName("com.example:type=ThreadMonitor"); ThreadMonitorMBean mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName, ThreadMonitorMBean.class, true); jmxc.close(); System.out.println("Done.");
private static void printMetrics(final int port) throws IOException { final JMXServiceURL jmxUrl = new JMXServiceURL( String.format("service:jmx:rmi:///jndi/rmi://localhost:%d/jmxrmi", port)); final JMXConnector connector = JMXConnectorFactory.connect(jmxUrl); connector.connect(); final MBeanServerConnection connection = connector.getMBeanServerConnection(); final Set<ObjectName> names = connection.queryNames(null, null); final List<ObjectName> ksqlObjects = new LinkedList<>(); for (final ObjectName n : names) { if (n.toString().startsWith("io.confluent.ksql.metrics:type=ksql-engine")) { ksqlObjects.add(n); final MBeanInfo info; try { info = connection.getMBeanInfo(n); } catch (final Exception error) { throw new PrintMetricsException( final Object attribute; try { attribute = connection.getAttribute(n, attributeInfo.getName()); } catch (final Exception error) { throw new PrintMetricsException(
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(); }
public void execute(final String hostportOrPid, final String login, final String password, final String beanname, int interval) throws Exception { JMXConnector jmxc = Client.connect(hostportOrPid, login, password); try { MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); gcUtilCommand(mbsc, interval); } finally { jmxc.close(); } }
public void connect(String serviceUrl) throws Exception { JMXServiceURL url = new JMXServiceURL(serviceUrl); connector = JMXConnectorFactory.connect(url, null); connection = connector.getMBeanServerConnection(); // create a mbean proxy so we can use the type safe api ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=context,name=\"camel-1\""); proxy = JMX.newMBeanProxy(connection, on, ManagedCamelContextMBean.class); }
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://my.tomcat.host:8080/jmxrmi"); JMXConnector jmxc = JMXConnectorFactory.connect(url, null); MBeanServerConnection conn = jmxc.getMBeanServerConnection(); ObjectName name = new ObjectName("oracle.jrockit.management:type=Runtime"); Double jvmCpuLoad =(Double)conn.getAttribute(name, "VMGeneratedCPULoad");
this.jmxUrl = new JMXServiceURL(lvm.connectorAddress()); jmxc.connect(); } else { this.jmxc = JMXConnectorFactory.connect(jmxUrl); jmxc.connect(env); } else { this.jmxc = JMXConnectorFactory.connect(jmxUrl, env); this.mbsc = jmxc.getMBeanServerConnection(); this.server = Snapshot.newSnapshot(mbsc); ObjectName on = new ObjectName(THREAD_MXBEAN_NAME); this.hasPlatformMXBeans = server.isRegistered(on); this.hasHotSpotDiagnosticMXBean = server.isRegistered(new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME)); on = new ObjectName(COMPILATION_MXBEAN_NAME); this.hasCompilationMXBean = server.isRegistered(on);
try { connector = JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(connectorPort, connectorPort)); mb = connector.getMBeanServerConnection(); pairs.put("name", "Master"); pairs.put("sub", "Balancer"); target = new ObjectName("Hadoop", pairs); MBeanInfo beanInfo = mb.getMBeanInfo(target); LOG.warn("Failed to get bean!!! " + target, e); if (mb != null) { Set<ObjectInstance> instances = mb.queryMBeans(null, null); Iterator<ObjectInstance> iterator = instances.iterator(); System.out.println("MBean Found:"); if (connector != null) { try { connector.close(); } catch (Exception e) { e.printStackTrace();
/** * Construct a holder for Participant and Recovery Store proxies. There is one instance for each connection * to a JVM. In practice there will only ever be one instance. * * @param serviceUrl the url for the MBean server to connect to. Use default to connect to the local MBean Server * @param listener optionally register a listener for notifications * @throws JMException if there are JMX errors during registration of MBeans and notification listeners * @throws IOException if there are errors on the connection to the MBean Server */ private StoreManagerProxy(String serviceUrl, NotificationListener listener) throws JMException, IOException { if ("default".equals(serviceUrl)) { mbsc = JMXServer.getAgent().getServer(); } else { // create an RMI connector JMXServiceURL url = new JMXServiceURL(serviceUrl); // connect to the target MBean server jmxc = JMXConnectorFactory.connect(url, null); mbsc = jmxc.getMBeanServerConnection(); } recoveryStoreON = ObjectName.getInstance(RECOVERY_BEAN_NAME); participantStoreON = ObjectName.getInstance(PARTICIPANT_BEAN_NAME); rsProxy = new RecoveryStoreProxy(JMX.newMBeanProxy( mbsc, recoveryStoreON, RecoveryStoreBeanMBean.class, true)); psProxy = new ParticipantStoreProxy(JMX.newMBeanProxy( mbsc, participantStoreON, ParticipantStoreBeanMBean.class, true)); if (listener != null) { mbsc.addNotificationListener(recoveryStoreON, listener, null, null); mbsc.addNotificationListener(participantStoreON, listener, null, null); } }
JMXServiceURL target = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+args[0]+":"+args[1]+"/jmxrmi"); JMXConnector connector = JMXConnectorFactory.connect(target); MBeanServerConnection remote = connector.getMBeanServerConnection(); ObjectName bean = new ObjectName("com.digitalscripter.search.statistics:name=requestStatistics,type=RequestStatistics"); MBeanInfo info = remote.getMBeanInfo(bean); MBeanAttributeInfo[] attributes = info.getAttributes(); for (MBeanAttributeInfo attr : attributes) System.out.println(attr.getDescription() + " " + remote.getAttribute(bean,attr.getName())); connector.close();
public MBeanInvocationHandler(String jmxServiceUrl, String jmxObjectName) throws IOException, MalformedObjectNameException { final JMXServiceURL url = new JMXServiceURL(jmxServiceUrl); final JMXConnector jmxc = JMXConnectorFactory.connect(url, null); this.mbsc = jmxc.getMBeanServerConnection(); this.mbeanObjectName = ObjectName.getInstance(jmxObjectName); }
this.url = new JMXServiceURL(MessageFormat.format(JMX_URL_FORMAT, checkAndConvertToCompatibleIPv6Syntax(host), String.valueOf(port))); this.connector = JMXConnectorFactory.connect(url, env); this.mbsc = connector.getMBeanServerConnection(); this.connector.addConnectionNotificationListener(new JMXConnectionListener(this), null, null); this.distributedSystemMXBeanProxy = JMX.newMXBeanProxy(mbsc, MBeanJMXAdapter.getDistributedSystemName(), DistributedSystemMXBean.class); } else { this.managerMemberObjectName = this.distributedSystemMXBeanProxy.getMemberObjectName(); if (this.managerMemberObjectName == null || !JMX.isMXBeanInterface(MemberMXBean.class)) { logger.info("MemberMXBean with ObjectName " + this.managerMemberObjectName + " is not present on member with endpoints : " + endpoints); } else { this.memberMXBeanProxy = JMX.newMXBeanProxy(mbsc, managerMemberObjectName, MemberMXBean.class); this.fileUploadMBeanProxy = JMX.newMBeanProxy(mbsc, new ObjectName(ManagementConstants.OBJECTNAME__FILEUPLOADER_MBEAN), FileUploaderMBean.class);
/** * 初始化jmx连接 * * @throws IOException */ private void initJmxConn() throws IOException { if (jmxUrl != null) { JMXServiceURL url = new JMXServiceURL(jmxUrl); Map<String, String[]> env = null; if (jmxUsername != null) { env = new HashMap<String, String[]>(); String[] credentials = new String[] { jmxUsername, jmxPassword }; env.put(JMXConnector.CREDENTIALS, credentials); } JMXConnector jmxc = JMXConnectorFactory.connect(url, env); conn = jmxc.getMBeanServerConnection(); } }
ObjectName queryName = new ObjectName(query); info("Attempt to find GridKernal MBean [num=" + i + ']'); Set<ObjectName> names = jmx.getMBeanServerConnection().queryNames(queryName, null); info("Found MBean for node: " + objectName); String kernalName = objectName.getKeyProperty("name"); UUID nodeId = (UUID)jmx.getMBeanServerConnection().getAttribute(kernal, "LocalNodeId"); if (jmx != null) { try { jmx.close();
mbsc = ManagementFactory.getPlatformMBeanServer(); } else { JMXServiceURL url = new JMXServiceURL(url_string); JMXConnector jmxc = JMXConnectorFactory.connect(url, null); mbsc = jmxc.getMBeanServerConnection(); String domains[] = mbsc.getDomains(); Arrays.sort(domains); for (String domain : domains) { err("\nMBeanServer default domain = " + mbsc.getDefaultDomain()); err("\nMBean count = " + mbsc.getMBeanCount()); ObjectName query = new ObjectName("Hadoop:service=" + service + ",*"); hadoopObjectNames = new ArrayList<ObjectName>(5); err("\nQuery MBeanServer MBeans:");
/** * Initialize the JMX client to listen to notification sent by CB4J monitor. * @param notificationListener the listener for report updates * @param connectionClosedNotificationListener the listener for JMX connection-closed event * @throws Exception thrown if an exception occurs during client initialization */ public void init(NotificationListener notificationListener, NotificationListener connectionClosedNotificationListener) throws Exception { JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"); JMXConnector jmxc = JMXConnectorFactory.connect(url, null); MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); ObjectName mbeanName = new ObjectName("io.github.benas.cb4j.jmx:type=BatchMonitorMBean"); mbsc.addNotificationListener(mbeanName, notificationListener, null, null); if (connectionClosedNotificationListener != null) { jmxc.addConnectionNotificationListener(connectionClosedNotificationListener, new ConnectionClosedNotificationFilter(), null); } }
String host ="myHost"; int port = 1234; HashMap map = new HashMap(); String[] credentials = new String[2]; credentials[0] = user; credentials[1] = password; map.put("jmx.remote.credentials", credentials); JMXConnector c = JMXConnectorFactory.newJMXConnector(createConnectionURL(host, port), map); c.connect(); Object o = c.getMBeanServerConnection().getAttribute(new ObjectName("java.lang:type=Memory"), "HeapMemoryUsage"); CompositeData cd = (CompositeData) o; System.out.println(cd.get("committed")); private static JMXServiceURL createConnectionURL(String host, int port) throws MalformedURLException { return new JMXServiceURL("rmi", "", 0, "/jndi/rmi://" + host + ":" + port + "/jmxrmi"); }
private static void fetchKafkaMetrics(String host, String jmxPort, String metric) throws Exception { Map<String, String[]> env = new HashMap<>(); JMXServiceURL address = new JMXServiceURL( "service:jmx:rmi://" + host + "/jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi"); JMXConnector connector = JMXConnectorFactory.connect(address, env); MBeanServerConnection mbs = connector.getMBeanServerConnection(); ObjectName name = ObjectName.getInstance(metric); MBeanInfo beanInfo = mbs.getMBeanInfo(name); for (MBeanAttributeInfo attributeInfo : beanInfo.getAttributes()) { Object obj = mbs.getAttribute(name, attributeInfo.getName()); System.out.println(" attributeName = " + attributeInfo.getName() + " " + obj.toString()); } }
env.put("jmx.remote.protocol.provider.class.loader", this.getClass().getClassLoader()); env.put("jmx.remote.protocol.provider.pkgs", NodesTree.getProtocolPackageProvider(this.getProtocol())); // efficacite partielle... Le reste etant assure par du codage en dur dans les classes du protocol murmi this.jmxc = JMXConnectorFactory.newJMXConnector(this, env); this.jmxc.connect(env); this.mbsc = jmxc.getMBeanServerConnection(); if ( this.mbsc.isRegistered(new ObjectName("OSGI:name=Remote Logger")) ) { jmxc.addConnectionNotificationListener(notificationListener, null, this);
jmxc = JMXConnectorFactory.connect(new JMXServiceURL(jmxUrl), environment); beanConn = jmxc.getMBeanServerConnection(); for (ObjectInstance instance : beanConn.queryMBeans(name, null)) { mBeanNames.add(instance.getObjectName()); for (ObjectInstance instance : beanConn.queryMBeans(name, null)) { mBeanNames.remove(instance.getObjectName()); long start = System.nanoTime(); scrapeBean(beanConn, objectName); logger.fine("TIME: " + (System.nanoTime() - start) + " ns for " + objectName.toString()); jmxc.close();