Example usage for org.apache.cassandra.utils EstimatedHistogram EstimatedHistogram

List of usage examples for org.apache.cassandra.utils EstimatedHistogram EstimatedHistogram

Introduction

In this page you can find the example usage for org.apache.cassandra.utils EstimatedHistogram EstimatedHistogram.

Prototype

public EstimatedHistogram() 

Source Link

Usage

From source file:c3.ops.priam.resources.CassandraAdmin.java

License:Apache License

@GET
@Path("/cfhistograms")
public Response cfhistograms(@QueryParam(REST_HEADER_KEYSPACES) String keyspace,
        @QueryParam(REST_HEADER_CFS) String cfname)
        throws IOException, ExecutionException, InterruptedException, JSONException {
    JMXNodeTool nodetool = null;/*from ww w .j ava 2s  .c  om*/
    try {
        nodetool = JMXNodeTool.instance(config);
    } catch (JMXConnectionException e) {
        return Response.status(503).entity("JMXConnectionException").build();
    }
    if (StringUtils.isBlank(keyspace) || StringUtils.isBlank(cfname))
        return Response.status(400).entity("Missing keyspace/cfname in request").build();

    ColumnFamilyStoreMBean store = nodetool.getCfsProxy(keyspace, cfname);

    // default is 90 offsets
    long[] offsets = new EstimatedHistogram().getBucketOffsets();

    long[] rrlh = store.getRecentReadLatencyHistogramMicros();
    long[] rwlh = store.getRecentWriteLatencyHistogramMicros();
    long[] sprh = store.getRecentSSTablesPerReadHistogram();
    long[] ersh = store.getEstimatedRowSizeHistogram();
    long[] ecch = store.getEstimatedColumnCountHistogram();

    JSONObject rootObj = new JSONObject();
    JSONArray columns = new JSONArray();
    columns.put("offset");
    columns.put("sstables");
    columns.put("write latency");
    columns.put("read latency");
    columns.put("row size");
    columns.put("column count");
    rootObj.put("columns", columns);
    JSONArray values = new JSONArray();
    for (int i = 0; i < offsets.length; i++) {
        JSONArray row = new JSONArray();
        row.put(offsets[i]);
        row.put(i < sprh.length ? sprh[i] : "");
        row.put(i < rwlh.length ? rwlh[i] : "");
        row.put(i < rrlh.length ? rrlh[i] : "");
        row.put(i < ersh.length ? ersh[i] : "");
        row.put(i < ecch.length ? ecch[i] : "");
        values.put(row);
    }
    rootObj.put("values", values);
    return Response.ok(rootObj, MediaType.APPLICATION_JSON).build();
}

From source file:com.netflix.priam.resources.CassandraAdminResource.java

License:Apache License

@GET
@Path("/cfhistograms")
public Response cfhistograms(@QueryParam("keyspace") String keyspace, @QueryParam("cfname") String cfname)
        throws Exception {
    JMXNodeTool nodetool = getNodeTool();
    if (StringUtils.isBlank(keyspace) || StringUtils.isBlank(cfname)) {
        return Response.status(400).entity("Missing keyspace/cfname in request").build();
    }// w  ww  . j  a v a2  s . co  m

    // default is 90 offsets
    long[] offsets = new EstimatedHistogram().getBucketOffsets();

    Object readLatency = nodetool.getColumnFamilyMetric(keyspace, cfname, "ReadLatency");
    Object writeLatency = nodetool.getColumnFamilyMetric(keyspace, cfname, "WriteLatency");
    Object ssTablesPerReadHist = nodetool.getColumnFamilyMetric(keyspace, cfname, "SSTablesPerReadHistogram");
    Object estimatedRowSizeHist = nodetool.getColumnFamilyMetric(keyspace, cfname, "EstimatedRowSizeHistogram");
    Object estimatedColumnCountHist = nodetool.getColumnFamilyMetric(keyspace, cfname,
            "EstimatedColumnCountHistogram");

    Map<String, Object> rootObj = Maps.newLinkedHashMap();
    List<String> columns = ImmutableList.of("offset", "sstables", "write latency", "read latency", "row size",
            "column count");
    rootObj.put("columns", columns);
    List<Object> values = Lists.newArrayList();
    for (int i = 0; i < offsets.length; i++) {
        List<Object> row = Lists.newArrayList();
        row.add(offsets[i]);
        row.add(readLatency);
        row.add(writeLatency);
        row.add(ssTablesPerReadHist);
        row.add(estimatedRowSizeHist);
        row.add(estimatedColumnCountHist);
        values.add(row);
    }
    rootObj.put("values", values);
    return Response.ok(rootObj, MediaType.APPLICATION_JSON).build();
}

From source file:org.wso2.carbon.cassandra.cluster.mgt.query.ClusterMBeanServiceHandler.java

License:Open Source License

public ColumnFamilyHistograms[] getCfHistograms(String keySpace, String columnFamily)
        throws ClusterDataAdminException {
    clusterColumnFamilyMBeanService = ClusterMBeanProxy.getClusterColumnFamilyMBeanService(keySpace,
            columnFamily);/*from w  w  w .  j  a  v  a  2s. c om*/

    // default is 90 offsets
    long[] offsets = new EstimatedHistogram().getBucketOffsets();

    long[] rrlh = clusterColumnFamilyMBeanService.getRecentReadLatencyHistogramMicros();
    long[] rwlh = clusterColumnFamilyMBeanService.getRecentWriteLatencyHistogramMicros();
    long[] sprh = clusterColumnFamilyMBeanService.getRecentSSTablesPerReadHistogram();
    long[] ersh = clusterColumnFamilyMBeanService.getEstimatedRowSizeHistogram();
    long[] ecch = clusterColumnFamilyMBeanService.getEstimatedColumnCountHistogram();
    ColumnFamilyHistograms[] columnFamilyHistograms = new ColumnFamilyHistograms[offsets.length];
    for (int i = 0; i < offsets.length; i++) {
        ColumnFamilyHistograms columnFamilyHistogram = new ColumnFamilyHistograms();
        columnFamilyHistogram.setOffset(offsets[i]);
        if (i < sprh.length)
            columnFamilyHistogram.setSSTables(sprh[i]);
        else
            columnFamilyHistogram.setSSTables(-1);

        if (i < rwlh.length)
            columnFamilyHistogram.setWriteLatency(rwlh[i]);
        else
            columnFamilyHistogram.setWriteLatency(-1);

        if (i < rrlh.length)
            columnFamilyHistogram.setReadLatency(rrlh[i]);
        else
            columnFamilyHistogram.setReadLatency(-1);

        if (i < ersh.length)
            columnFamilyHistogram.setRowSize(ersh[i]);
        else
            columnFamilyHistogram.setRowSize(-1);

        if (i < ecch.length)
            columnFamilyHistogram.setColumnCount(ecch[i]);
        else
            columnFamilyHistogram.setColumnCount(-1);
        columnFamilyHistograms[i] = columnFamilyHistogram;
    }
    return columnFamilyHistograms;
}