/** * Get a {@link ContextAwareMeter} with a given name. * * @param name name of the {@link ContextAwareMeter} * @return the {@link ContextAwareMeter} with the given name */ public ContextAwareMeter contextAwareMeter(String name) { return contextAwareMeter(name, ContextAwareMetricFactory.DEFAULT_CONTEXT_AWARE_METER_FACTORY); }
/** * This is equivalent to {@link #contextAwareMeter(String)}. */ @Override public Meter meter(String name) { return contextAwareMeter(name); }
InnerMeter(MetricContext context, String name, ContextAwareMeter contextAwareMeter) { this.name = name; Optional<MetricContext> parentContext = context.getParent(); if (parentContext.isPresent()) { this.parentMeter = Optional.fromNullable(parentContext.get().contextAwareMeter(name)); } else { this.parentMeter = Optional.absent(); } this.contextAwareMeter = new WeakReference<>(contextAwareMeter); }
public GobblinHelixMetrics(String metricsName, final MetricContext metricContext, int windowSizeInMin) { this.metricsName = metricsName; this.timeForHelixWait = metricContext.contextAwareTimer(TIMER_FOR_HELIX_WAIT, windowSizeInMin, TimeUnit.MINUTES); this.timeForHelixSubmit = metricContext.contextAwareTimer(TIMER_FOR_HELIX_SUBMIT, windowSizeInMin, TimeUnit.MINUTES); this.submitMeter = metricContext.contextAwareMeter(METER_FOR_HELIX_SUBMIT); this.contextAwareMetrics.add(timeForHelixWait); this.contextAwareMetrics.add(timeForHelixSubmit); this.contextAwareMetrics.add(submitMeter); }
@Override public void run() { Counter totalRecordsCounter = this.context.contextAwareCounter(TOTAL_RECORDS); Meter recordProcessRateMeter = this.context.contextAwareMeter(RECORD_PROCESS_RATE); Timer recordProcessTimeTimer = this.context.contextAwareTimer(RECORD_PROCESS_TIME); Histogram recordSizesHistogram = this.context.contextAwareHistogram(RECORD_SIZES);
@Test(dependsOnMethods = "testChildContext") public void testContextAwareMeter() { ContextAwareMeter jobRecordsProcessRate = this.context.contextAwareMeter(RECORD_PROCESS_RATE); Assert.assertEquals(this.context.getMeters() .get(jobRecordsProcessRate.getName()), jobRecordsProcessRate.getInnerMetric()); Assert.assertEquals(jobRecordsProcessRate.getContext(), this.context); Assert.assertEquals(jobRecordsProcessRate.getName(), RECORD_PROCESS_RATE); jobRecordsProcessRate.mark(); jobRecordsProcessRate.mark(3); Assert.assertEquals(jobRecordsProcessRate.getCount(), 4l); ContextAwareMeter taskRecordsProcessRate = this.childContext.contextAwareMeter(RECORD_PROCESS_RATE); Assert.assertEquals(this.childContext.getMeters() .get(taskRecordsProcessRate.getName()), taskRecordsProcessRate.getInnerMetric()); Assert.assertEquals(taskRecordsProcessRate.getContext(), this.childContext); Assert.assertEquals(taskRecordsProcessRate.getName(), RECORD_PROCESS_RATE); taskRecordsProcessRate.mark(2); Assert.assertEquals(taskRecordsProcessRate.getCount(), 2l); Assert.assertEquals(jobRecordsProcessRate.getCount(), 6l); taskRecordsProcessRate.mark(5); Assert.assertEquals(taskRecordsProcessRate.getCount(), 7l); Assert.assertEquals(jobRecordsProcessRate.getCount(), 11l); }
ContextAwareMeter meter = metricContext.contextAwareMeter("testMeter"); WeakReference<ContextAwareMeter> meterWeakReference = new WeakReference<ContextAwareMeter>(meter); meter.mark();
/** * This is equivalent to {@link #contextAwareMeter(String)}. */ @Override public Meter meter(String name) { return contextAwareMeter(name); }
/** * Get a {@link ContextAwareMeter} with a given name. * * @param name name of the {@link ContextAwareMeter} * @return the {@link ContextAwareMeter} with the given name */ public ContextAwareMeter contextAwareMeter(String name) { return contextAwareMeter(name, ContextAwareMetricFactory.DEFAULT_CONTEXT_AWARE_METER_FACTORY); }
InnerMeter(MetricContext context, String name, ContextAwareMeter contextAwareMeter) { this.name = name; Optional<MetricContext> parentContext = context.getParent(); if (parentContext.isPresent()) { this.parentMeter = Optional.fromNullable(parentContext.get().contextAwareMeter(name)); } else { this.parentMeter = Optional.absent(); } this.contextAwareMeter = new WeakReference<>(contextAwareMeter); }
@Override public void run() { Counter totalRecordsCounter = this.context.contextAwareCounter(TOTAL_RECORDS); Meter recordProcessRateMeter = this.context.contextAwareMeter(RECORD_PROCESS_RATE); Timer recordProcessTimeTimer = this.context.contextAwareTimer(RECORD_PROCESS_TIME); Histogram recordSizesHistogram = this.context.contextAwareHistogram(RECORD_SIZES);