Search in sources :

Example 1 with Counting

use of com.codahale.metrics.Counting in project jackrabbit-oak by apache.

the class BenchmarkRunner method reportMetrics.

private static void reportMetrics(StatisticsProvider statsProvider) {
    if (statsProvider instanceof MetricStatisticsProvider) {
        MetricRegistry metricRegistry = ((MetricStatisticsProvider) statsProvider).getRegistry();
        ConsoleReporter.forRegistry(metricRegistry).outputTo(System.out).filter(new MetricFilter() {

            @Override
            public boolean matches(String name, Metric metric) {
                if (metric instanceof Counting) {
                    // Only report non zero metrics
                    return ((Counting) metric).getCount() > 0;
                }
                return true;
            }
        }).build().report();
    }
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) MetricRegistry(com.codahale.metrics.MetricRegistry) MetricStatisticsProvider(org.apache.jackrabbit.oak.plugins.metric.MetricStatisticsProvider) Metric(com.codahale.metrics.Metric) Counting(com.codahale.metrics.Counting)

Example 2 with Counting

use of com.codahale.metrics.Counting in project jackrabbit-oak by apache.

the class NodeStoreFixtureProvider method reportMetrics.

private static void reportMetrics(MetricStatisticsProvider statsProvider) {
    MetricRegistry metricRegistry = statsProvider.getRegistry();
    ConsoleReporter.forRegistry(metricRegistry).outputTo(System.out).filter((name, metric) -> {
        if (metric instanceof Counting) {
            // Only report non zero metrics
            return ((Counting) metric).getCount() > 0;
        }
        return true;
    }).build().report();
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Counting(com.codahale.metrics.Counting)

Example 3 with Counting

use of com.codahale.metrics.Counting 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 4 with Counting

use of com.codahale.metrics.Counting in project graylog2-server by Graylog2.

the class ThroughputCalculator method doRun.

@Override
public void doRun() {
    final SortedMap<String, ? extends Counting> counters = metricRegistry.getCounters(filterSingleMetric(GlobalMetricNames.OUTPUT_THROUGHPUT));
    // rinse and repeat for input throughput
    final SortedMap<String, ? extends Counting> inputCounters = metricRegistry.getCounters(filterSingleMetric(GlobalMetricNames.INPUT_THROUGHPUT));
    // StreamMetrics isn't accessible here, so we need to use a metrics filter instead.
    final SortedMap<String, ? extends Counting> streamMeters = metricRegistry.getMeters(streamMetricFilter);
    final Iterable<Map.Entry<String, ? extends Counting>> entries = Iterables.concat(counters.entrySet(), inputCounters.entrySet(), streamMeters.entrySet());
    // calculate rates
    for (Map.Entry<String, ? extends Counting> countingEntry : entries) {
        final Counting value = countingEntry.getValue();
        final String metricName = countingEntry.getKey();
        CounterSample counterSample = sampledCounters.get(metricName);
        if (counterSample == null) {
            counterSample = new CounterSample();
            sampledCounters.put(metricName, counterSample);
        }
        counterSample.updateAverage(value.getCount());
        final String rateName = name(metricName, GlobalMetricNames.RATE_SUFFIX);
        if (!metricRegistry.getMetrics().containsKey(rateName)) {
            try {
                log.debug("Registering derived, per-second metric {}", rateName);
                metricRegistry.register(rateName, new Gauge<Double>() {

                    @Override
                    public Double getValue() {
                        final CounterSample sample = sampledCounters.get(metricName);
                        return sample == null ? 0d : sample.getCurrentAverage();
                    }
                });
            } catch (IllegalArgumentException e) {
                log.warn("Could not register gauge {} despite checking before that it didn't exist. This should not happen.", rateName);
            }
        }
    }
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Counting(com.codahale.metrics.Counting)

Example 5 with Counting

use of com.codahale.metrics.Counting 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)5 Metered (com.codahale.metrics.Metered)2 Metric (com.codahale.metrics.Metric)2 MetricRegistry (com.codahale.metrics.MetricRegistry)2 Sampling (com.codahale.metrics.Sampling)2 Gauge (com.codahale.metrics.Gauge)1 MetricFilter (com.codahale.metrics.MetricFilter)1 TemplateCall (com.peterphi.std.guice.web.rest.templating.TemplateCall)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Keyspace (org.apache.cassandra.db.Keyspace)1 TableMetadata (org.apache.cassandra.schema.TableMetadata)1 MetricStatisticsProvider (org.apache.jackrabbit.oak.plugins.metric.MetricStatisticsProvider)1