Search in sources :

Example 16 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project druid by alibaba.

the class DataSourceProxyImpl method getCompositeData.

public CompositeDataSupport getCompositeData() throws JMException {
    JdbcDataSourceStat stat = this.getDataSourceStat();
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("ID", id);
    map.put("URL", this.getUrl());
    map.put("Name", this.getName());
    map.put("FilterClasses", getFilterClasses());
    map.put("CreatedTime", getCreatedTime());
    map.put("RawDriverClassName", getRawDriverClassName());
    map.put("RawUrl", getRawUrl());
    map.put("RawDriverMajorVersion", getRawDriverMajorVersion());
    map.put("RawDriverMinorVersion", getRawDriverMinorVersion());
    map.put("Properties", getProperties());
    if (stat != null) {
        map.put("ConnectionActiveCount", stat.getConnectionActiveCount());
        map.put("ConnectionActiveCountMax", stat.getConnectionStat().getActiveMax());
        map.put("ConnectionCloseCount", stat.getConnectionStat().getCloseCount());
        map.put("ConnectionCommitCount", stat.getConnectionStat().getCommitCount());
        map.put("ConnectionRollbackCount", stat.getConnectionStat().getRollbackCount());
        map.put("ConnectionConnectLastTime", stat.getConnectionStat().getConnectLastTime());
        map.put("ConnectionConnectErrorCount", stat.getConnectionStat().getConnectErrorCount());
        Throwable lastConnectionConnectError = stat.getConnectionStat().getConnectErrorLast();
        if (lastConnectionConnectError != null) {
            map.put("ConnectionConnectErrorLastTime", stat.getConnectionStat().getErrorLastTime());
            map.put("ConnectionConnectErrorLastMessage", lastConnectionConnectError.getMessage());
            map.put("ConnectionConnectErrorLastStackTrace", Utils.getStackTrace(lastConnectionConnectError));
        } else {
            map.put("ConnectionConnectErrorLastTime", null);
            map.put("ConnectionConnectErrorLastMessage", null);
            map.put("ConnectionConnectErrorLastStackTrace", null);
        }
        map.put("StatementCreateCount", stat.getStatementStat().getCreateCount());
        map.put("StatementPrepareCount", stat.getStatementStat().getPrepareCount());
        map.put("StatementPreCallCount", stat.getStatementStat().getPrepareCallCount());
        map.put("StatementExecuteCount", stat.getStatementStat().getExecuteCount());
        map.put("StatementRunningCount", stat.getStatementStat().getRunningCount());
        map.put("StatementConcurrentMax", stat.getStatementStat().getConcurrentMax());
        map.put("StatementCloseCount", stat.getStatementStat().getCloseCount());
        map.put("StatementErrorCount", stat.getStatementStat().getErrorCount());
        Throwable lastStatementError = stat.getStatementStat().getLastException();
        if (lastStatementError != null) {
            map.put("StatementLastErrorTime", stat.getStatementStat().getLastErrorTime());
            map.put("StatementLastErrorMessage", lastStatementError.getMessage());
            map.put("StatementLastErrorStackTrace", Utils.getStackTrace(lastStatementError));
        } else {
            map.put("StatementLastErrorTime", null);
            map.put("StatementLastErrorMessage", null);
            map.put("StatementLastErrorStackTrace", null);
        }
        map.put("StatementExecuteMillisTotal", stat.getStatementStat().getMillisTotal());
        map.put("StatementExecuteLastTime", stat.getStatementStat().getExecuteLastTime());
        map.put("ConnectionConnectingCount", stat.getConnectionStat().getConnectingCount());
        map.put("ResultSetCloseCount", stat.getResultSetStat().getCloseCount());
        map.put("ResultSetOpenCount", stat.getResultSetStat().getOpenCount());
        map.put("ResultSetOpenningCount", stat.getResultSetStat().getOpeningCount());
        map.put("ResultSetOpenningMax", stat.getResultSetStat().getOpeningMax());
        map.put("ResultSetFetchRowCount", stat.getResultSetStat().getFetchRowCount());
        map.put("ResultSetLastOpenTime", stat.getResultSetStat().getLastOpenTime());
        map.put("ResultSetErrorCount", stat.getResultSetStat().getErrorCount());
        map.put("ResultSetOpenningMillisTotal", stat.getResultSetStat().getAliveMillisTotal());
        map.put("ResultSetLastErrorTime", stat.getResultSetStat().getLastErrorTime());
        Throwable lastResultSetError = stat.getResultSetStat().getLastError();
        if (lastResultSetError != null) {
            map.put("ResultSetLastErrorMessage", lastResultSetError.getMessage());
            map.put("ResultSetLastErrorStackTrace", Utils.getStackTrace(lastResultSetError));
        } else {
            map.put("ResultSetLastErrorMessage", null);
            map.put("ResultSetLastErrorStackTrace", null);
        }
        map.put("ConnectionConnectCount", stat.getConnectionStat().getConnectCount());
        Throwable lastConnectionError = stat.getConnectionStat().getErrorLast();
        if (lastConnectionError != null) {
            map.put("ConnectionErrorLastMessage", lastConnectionError.getMessage());
            map.put("ConnectionErrorLastStackTrace", Utils.getStackTrace(lastConnectionError));
        } else {
            map.put("ConnectionErrorLastMessage", null);
            map.put("ConnectionErrorLastStackTrace", null);
        }
        map.put("ConnectionConnectMillisTotal", stat.getConnectionStat().getConnectMillis());
        map.put("ConnectionConnectingCountMax", stat.getConnectionStat().getConnectingMax());
        map.put("ConnectionConnectMillisMax", stat.getConnectionStat().getConnectMillisMax());
        map.put("ConnectionErrorLastTime", stat.getConnectionStat().getErrorLastTime());
        map.put("ConnectionAliveMillisMax", stat.getConnectionConnectAliveMillisMax());
        map.put("ConnectionAliveMillisMin", stat.getConnectionConnectAliveMillisMin());
        map.put("ConnectionHistogram", stat.getConnectionHistogramValues());
        map.put("StatementHistogram", stat.getStatementStat().getHistogramValues());
    } else {
        map.put("ConnectionActiveCount", null);
        map.put("ConnectionActiveCountMax", null);
        map.put("ConnectionCloseCount", null);
        map.put("ConnectionCommitCount", null);
        map.put("ConnectionRollbackCount", null);
        map.put("ConnectionConnectLastTime", null);
        map.put("ConnectionConnectErrorCount", null);
        map.put("ConnectionConnectErrorLastTime", null);
        map.put("ConnectionConnectErrorLastMessage", null);
        map.put("ConnectionConnectErrorLastStackTrace", null);
        map.put("StatementCreateCount", null);
        map.put("StatementPrepareCount", null);
        map.put("StatementPreCallCount", null);
        map.put("StatementExecuteCount", null);
        map.put("StatementRunningCount", null);
        map.put("StatementConcurrentMax", null);
        map.put("StatementCloseCount", null);
        map.put("StatementErrorCount", null);
        map.put("StatementLastErrorTime", null);
        map.put("StatementLastErrorMessage", null);
        map.put("StatementLastErrorStackTrace", null);
        map.put("StatementExecuteMillisTotal", null);
        map.put("ConnectionConnectingCount", null);
        map.put("StatementExecuteLastTime", null);
        map.put("ResultSetCloseCount", null);
        map.put("ResultSetOpenCount", null);
        map.put("ResultSetOpenningCount", null);
        map.put("ResultSetOpenningMax", null);
        map.put("ResultSetFetchRowCount", null);
        map.put("ResultSetLastOpenTime", null);
        map.put("ResultSetErrorCount", null);
        map.put("ResultSetOpenningMillisTotal", null);
        map.put("ResultSetLastErrorTime", null);
        map.put("ResultSetLastErrorMessage", null);
        map.put("ResultSetLastErrorStackTrace", null);
        map.put("ConnectionConnectCount", null);
        map.put("ConnectionErrorLastMessage", null);
        map.put("ConnectionErrorLastStackTrace", null);
        map.put("ConnectionConnectMillisTotal", null);
        map.put("ConnectionConnectingCountMax", null);
        map.put("ConnectionConnectMillisMax", null);
        map.put("ConnectionErrorLastTime", null);
        map.put("ConnectionAliveMillisMax", null);
        map.put("ConnectionAliveMillisMin", null);
        map.put("ConnectionHistogram", new long[0]);
        map.put("StatementHistogram", new long[0]);
    }
    return new CompositeDataSupport(JdbcStatManager.getDataSourceCompositeType(), map);
}
Also used : HashMap(java.util.HashMap) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) JdbcDataSourceStat(com.alibaba.druid.stat.JdbcDataSourceStat)

Example 17 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project druid by alibaba.

the class JdbcStatManager method getSqlList.

@Override
public TabularData getSqlList() throws JMException {
    CompositeType rowType = JdbcSqlStat.getCompositeType();
    String[] indexNames = rowType.keySet().toArray(new String[rowType.keySet().size()]);
    TabularType tabularType = new TabularType("SqlListStatistic", "SqlListStatistic", rowType, indexNames);
    TabularData data = new TabularDataSupport(tabularType);
    JdbcDataSourceStat globalStat = JdbcDataSourceStat.getGlobal();
    if (globalStat != null) {
        Map<String, JdbcSqlStat> statMap = globalStat.getSqlStatMap();
        for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
            if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
                continue;
            }
            Map<String, Object> map = entry.getValue().getData();
            map.put("URL", globalStat.getUrl());
            data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
        }
    }
    for (DataSourceProxyImpl dataSource : DruidDriver.getProxyDataSources().values()) {
        JdbcDataSourceStat druidDataSourceStat = dataSource.getDataSourceStat();
        if (druidDataSourceStat == globalStat) {
            continue;
        }
        Map<String, JdbcSqlStat> statMap = druidDataSourceStat.getSqlStatMap();
        for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
            if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
                continue;
            }
            Map<String, Object> map = entry.getValue().getData();
            map.put("URL", dataSource.getUrl());
            data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
        }
    }
    for (DruidDataSource dataSource : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
        JdbcDataSourceStat druidDataSourceStat = dataSource.getDataSourceStat();
        if (druidDataSourceStat == globalStat) {
            continue;
        }
        Map<String, JdbcSqlStat> statMap = druidDataSourceStat.getSqlStatMap();
        for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
            if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
                continue;
            }
            Map<String, Object> map = entry.getValue().getData();
            map.put("URL", dataSource.getUrl());
            data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
        }
    }
    return data;
}
Also used : DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) TabularType(javax.management.openmbean.TabularType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) TabularData(javax.management.openmbean.TabularData) TabularDataSupport(javax.management.openmbean.TabularDataSupport) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) CompositeType(javax.management.openmbean.CompositeType)

Example 18 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project jmxtrans by jmxtrans.

the class JmxResultProcessor method getResult.

/**
	 * Populates the Result objects. This is a recursive function. Query
	 * contains the keys that we want to get the values of.
	 */
private void getResult(Builder<Result> accumulator, String attributeName, CompositeData cds) {
    CompositeType t = cds.getCompositeType();
    Map<String, Object> values = newHashMap();
    Set<String> keys = t.keySet();
    for (String key : keys) {
        Object value = cds.get(key);
        if (value instanceof TabularDataSupport) {
            TabularDataSupport tds = (TabularDataSupport) value;
            processTabularDataSupport(accumulator, attributeName + "." + key, tds);
        // continue because we added tabular contents within above, but need primitives at this level
        } else if (value instanceof CompositeDataSupport) {
            // now recursively go through everything.
            CompositeDataSupport cds2 = (CompositeDataSupport) value;
            getResult(accumulator, attributeName, cds2);
            // because we don't want to add to the list yet.
            return;
        } else {
            values.put(key, value);
        }
    }
    Result r = getNewResultObject(attributeName, values);
    accumulator.add(r);
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Example 19 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project nhin-d by DirectProject.

the class DNSServer method registerMBean.

/**
	 * Register the MBean
	 */
private void registerMBean(DNSServerSettings settings) {
    String[] itemNames = { "Port", "Bind Address", "Max Request Size", "Max Outstanding Accepts", "Max Active Accepts", "Max Connection Backlog", "Read Buffer Size", "Send Timeout", "Receive Timeout", "Socket Close Timeout" };
    String[] itemDesc = { "Port", "Bind Address", "Max Request Size", "Max Outstanding Accepts", "Max Active Accepts", "Max Connection Backlog", "Read Buffer Size", "Send Timeout", "Receive Timeout", "Socket Close Timeout" };
    OpenType<?>[] types = { SimpleType.INTEGER, SimpleType.STRING, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER };
    Object[] settingsValues = { settings.getPort(), settings.getBindAddress(), settings.getMaxRequestSize(), settings.getMaxOutstandingAccepts(), settings.getMaxActiveRequests(), settings.getMaxConnectionBacklog(), settings.getReadBufferSize(), settings.getSendTimeout(), settings.getReceiveTimeout(), settings.getSocketCloseTimeout() };
    try {
        CompositeType settingsType = new CompositeType(DNSServerSettings.class.getSimpleName(), "DNS server settings.", itemNames, itemDesc, types);
        settingsData = new CompositeDataSupport(settingsType, itemNames, settingsValues);
    } catch (OpenDataException e) {
        LOGGER.error("Failed to create settings composite type: " + e.getLocalizedMessage(), e);
        return;
    }
    Class<?> clazz = this.getClass();
    final StringBuilder objectNameBuilder = new StringBuilder(clazz.getPackage().getName());
    objectNameBuilder.append(":type=").append(clazz.getSimpleName());
    objectNameBuilder.append(",name=").append(UUID.randomUUID());
    try {
        final StandardMBean mbean = new StandardMBean(this, DNSServerMBean.class);
        final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        mbeanServer.registerMBean(mbean, new ObjectName(objectNameBuilder.toString()));
    } catch (JMException e) {
        LOGGER.error("Unable to register the DNSServer MBean", e);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) StandardMBean(javax.management.StandardMBean) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) ObjectName(javax.management.ObjectName) OpenDataException(javax.management.openmbean.OpenDataException) JMException(javax.management.JMException) CompositeType(javax.management.openmbean.CompositeType) MBeanServer(javax.management.MBeanServer)

Example 20 with CompositeDataSupport

use of javax.management.openmbean.CompositeDataSupport in project jdk8u_jdk by JetBrains.

the class CompositeDataStringTest method main.

public static void main(String[] args) throws Exception {
    CompositeType basicCT = new CompositeType("basicCT", "basic CompositeType", new String[] { "name", "value" }, new String[] { "name", "value" }, new OpenType<?>[] { SimpleType.STRING, SimpleType.INTEGER });
    CompositeType ct = new CompositeType("noddy", "descr", new String[] { "strings", "ints", "cds" }, new String[] { "string array", "int array", "composite data array" }, new OpenType<?>[] { ArrayType.getArrayType(SimpleType.STRING), ArrayType.getPrimitiveArrayType(int[].class), ArrayType.getArrayType(basicCT) });
    CompositeData basicCD1 = new CompositeDataSupport(basicCT, new String[] { "name", "value" }, new Object[] { "ceathar", 4 });
    CompositeData basicCD2 = new CompositeDataSupport(basicCT, new String[] { "name", "value" }, new Object[] { "naoi", 9 });
    CompositeData cd = new CompositeDataSupport(ct, new String[] { "strings", "ints", "cds" }, new Object[] { new String[] { "fred", "jim", "sheila" }, new int[] { 2, 3, 5, 7 }, new CompositeData[] { basicCD1, basicCD2 } });
    String s = cd.toString();
    System.out.println("CompositeDataSupport.toString(): " + s);
    String[] expected = { "fred, jim, sheila", "2, 3, 5, 7", "ceathar", "naoi" };
    boolean ok = true;
    for (String expect : expected) {
        if (s.contains(expect))
            System.out.println("OK: string contains <" + expect + ">");
        else {
            ok = false;
            System.out.println("NOT OK: string does not contain <" + expect + ">");
        }
    }
    if (ok)
        System.out.println("TEST PASSED");
    else
        throw new Exception("TEST FAILED: string did not contain expected substrings");
}
Also used : CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)92 CompositeData (javax.management.openmbean.CompositeData)68 TabularDataSupport (javax.management.openmbean.TabularDataSupport)60 CompositeType (javax.management.openmbean.CompositeType)55 TabularData (javax.management.openmbean.TabularData)43 OpenDataException (javax.management.openmbean.OpenDataException)25 HashMap (java.util.HashMap)21 Map (java.util.Map)19 TabularType (javax.management.openmbean.TabularType)19 OpenType (javax.management.openmbean.OpenType)10 Test (org.junit.Test)8 ObjectName (javax.management.ObjectName)7 EndpointUtilizationStatistics (org.apache.camel.spi.EndpointUtilizationStatistics)7 MBeanServer (javax.management.MBeanServer)6 IOException (java.io.IOException)5 MBeanException (javax.management.MBeanException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ArrayList (java.util.ArrayList)3 MBeanInfo (javax.management.MBeanInfo)3 Bundle (org.osgi.framework.Bundle)3