public void doScrape ( ) throws Exception { MBeanServerConnection beanConn ; JMXConnector jmxc = null ; if ( jmxUrl . isEmpty ( ) ) { beanConn = ManagementFactory . getPlatformMBeanServer ( ) ; } else { Map < String , Object > environment = new HashMap < String , Object > ( ) ; if ( username != null && username . length ( ) != 0 && password != null && password . length ( ) != 0 ) { String [ ] credent = new String [ ] { username , password } ; environment . put ( javax . management . remote . JMXConnector . CREDENTIALS , credent ) ; } if ( ssl ) { environment . put ( Context . SECURITY_PROTOCOL , "ssl" ) ; SslRMIClientSocketFactory clientSocketFactory = new SslRMIClientSocketFactory ( ) ; environment . put ( RMIConnectorServer . RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE , clientSocketFactory ) ; environment . put ( "com.sun.jndi.rmi.factory.socket" , clientSocketFactory ) ; } jmxc = JMXConnectorFactory . connect ( new JMXServiceURL ( jmxUrl ) , environment ) ; beanConn = jmxc . getMBeanServerConnection ( ) ; } try { // Query MBean names, see #89 for reasons queryMBeans() is used instead of queryNames() Set < ObjectInstance > mBeanNames = new HashSet ( ) ; for ( ObjectName name : whitelistObjectNames ) { mBeanNames . addAll ( beanConn . queryMBeans ( name , null ) ) ; } for ( ObjectName name : whitelistObjectInstances ) { mBeanNames . add ( beanConn . getObjectInstance ( name ) ) ; } for ( ObjectName name : blacklistObjectNames ) { mBeanNames . removeAll ( beanConn . queryMBeans ( name , null ) ) ; } for ( ObjectName name : blacklistObjectInstances ) { mBeanNames . remove ( beanConn . getObjectInstance ( name ) ) ; } for ( ObjectInstance name : mBeanNames ) { long start = System . nanoTime ( ) ; scrapeBean ( beanConn , name . getObjectName ( ) ) ; logger . fine ( "TIME: " + ( System . nanoTime ( ) - start ) + " ns for " + name . getObjectName ( ) . toString ( ) ) ; } } finally { if ( jmxc != null ) { jmxc . close ( ) ; } } }
Get a list of mbeans on host_port and scrape their values .