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;
}
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;
}
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());
}
}
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();
}
}
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();
}
}
}
Aggregations