Java Code Examples for io.micrometer.core.instrument.Metrics#addRegistry()
The following examples show how to use
io.micrometer.core.instrument.Metrics#addRegistry() .
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: TcpMetricsTests.java From reactor-netty with Apache License 2.0 | 6 votes |
@Before public void setUp() { tcpServer = customizeServerOptions(TcpServer.create() .host("127.0.0.1") .port(0) .metrics(true)); provider = ConnectionProvider.create("TcpMetricsTests", 1); tcpClient = customizeClientOptions(TcpClient.create(provider) .remoteAddress(() -> disposableServer.address()) .metrics(true)); registry = new SimpleMeterRegistry(); Metrics.addRegistry(registry); }
Example 2
Source File: MicrometerAtlasIntegrationTest.java From tutorials with MIT License | 6 votes |
@Test public void givenGlobalRegistry_whenIncrementAnywhere_thenCounted() { class CountedObject { private CountedObject() { Metrics .counter("objects.instance") .increment(1.0); } } Metrics.addRegistry(new SimpleMeterRegistry()); Metrics .counter("objects.instance") .increment(); new CountedObject(); Optional<Counter> counterOptional = Metrics.globalRegistry .find("objects.instance") .counter(); assertTrue(counterOptional.isPresent()); assertTrue(counterOptional .get() .count() == 2.0); }
Example 3
Source File: HttpMetricsHandlerTests.java From reactor-netty with Apache License 2.0 | 6 votes |
@Before public void setUp() { httpServer = customizeServerOptions( HttpServer.create() .host("127.0.0.1") .port(0) .metrics(true, s -> s) .route(r -> r.post("/1", (req, res) -> res.header("Connection", "close") .send(req.receive().retain().delayElements(Duration.ofMillis(10)))) .post("/2", (req, res) -> res.header("Connection", "close") .send(req.receive().retain().delayElements(Duration.ofMillis(10)))))); provider = ConnectionProvider.create("HttpMetricsHandlerTests", 1); httpClient = customizeClientOptions(HttpClient.create(provider) .remoteAddress(() -> disposableServer.address()) .metrics(true, s -> s)); registry = new SimpleMeterRegistry(); Metrics.addRegistry(registry); }
Example 4
Source File: UdpMetricsTests.java From reactor-netty with Apache License 2.0 | 6 votes |
@Before public void setUp() { udpServer = UdpServer.create() .host("127.0.0.1") .port(0) .metrics(true); udpClient = UdpClient.create() .remoteAddress(() -> serverConnection.address()) .metrics(true); registry = new SimpleMeterRegistry(); Metrics.addRegistry(registry); }
Example 5
Source File: PrometheusMetricsReporterConfiguration.java From java-metrics with Apache License 2.0 | 6 votes |
@Bean public MetricsReporter prometheusMetricsReporter(PrometheusMeterRegistry prometheusMeterRegistry) { Metrics.addRegistry(prometheusMeterRegistry); MicrometerMetricsReporter.Builder builder = MicrometerMetricsReporter.newMetricsReporter(); if (metricsName != null && !metricsName.isEmpty()) { builder.withName(metricsName); } if (metricLabels != null && !metricLabels.isEmpty()) { for (MetricLabel label : metricLabels) { builder.withCustomLabel(label); } } return builder.build(); }
Example 6
Source File: MicrometerMetricsReporterTest.java From java-metrics with Apache License 2.0 | 5 votes |
@Before public void init() { for (MeterRegistry registry : Metrics.globalRegistry.getRegistries()) { Metrics.removeRegistry(registry); } this.registry = new SimpleMeterRegistry(); Metrics.addRegistry(this.registry); }
Example 7
Source File: MeterRegistryConfigurer.java From foremast with Apache License 2.0 | 5 votes |
void configure(MeterRegistry registry) { // Customizers must be applied before binders, as they may add custom // tags or alter timer or summary configuration. customize(registry); addFilters(registry); addBinders(registry); if (this.addToGlobalRegistry && registry != Metrics.globalRegistry) { Metrics.addRegistry(registry); } }
Example 8
Source File: StatsProviderImpl.java From pravega with Apache License 2.0 | 5 votes |
@Synchronized @Override public void startWithoutExporting() { for (MeterRegistry registry : new ArrayList<MeterRegistry>(metrics.getRegistries())) { metrics.remove(registry); } Metrics.addRegistry(new SimpleMeterRegistry()); metrics.config().commonTags(createHostTag(DEFAULT_HOSTNAME_KEY)); }
Example 9
Source File: ServerBuilderTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void monitorBlockingTaskExecutorAndSchedulersTogetherWithPrometheus() { final PrometheusMeterRegistry registry = PrometheusMeterRegistries.newRegistry(); Metrics.addRegistry(registry); Server.builder() .meterRegistry(registry) .service("/", (ctx, req) -> HttpResponse.of(200)) .build(); Schedulers.enableMetrics(); Schedulers.decorateExecutorService(Schedulers.single(), Executors.newSingleThreadScheduledExecutor()); }
Example 10
Source File: TaskMetricsTests.java From spring-cloud-task with Apache License 2.0 | 5 votes |
@Before public void before() { Metrics.globalRegistry.getMeters().forEach(Metrics.globalRegistry::remove); simpleMeterRegistry = new SimpleMeterRegistry(); Metrics.addRegistry(simpleMeterRegistry); taskMetrics = new TaskMetrics(); }
Example 11
Source File: MeterRegistryConfigurer.java From foremast with Apache License 2.0 | 5 votes |
void configure(MeterRegistry registry) { // Customizers must be applied before binders, as they may add custom // tags or alter timer or summary configuration. customize(registry); addFilters(registry); addBinders(registry); if (this.addToGlobalRegistry && registry != Metrics.globalRegistry) { Metrics.addRegistry(registry); } }
Example 12
Source File: ProjectionTest.java From mewbase with MIT License | 4 votes |
@Test // @Repeat(50) public void testSimpleProjectionRuns() throws Exception { // Register the metrics counter(s) locally Metrics.addRegistry(new SimpleMeterRegistry()); final String TEST_BINDER = new Object(){}.getClass().getEnclosingMethod().getName(); ProjectionManager manager = ProjectionManager.instance(source,store); ProjectionBuilder builder = manager.builder(); final String TEST_BASKET_ID = "TestBasket"; final Integer RESULT = new Integer(27); final CountDownLatch latch = new CountDownLatch(1); CompletableFuture<Projection> projectionFut = builder .named(TEST_PROJECTION_NAME) .projecting(TEST_CHANNEL) .onto(TEST_BINDER) .filteredBy(event -> true) .identifiedBy(event -> event.getBson().getString(BASKET_ID_FIELD)) .as( (basket, event) -> { assertNotNull(basket); assertNotNull(event); BsonObject out = event.getBson().put("output",RESULT); latch.countDown(); return out; }) .create(); // ensure the projection is set up or times out final Projection projection = projectionFut.get(PROJECTION_SETUP_MAX_TIMEOUT, TimeUnit.SECONDS); // Send an event to the channel which the projection is subscribed to. BsonObject evt = new BsonObject().put(BASKET_ID_FIELD, TEST_BASKET_ID); sink.publishSync(TEST_CHANNEL, evt); latch.await(); Thread.sleep(200); // try to recover the new document Binder binder = store.open(TEST_BINDER); BsonObject basketDoc = binder.get(TEST_BASKET_ID).get(); assertNotNull(basketDoc); assertEquals(RESULT,basketDoc.getInteger("output")); projection.stop(); // test instrumentation final Counter processedEvents = Metrics.globalRegistry.find("mewbase.projection") .tag("name", TEST_PROJECTION_NAME) .counter(); assertTrue(processedEvents.count() > 0.000001); //wrong tag final Counter none = Metrics.globalRegistry.find("mewbase.projection") .tag("name", "Not a valid projection name") .counter(); assertNull("Non existent counter exists!", none); }
Example 13
Source File: EventSourceTest.java From mewbase with MIT License | 4 votes |
@Test public void testSubscribeAll() throws Exception { // Register the counters locally Metrics.addRegistry(new SimpleMeterRegistry()); // use test local config final Config testConfig = createConfig(); final EventSink sink = EventSink.instance(testConfig); final EventSource source = EventSource.instance(testConfig); final String testChannelName = "TestAllChannel"+UUID.randomUUID(); final long START_EVENT_NUMBER = 0; final long END_EVENT_NUMBER = 64; final long RESTART_EVENT_NUMBER = 65; final long REEND_EVENT_NUMBER = 128; final int expectedEvents = (int) (REEND_EVENT_NUMBER + 1); final CountDownLatch latch = new CountDownLatch(expectedEvents); final List<Long> nums = new LinkedList<>(); final EventSinkUtils utils = new EventSinkUtils(sink); utils.sendNumberedEvents(testChannelName,START_EVENT_NUMBER, END_EVENT_NUMBER); final CompletableFuture<Subscription> subFut = source.subscribeAll(testChannelName, event -> { nums.add(event.getBson().getLong("num")); latch.countDown(); }); // will throw if the subscription doesnt set uop in the given time final Subscription sub = subFut.get(SUBSCRIPTION_SETUP_MAX_TIMEOUT, TimeUnit.SECONDS); utils.sendNumberedEvents(testChannelName, RESTART_EVENT_NUMBER, REEND_EVENT_NUMBER ); latch.await(); // test instrumentation final Counter subs = Metrics.globalRegistry.find("mewbase.event.source.subscribe") .counter(); final Double minSubs = 1.0; // At least this subscription must have been recorded assertTrue("No subscriptions recorded", subs.count() >= minSubs ); final Counter events = Metrics.globalRegistry.find("mewbase.event.source.event") .tag("channel", testChannelName) .counter(); assertEquals(expectedEvents, events.count(), 0.000001); sub.close(); source.close(); sink.close(); }
Example 14
Source File: EventSinkTest.java From mewbase with MIT License | 4 votes |
@Test public void testManyEventsInOrder() throws Exception { // Register the counters locally Metrics.addRegistry(new SimpleMeterRegistry()); // use test local config final Config testConfig = createConfig(); final EventSink sink = EventSink.instance(testConfig); final EventSource source = EventSource.instance(testConfig); // Test local event producer to inject events in the event source. final String testChannelName = "TestManyOrderedEventsChannel" + UUID.randomUUID(); final int START_EVENT_NUMBER = 1; final int END_EVENT_NUMBER = 128; final int TOTAL_EVENTS = END_EVENT_NUMBER - START_EVENT_NUMBER; final CountDownLatch latch = new CountDownLatch(TOTAL_EVENTS); final CompletableFuture<Subscription> subFut = source.subscribe(testChannelName, event -> { BsonObject bson = event.getBson(); long thisEventNum = END_EVENT_NUMBER - latch.getCount(); assert (bson.getLong("num") == thisEventNum); latch.countDown(); }); final Subscription sub = subFut.get(SUBSCRIPTION_SETUP_MAX_TIMEOUT, TimeUnit.SECONDS); LongStream.rangeClosed(START_EVENT_NUMBER,END_EVENT_NUMBER).sequential().forEach(l -> { final BsonObject bsonEvent = new BsonObject().put("num", l); sink.publishSync(testChannelName,bsonEvent); } ); latch.await(); // test instrumentation final Counter gets = Metrics.globalRegistry.find("mewbase.event.sink.publish.sync") .tag("channel", testChannelName) .counter(); assertEquals(gets.count() , END_EVENT_NUMBER, 0.000001); sub.close(); source.close(); sink.close(); }
Example 15
Source File: MicrometerCapability.java From feign with Apache License 2.0 | 4 votes |
public MicrometerCapability() { this(new SimpleMeterRegistry(SimpleConfig.DEFAULT, Clock.SYSTEM)); Metrics.addRegistry(meterRegistry); }
Example 16
Source File: PooledConnectionProviderMetricsTest.java From reactor-netty with Apache License 2.0 | 4 votes |
@Before public void setUp() { registry = new SimpleMeterRegistry(); Metrics.addRegistry(registry); }
Example 17
Source File: AddressResolverGroupMetricsTest.java From reactor-netty with Apache License 2.0 | 4 votes |
@Before public void setUp() { registry = new SimpleMeterRegistry(); Metrics.addRegistry(registry); }
Example 18
Source File: ByteBufAllocatorMetricsTest.java From reactor-netty with Apache License 2.0 | 4 votes |
@Before public void setUp() { registry = new SimpleMeterRegistry(); Metrics.addRegistry(registry); }
Example 19
Source File: PrometheusMeterRegistryProvider.java From che with Eclipse Public License 2.0 | 4 votes |
@Inject public PrometheusMeterRegistryProvider(CollectorRegistry registry) { prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, registry, Clock.SYSTEM); Metrics.addRegistry(prometheusMeterRegistry); }
Example 20
Source File: SchedulersMetricsTest.java From reactor-core with Apache License 2.0 | 4 votes |
@Before public void setUp() { Metrics.addRegistry(simpleMeterRegistry); Schedulers.enableMetrics(); }