org.collectd.mx.RemoteMBeanSender Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jcollectd Show documentation
Show all versions of jcollectd Show documentation
The jcollectd package implements the collectd protocol in Java, making it possible for Java applications to push data into collectd over the wire.
The newest version!
/*
* jcollectd
* Copyright (C) 2009 Hyperic, Inc.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; only version 2 of the License is applicable.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.collectd.mx;
import java.io.IOException;
import java.lang.instrument.Instrumentation;
import java.util.logging.Logger;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import org.collectd.protocol.Network;
import org.collectd.protocol.PropertyNames;
/**
* Out-of-process MBeanSender, polling a remote JMX MBeanServer.
*/
public class RemoteMBeanSender extends MBeanSender {
private static final Logger _log =
Logger.getLogger(RemoteMBeanSender.class.getName());
public void setMBeanServerConnection(JMXServiceURL url)
throws IOException {
JMXConnector connector =
JMXConnectorFactory.connect(url);
setMBeanServerConnection(connector.getMBeanServerConnection());
}
public void setMBeanServerConnection(String url)
throws IOException {
if (url.indexOf('/') == -1) {
url =
"service:jmx:rmi:///jndi/rmi://" +
url +
"/jmxrmi";
}
_log.fine("URL=" + url);
setMBeanServerConnection(new JMXServiceURL(url));
}
public void configure() {
String url = Network.getProperty(PropertyNames.CONNECTION_URL);
if (url != null) {
try {
setMBeanServerConnection(url);
} catch (IOException e) {
_log.warning(url + ": " + e);
}
}
super.configure();
}
public static void premain(String args, Instrumentation instr) {
MBeanSender sender = new RemoteMBeanSender();
sender.premainConfigure(args);
}
}