Search in sources :

Example 11 with JMXConnector

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);
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Example 12 with JMXConnector

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);
        }
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HostIdentifier(sun.jvmstat.monitor.HostIdentifier) ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName) JMXConnector(javax.management.remote.JMXConnector) MonitoredHost(sun.jvmstat.monitor.MonitoredHost) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 13 with JMXConnector

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);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ConnectException(java.net.ConnectException) ReflectionException(javax.management.ReflectionException)

Example 14 with JMXConnector

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();
    }
}
Also used : JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection)

Example 15 with JMXConnector

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);
}
Also used : TargetSource(org.springframework.aop.TargetSource) AbstractLazyCreationTargetSource(org.springframework.aop.target.AbstractLazyCreationTargetSource) ProxyFactory(org.springframework.aop.framework.ProxyFactory) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection)

Aggregations

JMXConnector (javax.management.remote.JMXConnector)118 MBeanServerConnection (javax.management.MBeanServerConnection)85 JMXServiceURL (javax.management.remote.JMXServiceURL)78 ObjectName (javax.management.ObjectName)54 JMXConnectorServer (javax.management.remote.JMXConnectorServer)47 MBeanServer (javax.management.MBeanServer)37 IOException (java.io.IOException)35 HashMap (java.util.HashMap)27 Test (org.junit.Test)22 Notification (javax.management.Notification)14 NotificationListener (javax.management.NotificationListener)14 Attribute (javax.management.Attribute)13 MalformedURLException (java.net.MalformedURLException)12 RemoteException (java.rmi.RemoteException)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 MalformedObjectNameException (javax.management.MalformedObjectNameException)9 LocateRegistry (java.rmi.registry.LocateRegistry)8 Registry (java.rmi.registry.Registry)8 Properties (java.util.Properties)7