public ContextWeakReference(MetricContext referent, InnerMetricContext innerContext) { super(referent, RootMetricContext.get().getReferenceQueue()); this.innerContext = innerContext; }
/** * Get the singleton {@link RootMetricContext}. * @return singleton instance of {@link RootMetricContext}. */ public synchronized static RootMetricContext get() { return get(Lists.<Tag<?>>newArrayList()); }
/** * Removes {@link ContextAwareReporter} records from the {@link RootMetricContext}. * This method should be considered irreversible and destructive to the {@link ContextAwareReporter}. * @throws IOException */ @Override public void close() throws IOException { RootMetricContext.get().removeNotificationTarget(this.notificationTargetUUID); RootMetricContext.get().removeReporter(this); }
@Override public Set<MetricContext> getMatchingContexts() { ImmutableSet.Builder<MetricContext> builder = ImmutableSet.builder(); addContextsRecursively(builder, RootMetricContext.get()); return builder.build(); }
private void buildJmxMetricReporter(Properties properties) { if (!Boolean.valueOf(properties.getProperty(ConfigurationKeys.METRICS_REPORTING_JMX_ENABLED_KEY, ConfigurationKeys.DEFAULT_METRICS_REPORTING_JMX_ENABLED))) { return; } LOGGER.info("Reporting metrics to JMX"); this.jmxReporter = Optional.of(codahaleReportersCloser.register(JmxReporter.forRegistry(RootMetricContext.get()). convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build())); }
public AzkabanGobblinDaemon(String jobId, Properties props) throws Exception { super(jobId, LOG); List<Tag<?>> tags = Lists.newArrayList(); tags.addAll(Tag.fromMap(AzkabanTags.getAzkabanTags())); RootMetricContext.get(tags); this.daemon = new SchedulerDaemon(props); }
((CustomCodahaleReporterFactory) clazz.getConstructor().newInstance()); com.codahale.metrics.ScheduledReporter scheduledReporter = customCodahaleReporterFactory.newScheduledReporter(RootMetricContext.get(), properties); if (scheduledReporter == null) { LOGGER.warn("Factory {} returns a null scheduledReporter", clazz.getSimpleName());
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); } }
/** * Builder a new {@link MetricContext}. * * <p> * See {@link Taggable#metricNamePrefix(boolean)} for the semantic of {@code includeTagKeys}. * </p> * * @return the newly built {@link MetricContext} * @throws NameConflictException if the parent {@link MetricContext} already has a child with this name. */ public MetricContext buildStrict() throws NameConflictException { if(this.parent == null) { hasParent(RootMetricContext.get()); } return new MetricContext(this.name, this.parent, this.tags, false); }
@Override public Set<MetricContext> getMatchingContexts() { Set<MetricContext> contexts = Sets.newHashSet(); addContextsRecursively(contexts, RootMetricContext.get()); return ImmutableSet.copyOf(contexts); }
@AfterMethod public void tearDown() throws Exception { CACHE.invalidateAll(); System.gc(); RootMetricContext.get().clearNotificationTargets(); }
@BeforeMethod public void setUp() throws Exception { System.gc(); RootMetricContext.get().clearNotificationTargets(); }
public ContextAwareReporter(String name, Config config) { this.name = name; this.config = config; this.started = false; RootMetricContext.get().addNewReporter(this); this.notificationTargetUUID = RootMetricContext.get().addNotificationTarget(new Function<Notification, Void>() { @Nullable @Override public Void apply(Notification input) { notificationCallback(input); return null; } }); this.contextFilter = ContextFilterFactory.createContextFilter(config); this.contextsToReport = Sets.newConcurrentHashSet(); for (MetricContext context : this.contextFilter.getMatchingContexts()) { this.contextsToReport.add(context.getInnerMetricContext()); } }
RootMetricContext.get().stopReporting();
@Test public void testReporterCanBeAddedToStartedContext() throws Exception { RootMetricContext.get().startReporting(); ContextStoreReporter reporter = new ContextStoreReporter("testReporter", ConfigFactory.empty()); Assert.assertTrue(reporter.isStarted()); RootMetricContext.get().stopReporting(); }
@BeforeClass public void setUp() { String contextName = CONTEXT_NAME + "_" + UUID.randomUUID().toString(); this.context = MetricContext.builder(contextName) .addTag(new Tag<String>(JOB_ID_KEY, JOB_ID_PREFIX + 0)) .build(); Assert.assertEquals(this.context.getName(), contextName); Assert.assertTrue(this.context.getParent().isPresent()); Assert.assertEquals(this.context.getParent().get(), RootMetricContext.get()); Assert.assertEquals(this.context.getTags().size(), 3); // uuid and name tag gets added automatically Assert.assertEquals(this.context.getTags().get(0).getKey(), JOB_ID_KEY); Assert.assertEquals(this.context.getTags().get(0).getValue(), JOB_ID_PREFIX + 0); // Second tag should be uuid Assert.assertTrue(this.context.getTags().get(1).getValue().toString() .matches("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}")); }
@Builder private MetricsUpdater(int depth, int counters, int meters, int histograms, int timers, MetricContext baseContext) { this.depth = depth; this.random = new Random(); MetricContext tmpContext = baseContext == null ? RootMetricContext.get() : baseContext; while(depth > 0) { tmpContext = tmpContext.childBuilder(UUID.randomUUID().toString()).build(); depth--; } this.context = tmpContext; this.counters = Lists.newArrayList(); for(int i = 0; i < counters; i++) { this.counters.add(this.context.counter("gobblin.performance.test.counter" + i)); } this.meters = Lists.newArrayList(); for(int i = 0; i < meters; i++) { this.meters.add(this.context.meter("gobblin.performance.test.meter" + i)); } this.histograms = Lists.newArrayList(); for(int i = 0; i < histograms; i++) { this.histograms.add(this.context.histogram("gobblin.performance.test.histogram" + i)); } this.timers = Lists.newArrayList(); for(int i = 0; i < timers; i++) { this.timers.add(this.context.timer("gobblin.performance.test.timer" + i)); } }
MetricContext parentMetricContext = RootMetricContext.get();
RootMetricContext.get().startReporting();