Java Code Examples for io.micrometer.core.instrument.Clock#SYSTEM

The following examples show how to use io.micrometer.core.instrument.Clock#SYSTEM . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatsdMeterRegistryPublishTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@EnumSource(StatsdProtocol.class)
void whenRegistryStopped_doNotConnectToBackend(StatsdProtocol protocol) throws InterruptedException {
    serverLatch = new CountDownLatch(3);
    // start server to secure an open port
    server = startServer(protocol, 0);
    final int port = server.address().getPort();
    meterRegistry = new StatsdMeterRegistry(getUnbufferedConfig(protocol, port), Clock.SYSTEM);
    startRegistryAndWaitForClient();
    server.disposeNow();
    meterRegistry.stop();
    await().until(this::clientIsDisposed);
    server = startServer(protocol, port);
    Counter counter = Counter.builder("my.counter").register(meterRegistry);
    IntStream.range(0, 100).forEach(counter::increment);
    assertThat(serverLatch.await(1, TimeUnit.SECONDS)).isFalse();
}
 
Example 2
Source File: SampleRegistries.java    From micrometer with Apache License 2.0 6 votes vote down vote up
public static NewRelicMeterRegistry newRelic(String accountId, String apiKey) {
    return new NewRelicMeterRegistry(new NewRelicConfig() {
        @Override
        public String accountId() {
            return accountId;
        }

        @Override
        public String apiKey() {
            return apiKey;
        }

        @Override
        public Duration step() {
            return Duration.ofSeconds(10);
        }

        @Override
        @Nullable
        public String get(String k) {
            return null;
        }
    }, Clock.SYSTEM);
}
 
Example 3
Source File: StatsdMeterRegistryPublishTest.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@EnumSource(StatsdProtocol.class)
@Issue("#1676")
void stopAndStartMeterRegistrySendsMetrics(StatsdProtocol protocol) throws InterruptedException {
    serverLatch = new CountDownLatch(3);
    server = startServer(protocol, 0);

    final int port = server.address().getPort();

    meterRegistry = new StatsdMeterRegistry(getUnbufferedConfig(protocol, port), Clock.SYSTEM);
    startRegistryAndWaitForClient();
    Counter counter = Counter.builder("my.counter").register(meterRegistry);
    counter.increment();
    await().until(() -> serverLatch.getCount() == 2);
    meterRegistry.stop();
    await().until(this::clientIsDisposed);
    // These increments shouldn't be sent
    IntStream.range(0, 3).forEach(i -> counter.increment());
    startRegistryAndWaitForClient();
    assertThat(serverLatch.getCount()).isEqualTo(2);
    counter.increment();
    counter.increment();
    assertThat(serverLatch.await(1, TimeUnit.SECONDS)).isTrue();
}
 
Example 4
Source File: FluxMetricsFuseableTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void requestFusionDelegates() {
	AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create();
	FluxMetricsFuseable.MetricsFuseableSubscriber<Integer> fuseableSubscriber =
			new FluxMetricsFuseable.MetricsFuseableSubscriber<>(testSubscriber,
					registry, Clock.SYSTEM, "foo", Tags.empty());

	Fuseable.QueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>();
	fuseableSubscriber.onSubscribe(testQueue);

	assertThat(fuseableSubscriber.requestFusion(Fuseable.SYNC))
			.as("fusion mode SYNC").isEqualTo(Fuseable.SYNC);

	assertThat(fuseableSubscriber.requestFusion(Fuseable.ASYNC))
			.as("fusion mode ASYNC").isEqualTo(Fuseable.ASYNC);

	assertThat(fuseableSubscriber.requestFusion(Fuseable.NONE))
			.as("fusion mode NONE").isEqualTo(Fuseable.NONE);
}
 
Example 5
Source File: SampleRegistries.java    From micrometer with Apache License 2.0 6 votes vote down vote up
public static StatsdMeterRegistry sysdigStatsd() {
    return new StatsdMeterRegistry(new StatsdConfig() {
        @Override
        public Duration step() {
            return Duration.ofSeconds(10);
        }

        @Override
        @Nullable
        public String get(String k) {
            return null;
        }

        @Override
        public StatsdFlavor flavor() {
            return StatsdFlavor.SYSDIG;
        }
    }, Clock.SYSTEM);
}
 
Example 6
Source File: SampleRegistries.java    From micrometer with Apache License 2.0 6 votes vote down vote up
public static WavefrontMeterRegistry wavefrontDirect(String apiToken) {
    return new WavefrontMeterRegistry(new WavefrontConfig() {
        @Override
        public String get(String key) {
            return null;
        }

        @Override
        public String apiToken() {
            return apiToken;
        }

        @Override
        public String uri() {
            return "https://longboard.wavefront.com";
        }
    }, Clock.SYSTEM);
}
 
Example 7
Source File: MonoMetricsFuseableTest.java    From reactor-core with Apache License 2.0 6 votes vote down vote up
@Test
public void queueClearEmptySizeDelegates() {
	AssertSubscriber<Integer> testSubscriber = AssertSubscriber.create();
	MetricsFuseableSubscriber<Integer> fuseableSubscriber =
			new MetricsFuseableSubscriber<>(testSubscriber,
					registry, Clock.SYSTEM, Tags.empty());

	Fuseable.QueueSubscription<Integer> testQueue = new FluxPeekFuseableTest.AssertQueueSubscription<>();
	testQueue.offer(1);
	assertThat(testQueue.size()).isEqualTo(1);

	fuseableSubscriber.onSubscribe(testQueue);

	assertThat(fuseableSubscriber.isEmpty()).as("isEmpty").isFalse();
	assertThat(fuseableSubscriber.size()).as("size").isEqualTo(1);

	fuseableSubscriber.clear();

	assertThat(testQueue.size()).as("original queue impacted").isZero();
	assertThat(fuseableSubscriber.size()).as("size after clear").isEqualTo(0);
}
 
Example 8
Source File: SampleRegistries.java    From micrometer with Apache License 2.0 6 votes vote down vote up
public static AppOpticsMeterRegistry appOptics(String apiToken) {
    return new AppOpticsMeterRegistry(new AppOpticsConfig() {
        @Override
        public String apiToken() {
            return apiToken;
        }

        @Override
        public Duration step() {
            return Duration.ofSeconds(10);
        }

        @Override
        @Nullable
        public String get(String k) {
            return null;
        }
    }, Clock.SYSTEM);
}
 
Example 9
Source File: SampleRegistries.java    From micrometer with Apache License 2.0 6 votes vote down vote up
public static InfluxMeterRegistry influx() {
    return new InfluxMeterRegistry(new InfluxConfig() {
        @Override
        public String userName() {
            return "admin";
        }

        @Override
        public String password() {
            return "admin";
        }

        @Override
        public Duration step() {
            return Duration.ofSeconds(10);
        }

        @Override
        @Nullable
        public String get(String k) {
            return null;
        }
    }, Clock.SYSTEM);
}
 
Example 10
Source File: MicrometerAtlasIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenCompositeRegistries_whenRecordMeter_thenAllRegistriesRecorded() {
    CompositeMeterRegistry compositeRegistry = new CompositeMeterRegistry();

    SimpleMeterRegistry oneSimpleMeter = new SimpleMeterRegistry();
    AtlasMeterRegistry atlasMeterRegistry = new AtlasMeterRegistry(atlasConfig, Clock.SYSTEM);

    compositeRegistry.add(oneSimpleMeter);
    compositeRegistry.add(atlasMeterRegistry);

    compositeRegistry.gauge("baeldung.heat", 90);

    Optional<Gauge> oneGauge = oneSimpleMeter
      .find("baeldung.heat")
      .gauge();
    assertTrue(oneGauge.isPresent());
    Iterator<Measurement> measurements = oneGauge
      .get()
      .measure()
      .iterator();

    assertTrue(measurements.hasNext());
    assertThat(measurements
      .next()
      .getValue(), equalTo(90.00));

    Optional<Gauge> atlasGauge = atlasMeterRegistry
      .find("baeldung.heat")
      .gauge();
    assertTrue(atlasGauge.isPresent());
    Iterator<Measurement> anotherMeasurements = atlasGauge
      .get()
      .measure()
      .iterator();

    assertTrue(anotherMeasurements.hasNext());
    assertThat(anotherMeasurements
      .next()
      .getValue(), equalTo(90.00));
}
 
Example 11
Source File: CompareHistogramsWithOtherLibraries.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Setup(Level.Iteration)
public void setup() {
    registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, new CollectorRegistry(),
            Clock.SYSTEM);
    summary = DistributionSummary.builder("summary")
            .publishPercentileHistogram()
            .register(registry);
}
 
Example 12
Source File: TracingConfig.java    From Mastering-Distributed-Tracing with MIT License 5 votes vote down vote up
@Bean
public PrometheusMeterRegistry micrometerRegistry(CollectorRegistry collector) {
    PrometheusMeterRegistry registry = new PrometheusMeterRegistry( //
            PrometheusConfig.DEFAULT, collector, Clock.SYSTEM);
    io.micrometer.core.instrument.Metrics.addRegistry(registry);
    return registry;
}
 
Example 13
Source File: SampleRegistries.java    From micrometer with Apache License 2.0 5 votes vote down vote up
public static GraphiteMeterRegistry graphite() {
    return new GraphiteMeterRegistry(new GraphiteConfig() {
        @Override
        public Duration step() {
            return Duration.ofSeconds(10);
        }

        @Override
        @Nullable
        public String get(String k) {
            return null;
        }
    }, Clock.SYSTEM);
}
 
Example 14
Source File: SkywalkingMeterRegistry.java    From skywalking with Apache License 2.0 4 votes vote down vote up
public SkywalkingMeterRegistry() {
    this(SkywalkingConfig.DEFAULT, Clock.SYSTEM);
}
 
Example 15
Source File: JmxBackendRegistry.java    From vertx-micrometer-metrics with Apache License 2.0 4 votes vote down vote up
public JmxBackendRegistry(VertxJmxMetricsOptions options) {
  registry = new JmxMeterRegistry(options.toMicrometerConfig(), Clock.SYSTEM);
}
 
Example 16
Source File: PrometheusMetricsReporterConfiguration.java    From java-metrics with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public PrometheusMeterRegistry prometheusMeterRegistry() {
    return new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, collectorRegistry, Clock.SYSTEM);
}
 
Example 17
Source File: StatsdMeterRegistryPublishTest.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@ParameterizedTest
@EnumSource(StatsdProtocol.class)
void resumeSendingMetrics_whenServerIntermittentlyFails(StatsdProtocol protocol) throws InterruptedException {
    serverLatch = new CountDownLatch(1);
    AtomicInteger writeCount = new AtomicInteger();
    server = startServer(protocol, 0);

    final int port = server.address().getPort();

    meterRegistry = new StatsdMeterRegistry(getUnbufferedConfig(protocol, port), Clock.SYSTEM);
    startRegistryAndWaitForClient();
    trackWritesForUdpClient(protocol, writeCount);
    Counter counter = Counter.builder("my.counter").register(meterRegistry);
    counter.increment(1);
    assertThat(serverLatch.await(5, TimeUnit.SECONDS)).isTrue();

    Disposable firstClient = meterRegistry.client.get();

    server.disposeNow();
    serverLatch = new CountDownLatch(3);
    // client will try to send but server is down
    IntStream.range(2, 5).forEach(counter::increment);
    if (protocol == StatsdProtocol.UDP) {
        await().until(() -> writeCount.get() == 4);
    }
    server = startServer(protocol, port);
    assertThat(serverLatch.getCount()).isEqualTo(3);

    await().until(() -> bound);

    // Note that this guarantees this test to be passed.
    // For TCP, this will help trigger replacing client. If this triggered replacing, this change will be lost.
    // For UDP, the first change seems to be lost frequently somehow.
    Counter.builder("another.counter").register(meterRegistry).increment();

    if (protocol == StatsdProtocol.TCP) {
        await().until(() -> meterRegistry.client.get() != firstClient);
    }

    counter.increment(5);
    counter.increment(6);
    counter.increment(7);
    assertThat(serverLatch.await(3, TimeUnit.SECONDS)).isTrue();
}
 
Example 18
Source File: CustomMetricWriterTest.java    From cf-java-logging-support with Apache License 2.0 4 votes vote down vote up
private CustomMetricWriter createWriter() {
    return new CustomMetricWriter(CustomMetricsConfigurationFactory.create(), Clock.SYSTEM, client);
}
 
Example 19
Source File: MonoMetrics.java    From reactor-core with Apache License 2.0 4 votes vote down vote up
@Override
public CoreSubscriber<? super T> subscribeOrReturn(CoreSubscriber<? super T> actual) {
	return new MetricsSubscriber<>(actual, meterRegistry, Clock.SYSTEM, this.tags);
}
 
Example 20
Source File: DropwizardMeterRegistriesTest.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Test
void micrometerAddsUnwantedGauges() {
    final DropwizardMeterRegistry micrometer = new DropwizardMeterRegistry(
            DEFAULT_DROPWIZARD_CONFIG, new MetricRegistry(), DEFAULT_NAME_MAPPER, Clock.SYSTEM) {
        @Override
        protected Double nullGaugeValue() {
            return 0.0;
        }
    };
    final MetricRegistry dropwizard = micrometer.getDropwizardRegistry();

    final DistributionSummary percentileSummary = DistributionSummary.builder("percentileSummary")
                                                                     .publishPercentiles(0.5)
                                                                     .register(micrometer);
    final DistributionSummary histogramSummary = DistributionSummary.builder("histogramSummary")
                                                                    .sla(10)
                                                                    .register(micrometer);
    final Timer percentileTimer = Timer.builder("percentileTimer")
                                       .publishPercentiles(0.5)
                                       .register(micrometer);
    final Timer histogramTimer = Timer.builder("histogramTimer")
                                      .sla(Duration.ofSeconds(10))
                                      .register(micrometer);
    percentileSummary.record(42);
    histogramSummary.record(42);
    percentileTimer.record(42, TimeUnit.SECONDS);
    histogramTimer.record(42, TimeUnit.SECONDS);

    // Make sure Micrometer by default registers the unwanted gauges.
    final Map<String, Double> measurements = MoreMeters.measureAll(micrometer);
    assertThat(measurements).containsKeys(
            "percentileSummary.percentile#value{phi=0.5}",
            "histogramSummary.histogram#value{le=10}",
            "percentileTimer.percentile#value{phi=0.5}",
            "histogramTimer.histogram#value{le=10000}");

    assertThat(dropwizard.getGauges()).containsKeys(
            "percentileSummaryPercentile.phi:0.5",
            "histogramSummaryHistogram.le:10",
            "percentileTimerPercentile.phi:0.5",
            "histogramTimerHistogram.le:10000");
}