use of javax.management.remote.JMXConnector in project jersey by jersey.
the class Main method main.
public static void main(String[] args) throws Exception {
// e.g. "service:jmx:rmi:///jndi/rmi://sysifos.cz.oracle.com:11112/jmxrmi"
final String jmxUrl = args[0];
// e.g. "org.glassfish.jersey.test.performance.interceptor.dynamic:type=DynamicallyBoundInterceptorResource,name=gets"
final String mBeanName = args[1];
// e.g. "OneMinuteRate"
final String mBeanAttrName = args[2];
// e.g. 50
final int sampleCount = Integer.parseInt(args[3]);
// e.g. "phishing.properties"
final String propertiesFile = args[4];
System.out.printf("JMX URL = %s\nMBean = %s\nattribute = %s\nsamples = %d\nfilename = %s\n" + "Going to connect...\n", jmxUrl, mBeanName, mBeanAttrName, sampleCount, propertiesFile);
final JMXServiceURL url = new JMXServiceURL(jmxUrl);
final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
final MBeanServerConnection mBeanServer = jmxc.getMBeanServerConnection();
final ObjectName mBeanObjectName = new ObjectName(mBeanName);
System.out.println("Connected...");
double totalSum = 0;
int samplesTaken = 0;
for (int i = 0; i < sampleCount; i++) {
Thread.sleep(5000);
Double sample = (Double) mBeanServer.getAttribute(mBeanObjectName, mBeanAttrName);
System.out.printf("OMR[%d]=%f\n", i, sample);
totalSum += sample;
samplesTaken++;
}
jmxc.close();
final double result = totalSum / samplesTaken;
writeResult(result, propertiesFile);
System.out.printf("\nAverage=%f\n", result);
}
use of javax.management.remote.JMXConnector in project rest.li by linkedin.
the class LoadBalancerClientCli method resetTogglingStores.
public static void resetTogglingStores(String host, boolean enabled) throws Exception {
MonitoredHost _host = MonitoredHost.getMonitoredHost(new HostIdentifier(host));
for (Object pidObj : _host.activeVms()) {
int pid = (Integer) pidObj;
System.out.println("checking pid: " + pid);
JMXServiceURL jmxUrl = null;
com.sun.tools.attach.VirtualMachine vm = com.sun.tools.attach.VirtualMachine.attach(pid + "");
try {
// get the connector address
String connectorAddress = vm.getAgentProperties().getProperty(CONNECTOR_ADDRESS);
// establish connection to connector server
if (connectorAddress != null) {
jmxUrl = new JMXServiceURL(connectorAddress);
}
} finally {
vm.detach();
}
if (jmxUrl != null) {
System.out.println("got jmx url: " + jmxUrl);
// connect to jmx
JMXConnector connector = JMXConnectorFactory.connect(jmxUrl);
connector.connect();
MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
// look for all beans in the d2 name space
Set<ObjectInstance> objectInstances = mbeanServer.queryMBeans(new ObjectName("com.linkedin.d2:*"), null);
for (ObjectInstance objectInstance : objectInstances) {
System.err.println("checking object: " + objectInstance.getObjectName());
// if we've found a toggling store, then toggle it
if (objectInstance.getObjectName().toString().endsWith("TogglingStore")) {
System.out.println("found toggling zk store, so toggling to: " + enabled);
mbeanServer.invoke(objectInstance.getObjectName(), "setEnabled", new Object[] { enabled }, new String[] { "boolean" });
}
}
} else {
System.out.println("pid is not a jmx process: " + pid);
}
}
}
use of javax.management.remote.JMXConnector in project spring-boot by spring-projects.
the class StartMojo method waitForForkedSpringApplication.
private void waitForForkedSpringApplication() throws IOException, MojoFailureException, MojoExecutionException {
try {
getLog().debug("Connecting to local MBeanServer at port " + this.jmxPort);
JMXConnector connector = execute(this.wait, this.maxAttempts, new CreateJmxConnector(this.jmxPort));
if (connector == null) {
throw new MojoExecutionException("JMX MBean server was not reachable before the configured " + "timeout (" + (this.wait * this.maxAttempts) + "ms");
}
getLog().debug("Connected to local MBeanServer at port " + this.jmxPort);
try {
MBeanServerConnection connection = connector.getMBeanServerConnection();
doWaitForSpringApplication(connection);
} finally {
connector.close();
}
} catch (IOException ex) {
throw ex;
} catch (Exception ex) {
throw new MojoExecutionException("Failed to connect to MBean server at port " + this.jmxPort, ex);
}
}
use of javax.management.remote.JMXConnector in project spring-boot by spring-projects.
the class StopMojo method stopForkedProcess.
private void stopForkedProcess() throws IOException, MojoFailureException, MojoExecutionException {
JMXConnector connector = SpringApplicationAdminClient.connect(this.jmxPort);
try {
MBeanServerConnection connection = connector.getMBeanServerConnection();
doStop(connection);
} finally {
connector.close();
}
}
use of javax.management.remote.JMXConnector in project spring-framework by spring-projects.
the class MBeanServerConnectionFactoryBean method createLazyConnection.
/**
* Creates lazy proxies for the {@code JMXConnector} and {@code MBeanServerConnection}
*/
private void createLazyConnection() {
this.connectorTargetSource = new JMXConnectorLazyInitTargetSource();
TargetSource connectionTargetSource = new MBeanServerConnectionLazyInitTargetSource();
this.connector = (JMXConnector) new ProxyFactory(JMXConnector.class, this.connectorTargetSource).getProxy(this.beanClassLoader);
this.connection = (MBeanServerConnection) new ProxyFactory(MBeanServerConnection.class, connectionTargetSource).getProxy(this.beanClassLoader);
}
Aggregations