Search in sources :

Example 1 with Sampler

use of org.apache.cassandra.metrics.TableMetrics.Sampler 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 2 with Sampler

use of org.apache.cassandra.metrics.TableMetrics.Sampler 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)

Aggregations

CompositeData (javax.management.openmbean.CompositeData)2 Sampler (org.apache.cassandra.metrics.TableMetrics.Sampler)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 OpenDataException (javax.management.openmbean.OpenDataException)1 ColumnFamilyStoreMBean (org.apache.cassandra.db.ColumnFamilyStoreMBean)1 StreamStateCompositeData (org.apache.cassandra.streaming.management.StreamStateCompositeData)1