/** * Register a {@link org.apache.gobblin.metrics.ContextAwareMetric} under its own name. */ public <T extends ContextAwareMetric> T register(T metric) throws IllegalArgumentException { return register(metric.getName(), metric); }
protected MetricContext(String name, MetricContext parent, List<Tag<?>> tags, boolean isRoot) throws NameConflictException { Preconditions.checkArgument(!Strings.isNullOrEmpty(name)); this.closer = Closer.create(); try { this.innerMetricContext = this.closer.register(new InnerMetricContext(this, name, parent, tags)); } catch(ExecutionException ee) { throw Throwables.propagate(ee); } this.contextAwareMetricsSet = Sets.newConcurrentHashSet(); this.notificationTargets = Maps.newConcurrentMap(); this.executorServiceOptional = Optional.absent(); this.notificationTimer = new ContextAwareTimer(this, GOBBLIN_METRICS_NOTIFICATIONS_TIMER_NAME); register(this.notificationTimer); if (!isRoot) { RootMetricContext.get().addMetricContext(this); } }
@Test public void testTaggableGauge() { ContextAwareGauge<Long> queueSize = this.context.newContextAwareGauge( QUEUE_SIZE, new Gauge<Long>() { @Override public Long getValue() { return 1000l; } }); this.context.register(QUEUE_SIZE, queueSize); Assert.assertEquals(queueSize.getValue().longValue(), 1000l); Assert.assertEquals( this.context.getGauges().get(queueSize.getName()), queueSize.getInnerMetric()); Assert.assertEquals(queueSize.getContext(), this.context); Assert.assertEquals(queueSize.getName(), QUEUE_SIZE); }
metricContext.register(MetricRegistry.name(METRIC_PREFIX, GAUGE), contextAwareGauge); Counter counter = metricContext.counter(MetricRegistry.name(METRIC_PREFIX, COUNTER)); Meter meter = metricContext.meter(MetricRegistry.name(METRIC_PREFIX, METER));
metricContext.register(MetricRegistry.name(METRIC_PREFIX, GAUGE), contextAwareGauge); Counter counter = metricContext.counter(MetricRegistry.name(METRIC_PREFIX, COUNTER)); Meter meter = metricContext.meter(MetricRegistry.name(METRIC_PREFIX, METER));
/** * Register a {@link org.apache.gobblin.metrics.ContextAwareMetric} under its own name. */ public <T extends ContextAwareMetric> T register(T metric) throws IllegalArgumentException { return register(metric.getName(), metric); }
protected MetricContext(String name, MetricContext parent, List<Tag<?>> tags, boolean isRoot) throws NameConflictException { Preconditions.checkArgument(!Strings.isNullOrEmpty(name)); this.closer = Closer.create(); try { this.innerMetricContext = this.closer.register(new InnerMetricContext(this, name, parent, tags)); } catch(ExecutionException ee) { throw Throwables.propagate(ee); } this.contextAwareMetricsSet = Sets.newConcurrentHashSet(); this.notificationTargets = Maps.newConcurrentMap(); this.executorServiceOptional = Optional.absent(); this.notificationTimer = new ContextAwareTimer(this, GOBBLIN_METRICS_NOTIFICATIONS_TIMER_NAME); register(this.notificationTimer); if (!isRoot) { RootMetricContext.get().addMetricContext(this); } }