Search in sources :

Example 96 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project common by zenlunatics.

the class Admin method writeTomcatState.

// --------------------------------------------------------------------------
private void writeTomcatState(Request request) throws IOException {
    DecimalFormat df = new DecimalFormat();
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    try {
        request.writer.h4("Memory");
        Table table = new Table(request.writer).addClass("table table-condensed table-striped").addStyle("width", "auto");
        Runtime runtime = Runtime.getRuntime();
        table.tr().td("max").td(df.format(runtime.maxMemory()));
        table.tr().td("total").td(df.format(runtime.totalMemory()));
        table.tr().td("free").td(df.format(runtime.freeMemory()));
        table.tr().td("used").td(df.format(runtime.totalMemory() - runtime.freeMemory()));
        table.close();
        request.writer.h4("Sessions");
        String context = request.getContext();
        if (context == null || context.length() == 0)
            context = "/";
        ObjectName objectName = new ObjectName("Catalina:type=Manager,context=" + context + ",host=localhost");
        table = new Table(request.writer).addClass("table table-condensed table-striped").addStyle("width", "auto");
        table.tr().td("count").td(mBeanServer.getAttribute(objectName, "sessionCounter").toString());
        table.tr().td("active").td(mBeanServer.getAttribute(objectName, "activeSessions").toString());
        table.tr().td("expired").td(mBeanServer.getAttribute(objectName, "expiredSessions").toString());
        table.close();
    } catch (MalformedObjectNameException | AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException e) {
        System.out.println(e);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) AttributeNotFoundException(javax.management.AttributeNotFoundException) Table(web.Table) JDBCTable(db.JDBCTable) DecimalFormat(java.text.DecimalFormat) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 97 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project component-runtime by Talend.

the class JmxManager method onCreate.

@Override
public void onCreate(final Container container) {
    try {
        final ObjectName name = new ObjectName(String.format(namePattern, container.getId()));
        server.registerMBean(new ContainerMBean(manager, container), name);
        container.set(JmxData.class, new JmxData(name));
    } catch (final InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException | MalformedObjectNameException e) {
        log.warn(e.getMessage(), e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 98 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project redisson by redisson.

the class JCacheManager method enableManagement.

@Override
public void enableManagement(String cacheName, boolean enabled) {
    checkNotClosed();
    if (cacheName == null) {
        throw new NullPointerException();
    }
    JCache<?, ?> cache = caches.get(cacheName);
    if (cache == null) {
        throw new NullPointerException();
    }
    if (enabled) {
        JCacheManagementMXBean statBean = managementBeans.get(cache);
        if (statBean == null) {
            statBean = new JCacheManagementMXBean(cache);
            JCacheManagementMXBean oldBean = managementBeans.putIfAbsent(cache, statBean);
            if (oldBean != null) {
                statBean = oldBean;
            }
        }
        try {
            ObjectName objectName = queryNames("Configuration", cache);
            if (mBeanServer.queryNames(objectName, null).isEmpty()) {
                mBeanServer.registerMBean(statBean, objectName);
            }
        } catch (MalformedObjectNameException e) {
            throw new CacheException(e);
        } catch (InstanceAlreadyExistsException e) {
            throw new CacheException(e);
        } catch (MBeanRegistrationException e) {
            throw new CacheException(e);
        } catch (NotCompliantMBeanException e) {
            throw new CacheException(e);
        }
    } else {
        unregisterManagementBean(cache);
    }
    cache.getConfiguration(JCacheConfiguration.class).setManagementEnabled(enabled);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) JCacheConfiguration(org.redisson.jcache.configuration.JCacheConfiguration) CacheException(javax.cache.CacheException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) JCacheManagementMXBean(org.redisson.jcache.bean.JCacheManagementMXBean) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 99 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project cassandra by apache.

the class ColumnFamilyStoreMBeanIterator method connect.

/**
 * Create a connection to the JMX agent and setup the M[X]Bean proxies.
 *
 * @throws IOException on connection failures
 */
protected void connect() throws IOException {
    JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port));
    Map<String, Object> env = new HashMap<String, Object>();
    if (username != null) {
        String[] creds = { username, password };
        env.put(JMXConnector.CREDENTIALS, creds);
    }
    env.put("com.sun.jndi.rmi.factory.socket", getRMIClientSocketFactory());
    jmxc = JMXConnectorFactory.connect(jmxUrl, env);
    mbeanServerConn = jmxc.getMBeanServerConnection();
    try {
        ObjectName name = new ObjectName(ssObjName);
        ssProxy = JMX.newMBeanProxy(mbeanServerConn, name, StorageServiceMBean.class);
        name = new ObjectName(MessagingService.MBEAN_NAME);
        msProxy = JMX.newMBeanProxy(mbeanServerConn, name, MessagingServiceMBean.class);
        name = new ObjectName(StreamManagerMBean.OBJECT_NAME);
        streamProxy = JMX.newMBeanProxy(mbeanServerConn, name, StreamManagerMBean.class);
        name = new ObjectName(CompactionManager.MBEAN_OBJECT_NAME);
        compactionProxy = JMX.newMBeanProxy(mbeanServerConn, name, CompactionManagerMBean.class);
        name = new ObjectName(FailureDetector.MBEAN_NAME);
        fdProxy = JMX.newMBeanProxy(mbeanServerConn, name, FailureDetectorMBean.class);
        name = new ObjectName(CacheService.MBEAN_NAME);
        cacheService = JMX.newMBeanProxy(mbeanServerConn, name, CacheServiceMBean.class);
        name = new ObjectName(StorageProxy.MBEAN_NAME);
        spProxy = JMX.newMBeanProxy(mbeanServerConn, name, StorageProxyMBean.class);
        name = new ObjectName(HintsService.MBEAN_NAME);
        hsProxy = JMX.newMBeanProxy(mbeanServerConn, name, HintsServiceMBean.class);
        name = new ObjectName(GCInspector.MBEAN_NAME);
        gcProxy = JMX.newMBeanProxy(mbeanServerConn, name, GCInspectorMXBean.class);
        name = new ObjectName(Gossiper.MBEAN_NAME);
        gossProxy = JMX.newMBeanProxy(mbeanServerConn, name, GossiperMBean.class);
        name = new ObjectName(BatchlogManager.MBEAN_NAME);
        bmProxy = JMX.newMBeanProxy(mbeanServerConn, name, BatchlogManagerMBean.class);
        name = new ObjectName(ActiveRepairServiceMBean.MBEAN_NAME);
        arsProxy = JMX.newMBeanProxy(mbeanServerConn, name, ActiveRepairServiceMBean.class);
        name = new ObjectName(AuditLogManager.MBEAN_NAME);
        almProxy = JMX.newMBeanProxy(mbeanServerConn, name, AuditLogManagerMBean.class);
        name = new ObjectName(AuthCache.MBEAN_NAME_BASE + PasswordAuthenticator.CredentialsCacheMBean.CACHE_NAME);
        ccProxy = JMX.newMBeanProxy(mbeanServerConn, name, PasswordAuthenticator.CredentialsCacheMBean.class);
        name = new ObjectName(AuthCache.MBEAN_NAME_BASE + AuthorizationProxy.JmxPermissionsCacheMBean.CACHE_NAME);
        jpcProxy = JMX.newMBeanProxy(mbeanServerConn, name, AuthorizationProxy.JmxPermissionsCacheMBean.class);
        name = new ObjectName(AuthCache.MBEAN_NAME_BASE + NetworkPermissionsCache.CACHE_NAME);
        npcProxy = JMX.newMBeanProxy(mbeanServerConn, name, NetworkPermissionsCacheMBean.class);
        name = new ObjectName(AuthCache.MBEAN_NAME_BASE + PermissionsCache.CACHE_NAME);
        pcProxy = JMX.newMBeanProxy(mbeanServerConn, name, PermissionsCacheMBean.class);
        name = new ObjectName(AuthCache.MBEAN_NAME_BASE + RolesCache.CACHE_NAME);
        rcProxy = JMX.newMBeanProxy(mbeanServerConn, name, RolesCacheMBean.class);
    } catch (MalformedObjectNameException e) {
        throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e);
    }
    memProxy = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConn, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class);
    runtimeProxy = ManagementFactory.newPlatformMXBeanProxy(mbeanServerConn, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
}
Also used : HashMap(java.util.HashMap) CacheServiceMBean(org.apache.cassandra.service.CacheServiceMBean) GossiperMBean(org.apache.cassandra.gms.GossiperMBean) ActiveRepairServiceMBean(org.apache.cassandra.service.ActiveRepairServiceMBean) GCInspectorMXBean(org.apache.cassandra.service.GCInspectorMXBean) MemoryMXBean(java.lang.management.MemoryMXBean) StreamManagerMBean(org.apache.cassandra.streaming.StreamManagerMBean) StorageProxyMBean(org.apache.cassandra.service.StorageProxyMBean) AuditLogManagerMBean(org.apache.cassandra.audit.AuditLogManagerMBean) RolesCacheMBean(org.apache.cassandra.auth.RolesCacheMBean) JMXServiceURL(javax.management.remote.JMXServiceURL) MalformedObjectNameException(javax.management.MalformedObjectNameException) CompactionManagerMBean(org.apache.cassandra.db.compaction.CompactionManagerMBean) MessagingServiceMBean(org.apache.cassandra.net.MessagingServiceMBean) PermissionsCacheMBean(org.apache.cassandra.auth.PermissionsCacheMBean) NetworkPermissionsCacheMBean(org.apache.cassandra.auth.NetworkPermissionsCacheMBean) FailureDetectorMBean(org.apache.cassandra.gms.FailureDetectorMBean) NetworkPermissionsCacheMBean(org.apache.cassandra.auth.NetworkPermissionsCacheMBean) RuntimeMXBean(java.lang.management.RuntimeMXBean) ObjectName(javax.management.ObjectName) StorageServiceMBean(org.apache.cassandra.service.StorageServiceMBean) BatchlogManagerMBean(org.apache.cassandra.batchlog.BatchlogManagerMBean) HintsServiceMBean(org.apache.cassandra.hints.HintsServiceMBean)

Example 100 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project cassandra by apache.

the class ColumnFamilyStoreMBeanIterator method getColumnFamilyMetric.

/**
 * Retrieve ColumnFamily metrics
 * @param ks Keyspace for which stats are to be displayed or null for the global value
 * @param cf ColumnFamily for which stats are to be displayed or null for the keyspace value (if ks supplied)
 * @param metricName View {@link TableMetrics}.
 */
public Object getColumnFamilyMetric(String ks, String cf, String metricName) {
    try {
        ObjectName oName = null;
        if (!Strings.isNullOrEmpty(ks) && !Strings.isNullOrEmpty(cf)) {
            String type = cf.contains(".") ? "IndexTable" : "Table";
            oName = new ObjectName(String.format("org.apache.cassandra.metrics:type=%s,keyspace=%s,scope=%s,name=%s", type, ks, cf, metricName));
        } else if (!Strings.isNullOrEmpty(ks)) {
            oName = new ObjectName(String.format("org.apache.cassandra.metrics:type=Keyspace,keyspace=%s,name=%s", ks, metricName));
        } else {
            oName = new ObjectName(String.format("org.apache.cassandra.metrics:type=Table,name=%s", metricName));
        }
        switch(metricName) {
            case "BloomFilterDiskSpaceUsed":
            case "BloomFilterFalsePositives":
            case "BloomFilterFalseRatio":
            case "BloomFilterOffHeapMemoryUsed":
            case "IndexSummaryOffHeapMemoryUsed":
            case "CompressionMetadataOffHeapMemoryUsed":
            case "CompressionRatio":
            case "EstimatedColumnCountHistogram":
            case "EstimatedPartitionSizeHistogram":
            case "EstimatedPartitionCount":
            case "KeyCacheHitRate":
            case "LiveSSTableCount":
            case "OldVersionSSTableCount":
            case "MaxPartitionSize":
            case "MeanPartitionSize":
            case "MemtableColumnsCount":
            case "MemtableLiveDataSize":
            case "MemtableOffHeapSize":
            case "MinPartitionSize":
            case "PercentRepaired":
            case "BytesRepaired":
            case "BytesUnrepaired":
            case "BytesPendingRepair":
            case "RecentBloomFilterFalsePositives":
            case "RecentBloomFilterFalseRatio":
            case "SnapshotsSize":
                return JMX.newMBeanProxy(mbeanServerConn, oName, CassandraMetricsRegistry.JmxGaugeMBean.class).getValue();
            case "LiveDiskSpaceUsed":
            case "MemtableSwitchCount":
            case "SpeculativeRetries":
            case "TotalDiskSpaceUsed":
            case "WriteTotalLatency":
            case "ReadTotalLatency":
            case "PendingFlushes":
            case "DroppedMutations":
                return JMX.newMBeanProxy(mbeanServerConn, oName, CassandraMetricsRegistry.JmxCounterMBean.class).getCount();
            case "CoordinatorReadLatency":
            case "CoordinatorScanLatency":
            case "ReadLatency":
            case "WriteLatency":
                return JMX.newMBeanProxy(mbeanServerConn, oName, CassandraMetricsRegistry.JmxTimerMBean.class);
            case "LiveScannedHistogram":
            case "SSTablesPerReadHistogram":
            case "TombstoneScannedHistogram":
                return JMX.newMBeanProxy(mbeanServerConn, oName, CassandraMetricsRegistry.JmxHistogramMBean.class);
            default:
                throw new RuntimeException("Unknown table metric " + metricName);
        }
    } catch (MalformedObjectNameException e) {
        throw new RuntimeException(e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) CassandraMetricsRegistry(org.apache.cassandra.metrics.CassandraMetricsRegistry) ObjectName(javax.management.ObjectName)

Aggregations

MalformedObjectNameException (javax.management.MalformedObjectNameException)309 ObjectName (javax.management.ObjectName)285 InstanceNotFoundException (javax.management.InstanceNotFoundException)88 MBeanServer (javax.management.MBeanServer)80 MBeanRegistrationException (javax.management.MBeanRegistrationException)75 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)63 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)59 IOException (java.io.IOException)53 ArrayList (java.util.ArrayList)45 ReflectionException (javax.management.ReflectionException)30 MBeanException (javax.management.MBeanException)23 Test (org.testng.annotations.Test)23 CompositeData (javax.management.openmbean.CompositeData)18 Notification (javax.management.Notification)15 MBeanInfo (javax.management.MBeanInfo)14 AttributeNotFoundException (javax.management.AttributeNotFoundException)13 HashMap (java.util.HashMap)11 Map (java.util.Map)11 IntrospectionException (javax.management.IntrospectionException)11 MalformedURLException (java.net.MalformedURLException)10