/** * This is equivalent to {@link #contextAwareCounter(String)}. */ @Override public Counter counter(String name) { return contextAwareCounter(name); }
/** * Get a {@link ContextAwareCounter} with a given name. * * @param name name of the {@link ContextAwareCounter} * @return the {@link ContextAwareCounter} with the given name */ public ContextAwareCounter contextAwareCounter(String name) { return contextAwareCounter(name, ContextAwareMetricFactory.DEFAULT_CONTEXT_AWARE_COUNTER_FACTORY); }
public InnerCounter(MetricContext context, String name, ContextAwareCounter counter) { this.tagged = new Tagged(); this.name = name; Optional<MetricContext> parentContext = context.getParent(); if (parentContext.isPresent()) { this.parentCounter = Optional.fromNullable(parentContext.get().contextAwareCounter(name)); } else { this.parentCounter = Optional.absent(); } this.contextAwareCounter = new WeakReference<>(counter); }
public StandardMetrics(final JobExecutionLauncher parent) { this.numJobsLaunched = parent.getMetricContext().contextAwareCounter(NUM_JOBS_LAUNCHED); this.numJobsCompleted = parent.getMetricContext().contextAwareCounter(NUM_JOBS_COMPLETED); this.numJobsCommitted = parent.getMetricContext().contextAwareCounter(NUM_JOBS_COMMITTED); this.numJobsFailed = parent.getMetricContext().contextAwareCounter(NUM_JOBS_FAILED); this.numJobsCancelled = parent.getMetricContext().contextAwareCounter(NUM_JOBS_CANCELLED); this.numJobsRunning = parent.getMetricContext().newContextAwareGauge(NUM_JOBS_RUNNING, new Gauge<Integer>() { @Override public Integer getValue() { return (int)(StandardMetrics.this.getNumJobsLaunched().getCount() - StandardMetrics.this.getNumJobsCompleted().getCount() - StandardMetrics.this.getNumJobsCancelled().getCount()); } }); } }
@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);
public StandardMetrics(final GobblinInstanceDriver parent) { this.uptimeMs = parent.getMetricContext().newContextAwareGauge(UPTIMEMS_NAME, new Gauge<Long>() { @Override public Long getValue() { return startTimeMs > 0 ? System.currentTimeMillis() - startTimeMs : 0; } }); this.upFlag = parent.getMetricContext().newContextAwareGauge(UPFLAG_NAME, new Gauge<Integer>() { @Override public Integer getValue() { switch (parent.state()) { case RUNNING: return 1; case FAILED: return -1; default: return 0; } } }); this.numUnclassifiedErrors = parent.getMetricContext().contextAwareCounter(NUM_UNCLASSIFIED_ERRORS_NAME); parent.addListener(this, new Executor() { @Override public void execute(Runnable command) { command.run(); } }); }
@Test(dependsOnMethods = "testChildContext") public void testContextAwareCounter() { ContextAwareCounter jobRecordsProcessed = this.context.contextAwareCounter(RECORDS_PROCESSED); Assert.assertEquals(this.context.getCounters().get(jobRecordsProcessed.getName()), jobRecordsProcessed.getInnerMetric()); Assert.assertEquals(jobRecordsProcessed.getCount(), 2l); ContextAwareCounter taskRecordsProcessed = this.childContext.contextAwareCounter(RECORDS_PROCESSED); Assert.assertEquals(this.childContext.getCounters() .get(taskRecordsProcessed.getName()),
ContextAwareCounter counter1 = metricContext.contextAwareCounter("textCounter1"); ContextAwareCounter counter2 = metricContext.contextAwareCounter("testCounter"); WeakReference<ContextAwareCounter> counterWeakReference2 = new WeakReference<ContextAwareCounter>(counter2); ContextAwareMeter meter = metricContext.contextAwareMeter("testMeter");
/** * This is equivalent to {@link #contextAwareCounter(String)}. */ @Override public Counter counter(String name) { return contextAwareCounter(name); }
/** * Get a {@link ContextAwareCounter} with a given name. * * @param name name of the {@link ContextAwareCounter} * @return the {@link ContextAwareCounter} with the given name */ public ContextAwareCounter contextAwareCounter(String name) { return contextAwareCounter(name, ContextAwareMetricFactory.DEFAULT_CONTEXT_AWARE_COUNTER_FACTORY); }
public InnerCounter(MetricContext context, String name, ContextAwareCounter counter) { this.tagged = new Tagged(); this.name = name; Optional<MetricContext> parentContext = context.getParent(); if (parentContext.isPresent()) { this.parentCounter = Optional.fromNullable(parentContext.get().contextAwareCounter(name)); } else { this.parentCounter = Optional.absent(); } this.contextAwareCounter = new WeakReference<>(counter); }
public StandardMetrics(final JobExecutionLauncher parent) { this.numJobsLaunched = parent.getMetricContext().contextAwareCounter(NUM_JOBS_LAUNCHED); this.numJobsCompleted = parent.getMetricContext().contextAwareCounter(NUM_JOBS_COMPLETED); this.numJobsCommitted = parent.getMetricContext().contextAwareCounter(NUM_JOBS_COMMITTED); this.numJobsFailed = parent.getMetricContext().contextAwareCounter(NUM_JOBS_FAILED); this.numJobsCancelled = parent.getMetricContext().contextAwareCounter(NUM_JOBS_CANCELLED); this.numJobsRunning = parent.getMetricContext().newContextAwareGauge(NUM_JOBS_RUNNING, new Gauge<Integer>() { @Override public Integer getValue() { return (int)(StandardMetrics.this.getNumJobsLaunched().getCount() - StandardMetrics.this.getNumJobsCompleted().getCount() - StandardMetrics.this.getNumJobsCancelled().getCount()); } }); } }
@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);
public StandardMetrics(final GobblinInstanceDriver parent) { this.uptimeMs = parent.getMetricContext().newContextAwareGauge(UPTIMEMS_NAME, new Gauge<Long>() { @Override public Long getValue() { return startTimeMs > 0 ? System.currentTimeMillis() - startTimeMs : 0; } }); this.upFlag = parent.getMetricContext().newContextAwareGauge(UPFLAG_NAME, new Gauge<Integer>() { @Override public Integer getValue() { switch (parent.state()) { case RUNNING: return 1; case FAILED: return -1; default: return 0; } } }); this.numUnclassifiedErrors = parent.getMetricContext().contextAwareCounter(NUM_UNCLASSIFIED_ERRORS_NAME); parent.addListener(this, new Executor() { @Override public void execute(Runnable command) { command.run(); } }); }