Search in sources :

Example 1 with Metered

use of com.codahale.metrics.Metered in project cassandra by apache.

the class TableMetricTables method buildMetadata.

/**
 *  Identify the type of Metric it is (gauge, counter etc) abd create the TableMetadata. The column name
 *  and type for a counter/gauge is formatted differently based on the units (bytes/time) so allowed to
 *  be set.
 */
private static TableMetadata buildMetadata(String keyspace, String table, Function<TableMetrics, ? extends Metric> func, String colName, AbstractType colType, String suffix) {
    TableMetadata.Builder metadata = TableMetadata.builder(keyspace, table).kind(TableMetadata.Kind.VIRTUAL).addPartitionKeyColumn(KEYSPACE_NAME, UTF8Type.instance).addPartitionKeyColumn(TABLE_NAME, UTF8Type.instance).partitioner(PARTITIONER);
    // get a table from system keyspace and get metric from it for determining type of metric
    Keyspace system = Keyspace.system().iterator().next();
    Metric test = func.apply(system.getColumnFamilyStores().iterator().next().metric);
    if (test instanceof Counting) {
        metadata.addRegularColumn(colName, colType);
        // if it has a Histogram include some information about distribution
        if (test instanceof Sampling) {
            metadata.addRegularColumn(P50 + suffix, DoubleType.instance).addRegularColumn(P99 + suffix, DoubleType.instance).addRegularColumn(MAX + suffix, DoubleType.instance);
        }
        if (test instanceof Metered) {
            metadata.addRegularColumn(RATE, DoubleType.instance);
        }
    } else if (test instanceof Gauge) {
        metadata.addRegularColumn(colName, colType);
    }
    return metadata.build();
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) Metered(com.codahale.metrics.Metered) Keyspace(org.apache.cassandra.db.Keyspace) Metric(com.codahale.metrics.Metric) Sampling(com.codahale.metrics.Sampling) Counting(com.codahale.metrics.Counting) Gauge(com.codahale.metrics.Gauge)

Example 2 with Metered

use of com.codahale.metrics.Metered in project stdlib by petergeneric.

the class MetricsRestServiceImpl method getIndex.

@Override
public String getIndex() {
    TemplateCall call = templater.template(PREFIX + "index.html");
    call.set("gauges", registry.getGauges().entrySet());
    call.set("counters", this.<Counting>combine(registry.getCounters(), registry.getMeters(), registry.getTimers(), registry.getHistograms()).entrySet());
    call.set("meters", this.<Metered>combine(registry.getMeters(), registry.getTimers()).entrySet());
    call.set("histograms", this.<Sampling>combine(registry.getHistograms(), registry.getTimers()).entrySet());
    return call.process();
}
Also used : Metered(com.codahale.metrics.Metered) Sampling(com.codahale.metrics.Sampling) Counting(com.codahale.metrics.Counting) TemplateCall(com.peterphi.std.guice.web.rest.templating.TemplateCall)

Aggregations

Counting (com.codahale.metrics.Counting)2 Metered (com.codahale.metrics.Metered)2 Sampling (com.codahale.metrics.Sampling)2 Gauge (com.codahale.metrics.Gauge)1 Metric (com.codahale.metrics.Metric)1 TemplateCall (com.peterphi.std.guice.web.rest.templating.TemplateCall)1 Keyspace (org.apache.cassandra.db.Keyspace)1 TableMetadata (org.apache.cassandra.schema.TableMetadata)1