exportInterval, retryInterval, Metrics.getExportComponent().getMetricProducerManager()); exporter.workerThread.start();
@Test public void getMetricRegistry() { assertThat(Metrics.getMetricRegistry()).isInstanceOf(MetricRegistryImpl.class); } }
@Test public void loadMetricsComponent_IgnoresMissingClasses() { ClassLoader classLoader = new ClassLoader() { @Override public Class<?> loadClass(String name) throws ClassNotFoundException { throw new ClassNotFoundException(); } }; assertThat(Metrics.loadMetricsComponent(classLoader).getClass().getName()) .isEqualTo("io.opencensus.metrics.MetricsComponent$NoopMetricsComponent"); }
/** * Creates a SignalFx Stats exporter from the given {@link SignalFxStatsConfiguration}. * * <p>If {@code ingestEndpoint} is not set on the configuration, the exporter will use {@link * SignalFxStatsConfiguration#DEFAULT_SIGNALFX_ENDPOINT}. * * <p>If {@code exportInterval} is not set on the configuration, the exporter will use {@link * SignalFxStatsConfiguration#DEFAULT_EXPORT_INTERVAL}. * * @param configuration the {@code SignalFxStatsConfiguration}. * @throws IllegalStateException if a SignalFx exporter is already created. * @since 0.11 */ public static void create(SignalFxStatsConfiguration configuration) { synchronized (monitor) { Preconditions.checkState(exporter == null, "SignalFx stats exporter is already created."); exporter = new SignalFxStatsExporter( configuration, Metrics.getExportComponent().getMetricProducerManager()); } }
@Test public void getMetricRegistry() { assertThat(Metrics.getMetricRegistry()).isInstanceOf(MetricRegistryImpl.class); } }
@Test public void loadMetricsComponent_UsesProvidedClassLoader() { final RuntimeException toThrow = new RuntimeException("UseClassLoader"); thrown.expect(RuntimeException.class); thrown.expectMessage("UseClassLoader"); Metrics.loadMetricsComponent( new ClassLoader() { @Override public Class<?> loadClass(String name) { throw toThrow; } }); }
/** * Creates a {@link PrometheusStatsCollector} and registers it to Prometheus {@link * CollectorRegistry#defaultRegistry}. * * <p>This is equivalent with: * * <pre>{@code * PrometheusStatsCollector.createAndRegister(PrometheusStatsConfiguration.builder().build()); * }</pre> * * @throws IllegalArgumentException if a {@code PrometheusStatsCollector} has already been created * and registered. * @since 0.12 */ public static void createAndRegister() { new PrometheusStatsCollector(Metrics.getExportComponent().getMetricProducerManager()) .register(); }
@Test public void defaultMetricRegistry() { assertThat(Metrics.getMetricRegistry()) .isInstanceOf(MetricRegistry.newNoopMetricRegistry().getClass()); } }
/** * Returns a new {@link Options.Builder}. * * @return a {@code Builder}. * @since 0.19 */ public static Builder builder() { return new AutoValue_MetricReader_Options.Builder() .setMetricProducerManager(Metrics.getExportComponent().getMetricProducerManager()) .setSpanName(DEFAULT_SPAN_NAME); }
/** * Returns a new {@link Options.Builder}. * * @return a {@code Builder}. * @since 0.19 */ public static Builder builder() { return new AutoValue_MetricReader_Options.Builder() .setMetricProducerManager(Metrics.getExportComponent().getMetricProducerManager()) .setSpanName(DEFAULT_SPAN_NAME); }
@Test public void getExportComponent() { assertThat(Metrics.getExportComponent()).isInstanceOf(ExportComponentImpl.class); }
@Test public void getExportComponent() { assertThat(Metrics.getExportComponent()).isInstanceOf(ExportComponentImpl.class); }
@Test public void defaultExportComponent() { assertThat(Metrics.getExportComponent()) .isInstanceOf(ExportComponent.newNoopExportComponent().getClass()); }
/** * Creates a {@link PrometheusStatsCollector} and registers it to the given Prometheus {@link * CollectorRegistry} in the {@link PrometheusStatsConfiguration}. * * <p>If {@code CollectorRegistry} of the configuration is not set, the collector will use {@link * CollectorRegistry#defaultRegistry}. * * @throws IllegalArgumentException if a {@code PrometheusStatsCollector} has already been created * and registered. * @since 0.13 */ public static void createAndRegister(PrometheusStatsConfiguration configuration) { CollectorRegistry registry = configuration.getRegistry(); if (registry == null) { registry = CollectorRegistry.defaultRegistry; } new PrometheusStatsCollector(Metrics.getExportComponent().getMetricProducerManager()) .register(registry); }
/** * Creates a new {@code StatsComponentImplBase}. * * @param queue the queue implementation. * @param clock the clock to use when recording stats. */ public StatsComponentImplBase(EventQueue queue, Clock clock) { StatsManager statsManager = new StatsManager(queue, clock, currentState); this.viewManager = new ViewManagerImpl(statsManager); this.statsRecorder = new StatsRecorderImpl(statsManager); // Create a new MetricProducerImpl and register it to MetricProducerManager when // StatsComponentImplBase is initialized. MetricProducer metricProducer = new MetricProducerImpl(statsManager); Metrics.getExportComponent().getMetricProducerManager().add(metricProducer); }
/** * Creates a new {@code StatsComponentImplBase}. * * @param queue the queue implementation. * @param clock the clock to use when recording stats. */ public StatsComponentImplBase(EventQueue queue, Clock clock) { StatsManager statsManager = new StatsManager(queue, clock, currentState); this.viewManager = new ViewManagerImpl(statsManager); this.statsRecorder = new StatsRecorderImpl(statsManager); // Create a new MetricProducerImpl and register it to MetricProducerManager when // StatsComponentImplBase is initialized. MetricProducer metricProducer = new MetricProducerImpl(statsManager); Metrics.getExportComponent().getMetricProducerManager().add(metricProducer); }
private StackdriverStatsExporter( String projectId, MetricServiceClient metricServiceClient, Duration exportInterval, MonitoredResource monitoredResource, @Nullable String metricNamePrefix) { IntervalMetricReader.Options.Builder intervalMetricReaderOptionsBuilder = IntervalMetricReader.Options.builder(); if (exportInterval != null) { intervalMetricReaderOptionsBuilder.setExportInterval(exportInterval); } intervalMetricReader = IntervalMetricReader.create( new CreateMetricDescriptorExporter( projectId, metricServiceClient, metricNamePrefix, new CreateTimeSeriesExporter( projectId, metricServiceClient, monitoredResource, metricNamePrefix)), MetricReader.create( MetricReader.Options.builder() .setMetricProducerManager( Metrics.getExportComponent().getMetricProducerManager()) .setSpanName(EXPORTER_SPAN_NAME) .build()), intervalMetricReaderOptionsBuilder.build()); }