Search in sources :

Example 41 with TabularData

use of javax.management.openmbean.TabularData in project hibernate-orm by hibernate.

the class HibernateStatsImpl method getCacheRegionStats.

@Override
public TabularData getCacheRegionStats() {
    final List<CompositeData> list = new ArrayList<CompositeData>();
    final Statistics statistics = getStatistics();
    for (String region : statistics.getSecondLevelCacheRegionNames()) {
        final CacheRegionStats l2CacheStats = new CacheRegionStats(region, statistics.getSecondLevelCacheStatistics(region));
        list.add(l2CacheStats.toCompositeData());
    }
    final TabularData td = CacheRegionStats.newTabularDataInstance();
    td.putAll(list.toArray(new CompositeData[list.size()]));
    return td;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) Statistics(org.hibernate.stat.Statistics) TabularData(javax.management.openmbean.TabularData)

Example 42 with TabularData

use of javax.management.openmbean.TabularData in project cassandra by apache.

the class FailureDetectorInfo method execute.

@Override
public void execute(NodeProbe probe) {
    TabularData data = probe.getFailureDetectorPhilValues();
    System.out.printf("%10s,%16s%n", "Endpoint", "Phi");
    for (Object o : data.keySet()) {
        @SuppressWarnings({ "rawtypes", "unchecked" }) CompositeData datum = data.get(((List) o).toArray(new Object[((List) o).size()]));
        System.out.printf("%10s,%16.8f%n", datum.get("Endpoint"), datum.get("PHI"));
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) List(java.util.List) TabularData(javax.management.openmbean.TabularData)

Example 43 with TabularData

use of javax.management.openmbean.TabularData in project cassandra by apache.

the class ListSnapshots method execute.

@Override
public void execute(NodeProbe probe) {
    try {
        System.out.println("Snapshot Details: ");
        final Map<String, TabularData> snapshotDetails = probe.getSnapshotDetails();
        if (snapshotDetails.isEmpty()) {
            System.out.printf("There are no snapshots");
            return;
        }
        final long trueSnapshotsSize = probe.trueSnapshotsSize();
        TableBuilder table = new TableBuilder();
        // display column names only once
        final List<String> indexNames = snapshotDetails.entrySet().iterator().next().getValue().getTabularType().getIndexNames();
        table.add(indexNames.toArray(new String[indexNames.size()]));
        for (final Map.Entry<String, TabularData> snapshotDetail : snapshotDetails.entrySet()) {
            Set<?> values = snapshotDetail.getValue().keySet();
            for (Object eachValue : values) {
                final List<?> value = (List<?>) eachValue;
                table.add(value.toArray(new String[value.size()]));
            }
        }
        table.printTo(System.out);
        System.out.println("\nTotal TrueDiskSpaceUsed: " + FileUtils.stringifyFileSize(trueSnapshotsSize) + "\n");
    } catch (Exception e) {
        throw new RuntimeException("Error during list snapshot", e);
    }
}
Also used : TableBuilder(org.apache.cassandra.tools.nodetool.formatter.TableBuilder) TabularData(javax.management.openmbean.TabularData) List(java.util.List) Map(java.util.Map)

Example 44 with TabularData

use of javax.management.openmbean.TabularData in project cassandra by apache.

the class CompactionHistoryHolder method convert2Map.

@Override
public Map<String, Object> convert2Map() {
    HashMap<String, Object> result = new HashMap<>();
    ArrayList<Map<String, Object>> compactions = new ArrayList<>();
    TabularData tabularData = probe.getCompactionHistory();
    this.indexNames = tabularData.getTabularType().getIndexNames();
    if (tabularData.isEmpty())
        return result;
    List<CompactionHistoryHolder.CompactionHistoryRow> chrList = new ArrayList<>();
    Set<?> values = tabularData.keySet();
    for (Object eachValue : values) {
        List<?> value = (List<?>) eachValue;
        CompactionHistoryHolder.CompactionHistoryRow chr = new CompactionHistoryHolder.CompactionHistoryRow((String) value.get(0), (String) value.get(1), (String) value.get(2), (Long) value.get(3), (Long) value.get(4), (Long) value.get(5), (String) value.get(6));
        chrList.add(chr);
    }
    Collections.sort(chrList);
    for (CompactionHistoryHolder.CompactionHistoryRow chr : chrList) {
        compactions.add(chr.getAllAsMap());
    }
    result.put("CompactionHistory", compactions);
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TabularData(javax.management.openmbean.TabularData) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 45 with TabularData

use of javax.management.openmbean.TabularData in project twitter4j by yusuke.

the class MBeansTest method testAPIStatisticsOpenMBean.

/**
     * Tests exposure of API statistics via a dynamic MBean
     */
public void testAPIStatisticsOpenMBean() throws Exception {
    APIStatistics stats = new APIStatistics(5);
    APIStatisticsOpenMBean openMBean = new APIStatisticsOpenMBean(stats);
    // sanity check to ensure metadata accurately describes dynamic attributes
    MBeanInfo info = openMBean.getMBeanInfo();
    assertEquals(5, info.getAttributes().length);
    assertEquals(1, info.getOperations().length);
    List<String> attrNames = new ArrayList<String>();
    for (MBeanAttributeInfo attr : info.getAttributes()) {
        assertNotNull(openMBean.getAttribute(attr.getName()));
        attrNames.add(attr.getName());
    }
    AttributeList attrList = openMBean.getAttributes(attrNames.toArray(new String[attrNames.size()]));
    assertNotNull(attrList);
    assertEquals(5, attrList.size());
    // check stats (empty case)
    Long callCount = (Long) openMBean.getAttribute("callCount");
    assertEquals(0, callCount.longValue());
    Long errorCount = (Long) openMBean.getAttribute("errorCount");
    assertEquals(0, callCount.longValue());
    Long totalTime = (Long) openMBean.getAttribute("totalTime");
    assertEquals(0, totalTime.longValue());
    Long averageTime = (Long) openMBean.getAttribute("averageTime");
    assertEquals(0, averageTime.longValue());
    // check table (empty case)
    TabularData table = (TabularData) openMBean.getAttribute("statisticsTable");
    assertTrue(table.isEmpty());
    stats.methodCalled("foo", 100, true);
    // check stats (populated case)
    callCount = (Long) openMBean.getAttribute("callCount");
    assertEquals(1, callCount.longValue());
    errorCount = (Long) openMBean.getAttribute("errorCount");
    assertEquals(0, errorCount.longValue());
    totalTime = (Long) openMBean.getAttribute("totalTime");
    assertEquals(100, totalTime.longValue());
    averageTime = (Long) openMBean.getAttribute("averageTime");
    assertEquals(100, averageTime.longValue());
    // check table (populated  case)
    table = (TabularData) openMBean.getAttribute("statisticsTable");
    assertFalse(table.isEmpty());
    assertEquals(1, table.keySet().size());
    CompositeData data = table.get(new Object[] { "foo" });
    assertNotNull(data);
    String[] columnNames = new String[] { "methodName", "callCount", "totalTime", "avgTime" };
    Object[] columnValues = data.getAll(columnNames);
    assertEquals(columnNames.length, columnValues.length);
    assertEquals("foo", columnValues[0]);
    assertEquals(1, ((Long) columnValues[1]).longValue());
    assertEquals(100, ((Long) columnValues[2]).longValue());
    assertEquals(100, ((Long) columnValues[3]).longValue());
    // check reset
    openMBean.invoke("reset", new Object[0], new String[0]);
    checkCalculator(stats, 0, 0, 0, 0);
    assertFalse(stats.getInvocationStatistics().iterator().hasNext());
}
Also used : MBeanInfo(javax.management.MBeanInfo) AttributeList(javax.management.AttributeList) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) TabularData(javax.management.openmbean.TabularData)

Aggregations

TabularData (javax.management.openmbean.TabularData)183 CompositeData (javax.management.openmbean.CompositeData)91 TabularDataSupport (javax.management.openmbean.TabularDataSupport)67 ObjectName (javax.management.ObjectName)54 MBeanServer (javax.management.MBeanServer)50 CompositeType (javax.management.openmbean.CompositeType)47 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)43 Test (org.junit.Test)38 Map (java.util.Map)28 ArrayList (java.util.ArrayList)23 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)21 HashMap (java.util.HashMap)20 TabularType (javax.management.openmbean.TabularType)17 Bundle (org.osgi.framework.Bundle)17 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)15 Collection (java.util.Collection)13 IOException (java.io.IOException)11 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)9 List (java.util.List)8 ServiceReference (org.osgi.framework.ServiceReference)8