Example usage for javax.management ObjectName ObjectName

List of usage examples for javax.management ObjectName ObjectName

Introduction

In this page you can find the example usage for javax.management ObjectName ObjectName.

Prototype

public ObjectName(String name) throws MalformedObjectNameException 

Source Link

Document

Construct an object name from the given string.

Usage

From source file:com.newlandframework.rpc.jmx.ThreadPoolMonitorProvider.java

public static void monitor(ThreadPoolStatus status) throws IOException, MalformedObjectNameException,
        ReflectionException, MBeanException, InstanceNotFoundException {
    MBeanServerConnectionFactoryBean mBeanServerConnectionFactoryBean = new MBeanServerConnectionFactoryBean();
    mBeanServerConnectionFactoryBean.setServiceUrl(url);
    mBeanServerConnectionFactoryBean.afterPropertiesSet();
    MBeanServerConnection connection = mBeanServerConnectionFactoryBean.getObject();
    ObjectName objectName = new ObjectName(
            "com.newlandframework.rpc.jmx:name=threadPoolStatus,type=ThreadPoolStatus");

    connection.invoke(objectName, jmxPoolSizeMethod, new Object[] { status.getPoolSize() },
            new String[] { int.class.getName() });
    connection.invoke(objectName, jmxActiveCountMethod, new Object[] { status.getActiveCount() },
            new String[] { int.class.getName() });
    connection.invoke(objectName, jmxCorePoolSizeMethod, new Object[] { status.getCorePoolSize() },
            new String[] { int.class.getName() });
    connection.invoke(objectName, jmxMaximumPoolSizeMethod, new Object[] { status.getMaximumPoolSize() },
            new String[] { int.class.getName() });
    connection.invoke(objectName, jmxLargestPoolSizeMethod, new Object[] { status.getLargestPoolSize() },
            new String[] { int.class.getName() });
    connection.invoke(objectName, jmxTaskCountMethod, new Object[] { status.getTaskCount() },
            new String[] { long.class.getName() });
    connection.invoke(objectName, jmxCompletedTaskCountMethod, new Object[] { status.getCompletedTaskCount() },
            new String[] { long.class.getName() });
}

From source file:net.centro.rtb.monitoringcenter.metrics.tomcat.TomcatConnectorMetricSet.java

TomcatConnectorMetricSet(ObjectName threadPoolObjectName) {
    Preconditions.checkNotNull(threadPoolObjectName);

    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

    this.name = threadPoolObjectName.getKeyProperty("name");
    this.port = JmxUtil.getJmxAttribute(threadPoolObjectName, "port", Integer.class, null);

    Set<ObjectName> connectorObjectNames = null;
    try {//from   w w  w.ja va  2s  . co m
        connectorObjectNames = mBeanServer.queryNames(new ObjectName("Catalina:type=Connector,port=" + port),
                null);
    } catch (MalformedObjectNameException e) {
        logger.debug("Invalid ObjectName defined for the Tomcat's Connector MxBean for the {} thread pool",
                name, e);
    }

    if (connectorObjectNames != null && !connectorObjectNames.isEmpty()) {
        ObjectName connectorObjectName = connectorObjectNames.iterator().next();
        String internalPortStr = JmxUtil.getJmxAttribute(connectorObjectName, "internalPort", String.class,
                Boolean.FALSE.toString());
        this.isInternalPort = Boolean.TRUE.toString().equalsIgnoreCase(internalPortStr);
    }

    this.isSecure = JmxUtil.getJmxAttribute(threadPoolObjectName, "sSLEnabled", Boolean.class, Boolean.FALSE);
    this.isAjp = isAjpFromName(name);

    Map<String, Metric> metricsByNames = new HashMap<>();

    this.currentPoolSizeGauge = JmxUtil.getJmxAttributeAsGauge(threadPoolObjectName, "currentThreadCount",
            Integer.class, 0);
    if (currentPoolSizeGauge != null) {
        metricsByNames.put("currentPoolSize", currentPoolSizeGauge);
    }

    this.maxPoolSizeGauge = JmxUtil.getJmxAttributeAsGauge(threadPoolObjectName, "maxThreads", Integer.class,
            0);
    if (maxPoolSizeGauge != null) {
        metricsByNames.put("maxPoolSize", maxPoolSizeGauge);
    }

    this.busyThreadsGauge = JmxUtil.getJmxAttributeAsGauge(threadPoolObjectName, "currentThreadsBusy",
            Integer.class, 0);
    if (busyThreadsGauge != null) {
        metricsByNames.put("busyThreads", busyThreadsGauge);
    }

    this.activeConnectionsGauge = JmxUtil.getJmxAttributeAsGauge(threadPoolObjectName, "connectionCount",
            Long.class, 0L);
    if (activeConnectionsGauge != null) {
        metricsByNames.put("activeConnections", activeConnectionsGauge);
    }

    this.maxConnectionsGauge = JmxUtil.getJmxAttributeAsGauge(threadPoolObjectName, "maxConnections",
            Integer.class, 0);
    if (maxConnectionsGauge != null) {
        metricsByNames.put("maxConnections", maxConnectionsGauge);
    }

    Set<ObjectName> globalRequestProcessorObjectNames = null;
    try {
        globalRequestProcessorObjectNames = mBeanServer
                .queryNames(new ObjectName("Catalina:type=GlobalRequestProcessor,name=" + name), null);
    } catch (MalformedObjectNameException e) {
        logger.debug(
                "Invalid ObjectName defined for the Tomcat's GlobalRequestProcessor MxBean for the {} thread pool",
                name, e);
    }

    if (globalRequestProcessorObjectNames != null && !globalRequestProcessorObjectNames.isEmpty()) {
        ObjectName globalRequestProcessorObjectName = globalRequestProcessorObjectNames.iterator().next();
        this.totalRequestsGauge = JmxUtil.getJmxAttributeAsGauge(globalRequestProcessorObjectName,
                "requestCount", Integer.class, 0);

        if (totalRequestsGauge != null) {
            metricsByNames.put("totalRequests", totalRequestsGauge);

            this.qpsHolder = new AtomicInteger();
            this.previousRequestCount = totalRequestsGauge.getValue();

            this.qpsGauge = new Gauge<Integer>() {
                @Override
                public Integer getValue() {
                    return qpsHolder.get();
                }
            };
            metricsByNames.put("qps", qpsGauge);
        }

        this.errorsGauge = JmxUtil.getJmxAttributeAsGauge(globalRequestProcessorObjectName, "errorCount",
                Integer.class, 0);
        if (errorsGauge != null) {
            metricsByNames.put("errors", errorsGauge);
        }

        this.receivedBytesGauge = JmxUtil.getJmxAttributeAsGauge(globalRequestProcessorObjectName,
                "bytesReceived", Long.class, 0L);
        if (receivedBytesGauge != null) {
            metricsByNames.put("receivedBytes", receivedBytesGauge);
        }

        this.sentBytesGauge = JmxUtil.getJmxAttributeAsGauge(globalRequestProcessorObjectName, "bytesSent",
                Long.class, 0L);
        if (sentBytesGauge != null) {
            metricsByNames.put("sentBytes", sentBytesGauge);
        }
    }

    this.metricsByNames = metricsByNames;
}

From source file:com.athena.dolly.console.module.jmx.JmxClientManager.java

public static MemoryVo getMemoryUsage(String nodeName) {
    JmxClient jmxClient = jmxClientMap.get(nodeName);

    MemoryVo memory = null;//from w w w. j  av  a 2  s.co m
    try {
        ObjectName objectName = new ObjectName("java.lang:type=Memory");

        MBeanServerConnection connection = jmxClient.getJmxConnector().getMBeanServerConnection();
        CompositeDataSupport heapMemoryUsage = (CompositeDataSupport) connection.getAttribute(objectName,
                "HeapMemoryUsage");

        memory = new MemoryVo();
        memory.setCommitted((Long) heapMemoryUsage.get("committed"));
        memory.setInit((Long) heapMemoryUsage.get("init"));
        memory.setMax((Long) heapMemoryUsage.get("max"));
        memory.setUsed((Long) heapMemoryUsage.get("used"));

        logger.debug("nodeName: [{}], memoryUsage: [committed: {}, init:{}, max:{}, used:{}]", new Object[] {
                nodeName, memory.getCommitted(), memory.getInit(), memory.getMax(), memory.getUsed() });
    } catch (Exception e) {
        logger.error("unhandled exception has errored : ", e);
    }

    return memory;
}

From source file:com.rackspacecloud.blueflood.cache.TtlCacheTest.java

@After
public void deregister() throws Exception {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    final String name = String.format(TtlCache.class.getPackage().getName() + ":type=%s,scope=%s,name=Stats",
            TtlCache.class.getSimpleName(), "Test");
    final ObjectName nameObj = new ObjectName(name);
    mbs.unregisterMBean(nameObj);//from w ww  . j a va 2 s .c  o m

    // involves a little unsafe knowledge of TtlCache internals.
    Metrics.defaultRegistry().removeMetric(TtlCache.class, "Load Errors", "Test");
    Metrics.defaultRegistry().removeMetric(TtlCache.class, "Http Errors", "Test");
}

From source file:io.fabric8.api.jmx.FabricManager.java

public ObjectName getObjectName() throws MalformedObjectNameException {
    if (objectName == null) {
        // TODO to avoid mbean clashes if ever a JVM had multiple FabricService instances, we may
        // want to add a parameter of the fabric ID here...
        objectName = new ObjectName("io.fabric8:type=Fabric");
    }/*from   w  w w .  j  a  v a2s  . co m*/
    return objectName;
}

From source file:org.jeasy.props.PropertiesInjectorImplTest.java

@Test
public void testManageableConfiguration() throws Exception {
    System.setProperty("sp", "foo");
    ManageableConfig config = new ManageableConfig();
    aNewPropertiesInjector().injectProperties(config);

    ObjectName objectName = new ObjectName("org.jeasy.props:name=myConfig");
    assertThat(getPlatformMBeanServer().isRegistered(objectName)).isTrue();
}

From source file:net.sbbi.upnp.jmx.JMXManager.java

public void startup(int discoveryTimeout) throws Exception {
    discBeanName = new ObjectName("UPNPLib discovery:name=Discovery MBean_" + this.hashCode());
    UPNPDiscoveryMBean bean = new UPNPDiscovery(discoveryTimeout, true, true);
    server.registerMBean(bean, discBeanName);
}

From source file:io.github.benas.easyproperties.PropertiesInjectorImplTest.java

@Test
public void testManageableConfiguration() throws Exception {
    System.setProperty("sp", "foo");
    ManageableConfig config = new ManageableConfig();
    aNewPropertiesInjector().injectProperties(config);

    ObjectName objectName = new ObjectName("io.github.benas.easyproperties:name=myConfig");
    assertThat(getPlatformMBeanServer().isRegistered(objectName)).isTrue();
}

From source file:net.nicoll.boot.daemon.SpringApplicationAdminClient.java

private ObjectName toObjectName(String name) {
    try {/*ww w  .java  2 s .c  om*/
        return new ObjectName(name);
    } catch (MalformedObjectNameException ex) {
        throw new IllegalArgumentException("Invalid jmx name '" + name + "'");
    }
}