Search in sources :

Example 1 with Counter

use of com.codahale.metrics.Counter in project hadoop by apache.

the class SLSCapacityScheduler method registerSchedulerMetrics.

private void registerSchedulerMetrics() {
    samplerLock.lock();
    try {
        // counters for scheduler operations
        schedulerAllocateCounter = metrics.counter("counter.scheduler.operation.allocate");
        schedulerHandleCounter = metrics.counter("counter.scheduler.operation.handle");
        schedulerHandleCounterMap = new HashMap<SchedulerEventType, Counter>();
        for (SchedulerEventType e : SchedulerEventType.values()) {
            Counter counter = metrics.counter("counter.scheduler.operation.handle." + e);
            schedulerHandleCounterMap.put(e, counter);
        }
        // timers for scheduler operations
        int timeWindowSize = conf.getInt(SLSConfiguration.METRICS_TIMER_WINDOW_SIZE, SLSConfiguration.METRICS_TIMER_WINDOW_SIZE_DEFAULT);
        schedulerAllocateTimer = new Timer(new SlidingWindowReservoir(timeWindowSize));
        schedulerHandleTimer = new Timer(new SlidingWindowReservoir(timeWindowSize));
        schedulerHandleTimerMap = new HashMap<SchedulerEventType, Timer>();
        for (SchedulerEventType e : SchedulerEventType.values()) {
            Timer timer = new Timer(new SlidingWindowReservoir(timeWindowSize));
            schedulerHandleTimerMap.put(e, timer);
        }
        // histogram for scheduler operations (Samplers)
        schedulerHistogramList = new ArrayList<Histogram>();
        histogramTimerMap = new HashMap<Histogram, Timer>();
        Histogram schedulerAllocateHistogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE));
        metrics.register("sampler.scheduler.operation.allocate.timecost", schedulerAllocateHistogram);
        schedulerHistogramList.add(schedulerAllocateHistogram);
        histogramTimerMap.put(schedulerAllocateHistogram, schedulerAllocateTimer);
        Histogram schedulerHandleHistogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE));
        metrics.register("sampler.scheduler.operation.handle.timecost", schedulerHandleHistogram);
        schedulerHistogramList.add(schedulerHandleHistogram);
        histogramTimerMap.put(schedulerHandleHistogram, schedulerHandleTimer);
        for (SchedulerEventType e : SchedulerEventType.values()) {
            Histogram histogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE));
            metrics.register("sampler.scheduler.operation.handle." + e + ".timecost", histogram);
            schedulerHistogramList.add(histogram);
            histogramTimerMap.put(histogram, schedulerHandleTimerMap.get(e));
        }
    } finally {
        samplerLock.unlock();
    }
}
Also used : SlidingWindowReservoir(com.codahale.metrics.SlidingWindowReservoir) Histogram(com.codahale.metrics.Histogram) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) SchedulerEventType(org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType)

Example 2 with Counter

use of com.codahale.metrics.Counter in project hadoop by apache.

the class ResourceSchedulerWrapper method registerSchedulerMetrics.

private void registerSchedulerMetrics() {
    samplerLock.lock();
    try {
        // counters for scheduler operations
        schedulerAllocateCounter = metrics.counter("counter.scheduler.operation.allocate");
        schedulerHandleCounter = metrics.counter("counter.scheduler.operation.handle");
        schedulerHandleCounterMap = new HashMap<SchedulerEventType, Counter>();
        for (SchedulerEventType e : SchedulerEventType.values()) {
            Counter counter = metrics.counter("counter.scheduler.operation.handle." + e);
            schedulerHandleCounterMap.put(e, counter);
        }
        // timers for scheduler operations
        int timeWindowSize = conf.getInt(SLSConfiguration.METRICS_TIMER_WINDOW_SIZE, SLSConfiguration.METRICS_TIMER_WINDOW_SIZE_DEFAULT);
        schedulerAllocateTimer = new Timer(new SlidingWindowReservoir(timeWindowSize));
        schedulerHandleTimer = new Timer(new SlidingWindowReservoir(timeWindowSize));
        schedulerHandleTimerMap = new HashMap<SchedulerEventType, Timer>();
        for (SchedulerEventType e : SchedulerEventType.values()) {
            Timer timer = new Timer(new SlidingWindowReservoir(timeWindowSize));
            schedulerHandleTimerMap.put(e, timer);
        }
        // histogram for scheduler operations (Samplers)
        schedulerHistogramList = new ArrayList<Histogram>();
        histogramTimerMap = new HashMap<Histogram, Timer>();
        Histogram schedulerAllocateHistogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE));
        metrics.register("sampler.scheduler.operation.allocate.timecost", schedulerAllocateHistogram);
        schedulerHistogramList.add(schedulerAllocateHistogram);
        histogramTimerMap.put(schedulerAllocateHistogram, schedulerAllocateTimer);
        Histogram schedulerHandleHistogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE));
        metrics.register("sampler.scheduler.operation.handle.timecost", schedulerHandleHistogram);
        schedulerHistogramList.add(schedulerHandleHistogram);
        histogramTimerMap.put(schedulerHandleHistogram, schedulerHandleTimer);
        for (SchedulerEventType e : SchedulerEventType.values()) {
            Histogram histogram = new Histogram(new SlidingWindowReservoir(SAMPLING_SIZE));
            metrics.register("sampler.scheduler.operation.handle." + e + ".timecost", histogram);
            schedulerHistogramList.add(histogram);
            histogramTimerMap.put(histogram, schedulerHandleTimerMap.get(e));
        }
    } finally {
        samplerLock.unlock();
    }
}
Also used : SlidingWindowReservoir(com.codahale.metrics.SlidingWindowReservoir) Histogram(com.codahale.metrics.Histogram) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) SchedulerEventType(org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEventType)

Example 3 with Counter

use of com.codahale.metrics.Counter in project hive by apache.

the class TestMetricsQueryLifeTimeHook method testCompilationQueryMetric.

@Test
public void testCompilationQueryMetric() {
    Timer timer = metricRegistry.getTimers().get(MetricsConstant.HS2_COMPILING_QUERIES);
    Counter counter = metricRegistry.getCounters().get(MetricsConstant.ACTIVE_CALLS + MetricsConstant.HS2_COMPILING_QUERIES);
    assertThat(timer, nullValue());
    assertThat(counter, nullValue());
    hook.beforeCompile(ctx);
    timer = metricRegistry.getTimers().get(MetricsConstant.HS2_COMPILING_QUERIES);
    counter = metricRegistry.getCounters().get(MetricsConstant.ACTIVE_CALLS + MetricsConstant.HS2_COMPILING_QUERIES);
    assertThat(timer.getCount(), equalTo(0l));
    assertThat(counter.getCount(), equalTo(1l));
    hook.afterCompile(ctx, false);
    timer = metricRegistry.getTimers().get(MetricsConstant.HS2_COMPILING_QUERIES);
    counter = metricRegistry.getCounters().get(MetricsConstant.ACTIVE_CALLS + MetricsConstant.HS2_COMPILING_QUERIES);
    assertThat(timer.getCount(), equalTo(1l));
    assertThat(counter.getCount(), equalTo(0l));
}
Also used : Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Test(org.junit.Test)

Example 4 with Counter

use of com.codahale.metrics.Counter in project newts by OpenNMS.

the class NewtsReporter method report.

@Override
@SuppressWarnings("rawtypes")
public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) {
    Timestamp timestamp = Timestamp.fromEpochMillis(clock.getTime());
    List<Sample> samples = Lists.newArrayList();
    for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
        reportGauge(samples, timestamp, entry.getKey(), entry.getValue());
    }
    for (Map.Entry<String, Counter> entry : counters.entrySet()) {
        reportCounter(samples, timestamp, entry.getKey(), entry.getValue());
    }
    for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
        reportHistogram(samples, timestamp, entry.getKey(), entry.getValue());
    }
    for (Map.Entry<String, Meter> entry : meters.entrySet()) {
        reportMeter(samples, timestamp, entry.getKey(), entry.getValue());
    }
    for (Map.Entry<String, Timer> entry : timers.entrySet()) {
        reportTimer(samples, timestamp, entry.getKey(), entry.getValue());
    }
    this.repository.insert(samples);
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) Sample(org.opennms.newts.api.Sample) Timestamp(org.opennms.newts.api.Timestamp) Gauge(com.codahale.metrics.Gauge) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 5 with Counter

use of com.codahale.metrics.Counter in project ninja by ninjaframework.

the class CountedInterceptor method invoke.

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    Counted counted = invocation.getMethod().getAnnotation(Counted.class);
    String counterName = counted.value();
    if (counterName.isEmpty()) {
        counterName = MetricRegistry.name(invocation.getThis().getClass().getSuperclass(), invocation.getMethod().getName());
    }
    Counter counter = metricsServiceProvider.get().getMetricRegistry().counter(counterName);
    counter.inc();
    try {
        return invocation.proceed();
    } finally {
        if (counted.active()) {
            counter.dec();
        }
    }
}
Also used : Counter(com.codahale.metrics.Counter)

Aggregations

Counter (com.codahale.metrics.Counter)55 Test (org.junit.Test)24 Map (java.util.Map)15 Timer (com.codahale.metrics.Timer)14 MetricRegistry (com.codahale.metrics.MetricRegistry)13 HashMap (java.util.HashMap)11 Gauge (com.codahale.metrics.Gauge)10 Histogram (com.codahale.metrics.Histogram)10 Metric (com.codahale.metrics.Metric)9 Meter (com.codahale.metrics.Meter)8 Random (java.util.Random)8 SolrInfoBean (org.apache.solr.core.SolrInfoBean)6 SortedMap (java.util.SortedMap)5 IOException (java.io.IOException)4 TreeMap (java.util.TreeMap)4 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)4 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)4 Description (com.google.gerrit.metrics.Description)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3