Search in sources :

Example 21 with CompositeData

use of javax.management.openmbean.CompositeData in project neo4j by neo4j.

the class Dbinfo method printAttribute.

private void printAttribute(JSONObject json, Object value) throws RemoteException, ShellException {
    try {
        Attribute attribute = (Attribute) value;
        Object attributeValue = attribute.getValue();
        if (attributeValue != null && attributeValue.getClass().isArray()) {
            Object[] arrayValue = (Object[]) attributeValue;
            JSONArray array = new JSONArray();
            for (Object item : (Object[]) arrayValue) {
                if (item instanceof CompositeData) {
                    array.put(compositeDataAsMap((CompositeData) item));
                } else {
                    array.put(item.toString());
                }
            }
            json.put(attribute.getName(), array);
        } else {
            json.put(attribute.getName(), attributeValue);
        }
    } catch (JSONException e) {
        throw ShellException.wrapCause(e);
    }
}
Also used : Attribute(javax.management.Attribute) CompositeData(javax.management.openmbean.CompositeData) JSONArray(org.neo4j.shell.util.json.JSONArray) JSONException(org.neo4j.shell.util.json.JSONException) JSONObject(org.neo4j.shell.util.json.JSONObject)

Example 22 with CompositeData

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

the class ColumnFamilyStoreMBeanIterator method getPartitionSample.

public Map<Sampler, CompositeData> getPartitionSample(String ks, String cf, int capacity, int duration, int count, List<Sampler> samplers) throws OpenDataException {
    ColumnFamilyStoreMBean cfsProxy = getCfsProxy(ks, cf);
    for (Sampler sampler : samplers) {
        cfsProxy.beginLocalSampling(sampler.name(), capacity);
    }
    Uninterruptibles.sleepUninterruptibly(duration, TimeUnit.MILLISECONDS);
    Map<Sampler, CompositeData> result = Maps.newHashMap();
    for (Sampler sampler : samplers) {
        result.put(sampler, cfsProxy.finishLocalSampling(sampler.name(), count));
    }
    return result;
}
Also used : Sampler(org.apache.cassandra.metrics.TableMetrics.Sampler) CompositeData(javax.management.openmbean.CompositeData) StreamStateCompositeData(org.apache.cassandra.streaming.management.StreamStateCompositeData) ColumnFamilyStoreMBean(org.apache.cassandra.db.ColumnFamilyStoreMBean)

Example 23 with CompositeData

use of javax.management.openmbean.CompositeData 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 24 with CompositeData

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

the class TopPartitions method execute.

@Override
public void execute(NodeProbe probe) {
    checkArgument(args.size() == 3, "toppartitions requires keyspace, column family name, and duration");
    checkArgument(topCount < size, "TopK count (-k) option must be smaller then the summary capacity (-s)");
    String keyspace = args.get(0);
    String cfname = args.get(1);
    Integer duration = Integer.valueOf(args.get(2));
    // generate the list of samplers
    List<Sampler> targets = Lists.newArrayList();
    for (String s : samplers.split(",")) {
        try {
            targets.add(Sampler.valueOf(s.toUpperCase()));
        } catch (Exception e) {
            throw new IllegalArgumentException(s + " is not a valid sampler, choose one of: " + join(Sampler.values(), ", "));
        }
    }
    Map<Sampler, CompositeData> results;
    try {
        results = probe.getPartitionSample(keyspace, cfname, size, duration, topCount, targets);
    } catch (OpenDataException e) {
        throw new RuntimeException(e);
    }
    boolean first = true;
    for (Entry<Sampler, CompositeData> result : results.entrySet()) {
        CompositeData sampling = result.getValue();
        // weird casting for http://bugs.sun.com/view_bug.do?bug_id=6548436
        List<CompositeData> topk = (List<CompositeData>) (Object) Lists.newArrayList(((TabularDataSupport) sampling.get("partitions")).values());
        Collections.sort(topk, new Ordering<CompositeData>() {

            public int compare(CompositeData left, CompositeData right) {
                return Long.compare((long) right.get("count"), (long) left.get("count"));
            }
        });
        if (!first)
            System.out.println();
        System.out.println(result.getKey().toString() + " Sampler:");
        System.out.printf("  Cardinality: ~%d (%d capacity)%n", sampling.get("cardinality"), size);
        System.out.printf("  Top %d partitions:%n", topCount);
        if (topk.size() == 0) {
            System.out.println("\tNothing recorded during sampling period...");
        } else {
            int offset = 0;
            for (CompositeData entry : topk) offset = Math.max(offset, entry.get("string").toString().length());
            System.out.printf("\t%-" + offset + "s%10s%10s%n", "Partition", "Count", "+/-");
            for (CompositeData entry : topk) System.out.printf("\t%-" + offset + "s%10d%10d%n", entry.get("string").toString(), entry.get("count"), entry.get("error"));
        }
        first = false;
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) OpenDataException(javax.management.openmbean.OpenDataException) OpenDataException(javax.management.openmbean.OpenDataException) Sampler(org.apache.cassandra.metrics.TableMetrics.Sampler) ArrayList(java.util.ArrayList) List(java.util.List)

Example 25 with CompositeData

use of javax.management.openmbean.CompositeData 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

CompositeData (javax.management.openmbean.CompositeData)229 TabularData (javax.management.openmbean.TabularData)91 Test (org.junit.Test)73 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)68 TabularDataSupport (javax.management.openmbean.TabularDataSupport)51 CompositeType (javax.management.openmbean.CompositeType)50 HashMap (java.util.HashMap)31 ArrayList (java.util.ArrayList)27 Map (java.util.Map)27 Bundle (org.osgi.framework.Bundle)24 ObjectName (javax.management.ObjectName)21 OpenDataException (javax.management.openmbean.OpenDataException)18 IOException (java.io.IOException)17 Collection (java.util.Collection)16 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)16 AuditEvent (org.nhindirect.common.audit.AuditEvent)15 TabularType (javax.management.openmbean.TabularType)13 MBeanServer (javax.management.MBeanServer)12 DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)11 MBeanException (javax.management.MBeanException)8