Search in sources :

Example 71 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project narayana by jbosstm.

the class TxPerfGraph method connect.

private static MBeanServerConnection connect(String hostname, int port) {
    String urlPath = "/jndi/rmi://" + hostname + ":" + port + "/jmxrmi";
    MBeanServerConnection server = null;
    try {
        JMXServiceURL url = new JMXServiceURL("rmi", "", 0, urlPath);
        JMXConnector jmxc = JMXConnectorFactory.connect(url);
        server = jmxc.getMBeanServerConnection();
    } catch (MalformedURLException e) {
    } catch (IOException e) {
        System.err.println("Unable to get an MBean Server connection: " + e.getMessage());
        System.exit(1);
    }
    return server;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MalformedURLException(java.net.MalformedURLException) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 72 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project nimbus by nimbus-org.

the class DefaultMBeanServerConnectionFactoryService method getConnection.

public MBeanServerConnection getConnection() throws MBeanServerConnectionFactoryException {
    MBeanServerConnection connection = null;
    try {
        if (jndiFinder != null) {
            connection = (MBeanServerConnection) jndiFinder.lookup(rmiAdaptorName);
        /*
            }else{
*/
        } else if (serviceURL != null) {
            if (connector == null) {
                synchronized (connector) {
                    if (connector == null) {
                        connector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL(serviceURL), jmxConnectorEnvironment);
                        connector.connect();
                        isConnected = true;
                    }
                }
            } else if (!isConnected) {
                synchronized (connector) {
                    if (!isConnected) {
                        connector.connect();
                        isConnected = true;
                    }
                }
            }
            connection = connector.getMBeanServerConnection();
        } else {
            connection = ManagementFactory.getPlatformMBeanServer();
        }
    } catch (IOException e) {
        throw new MBeanServerConnectionFactoryException(e);
    } catch (NamingException e) {
        throw new MBeanServerConnectionFactoryException(e);
    }
    return connection;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) NamingException(javax.naming.NamingException) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 73 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project nimbus by nimbus-org.

the class DefaultMBeanServerConnectionFactoryService method getJMXConnector.

public JMXConnector getJMXConnector() throws MBeanServerConnectionFactoryException {
    if (serviceURL != null) {
        JMXConnector connector = this.connector;
        try {
            if (isNewConnection) {
                connector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL(serviceURL), jmxConnectorEnvironment);
                connector.connect();
            } else if (!isConnected) {
                synchronized (connector) {
                    if (!isConnected) {
                        connector.connect();
                        isConnected = true;
                    }
                }
            }
            return connector;
        } catch (IOException e) {
            throw new MBeanServerConnectionFactoryException(e);
        }
    } else {
        return new JMXConnectorWrapper(getConnection());
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException)

Example 74 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project nimbus by nimbus-org.

the class MBeanWatcherService method startService.

public void startService() throws Exception {
    if (jndiFinderServiceName != null) {
        jndiFinder = (JndiFinder) ServiceManagerFactory.getServiceObject(jndiFinderServiceName);
    } else if (serviceURL != null) {
        if (isConnectOnStart) {
            connector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL(serviceURL), jmxConnectorEnvironment);
            connector.connect();
        }
    /*
        }else{
            throw new IllegalArgumentException("ServiceURL or jndiFinderServiceName must be specified.");
*/
    }
    if (categoryServiceName != null) {
        category = (Category) ServiceManagerFactory.getServiceObject(categoryServiceName);
    }
    for (int i = 0, imax = targetList.size(); i < imax; i++) {
        Target target = (Target) targetList.get(i);
        target.setWatcherServiceName(getServiceNameObject());
        target.setWatcherService(this);
        target.setLogger(getLogger());
        if (isResetOnStart) {
            target.reset();
        }
        target.start();
    }
    if (interval > 0) {
        watcher = new Daemon(this);
        watcher.setName("Nimbus MBeanWatcher " + getServiceNameObject());
        watcher.setDaemon(true);
        if (connector != null) {
            JMXConnectorNotificationListener listener = new JMXConnectorNotificationListener();
            connector.addConnectionNotificationListener(listener, listener, watcher);
        }
        watcher.start();
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) Daemon(jp.ossc.nimbus.daemon.Daemon)

Example 75 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project jmx_exporter by prometheus.

the class JmxScraper method doScrape.

/**
 * Get a list of mbeans on host_port and scrape their values.
 *
 * Values are passed to the receiver in a single thread.
 */
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<ObjectName> mBeanNames = new HashSet<ObjectName>();
        for (ObjectName name : whitelistObjectNames) {
            for (ObjectInstance instance : beanConn.queryMBeans(name, null)) {
                mBeanNames.add(instance.getObjectName());
            }
        }
        for (ObjectName name : blacklistObjectNames) {
            for (ObjectInstance instance : beanConn.queryMBeans(name, null)) {
                mBeanNames.remove(instance.getObjectName());
            }
        }
        // Now that we have *only* the whitelisted mBeans, remove any old ones from the cache:
        jmxMBeanPropertyCache.onlyKeepMBeans(mBeanNames);
        for (ObjectName objectName : mBeanNames) {
            long start = System.nanoTime();
            scrapeBean(beanConn, objectName);
            logger.fine("TIME: " + (System.nanoTime() - start) + " ns for " + objectName.toString());
        }
    } finally {
        if (jmxc != null) {
            jmxc.close();
        }
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName) SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) HashSet(java.util.HashSet)

Aggregations

JMXServiceURL (javax.management.remote.JMXServiceURL)280 JMXConnector (javax.management.remote.JMXConnector)150 MBeanServerConnection (javax.management.MBeanServerConnection)107 ObjectName (javax.management.ObjectName)90 IOException (java.io.IOException)78 HashMap (java.util.HashMap)75 MBeanServer (javax.management.MBeanServer)71 JMXConnectorServer (javax.management.remote.JMXConnectorServer)64 MalformedURLException (java.net.MalformedURLException)45 RemoteException (java.rmi.RemoteException)22 Test (org.junit.Test)22 Map (java.util.Map)16 UnknownHostException (java.net.UnknownHostException)14 Properties (java.util.Properties)14 Notification (javax.management.Notification)14 NotificationListener (javax.management.NotificationListener)14 MalformedObjectNameException (javax.management.MalformedObjectNameException)13 LocateRegistry (java.rmi.registry.LocateRegistry)12 Registry (java.rmi.registry.Registry)12 ArrayList (java.util.ArrayList)11