Bird
0
0

Which of the following is the correct way to create a counter metric using Micrometer in Spring Boot?

easy📝 Syntax Q12 of 15
Spring Boot - Actuator
Which of the following is the correct way to create a counter metric using Micrometer in Spring Boot?
ACounter counter = Counter.builder("my.counter").register(meterRegistry);
BCounter counter = new Counter("my.counter");
CCounter counter = meterRegistry.createCounter("my.counter");
DCounter counter = Counter.create("my.counter");
Step-by-Step Solution
Solution:
  1. Step 1: Recall Micrometer counter creation syntax

    Micrometer uses builder pattern: Counter.builder(name).register(meterRegistry) to create counters.
  2. Step 2: Check other options for correctness

    Options B, C, and D use incorrect constructors or methods not available in Micrometer.
  3. Final Answer:

    Counter counter = Counter.builder("my.counter").register(meterRegistry); -> Option A
  4. Quick Check:

    Use builder().register() to create counters [OK]
Quick Trick: Use builder() and register() to create metrics [OK]
Common Mistakes:
  • Trying to instantiate Counter with new keyword
  • Using non-existent createCounter method
  • Missing register() call after builder()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes