0
0
Spring Bootframework~20 mins

Metrics with Micrometer in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Micrometer Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Micrometer counter increment?
Consider this Spring Boot code snippet using Micrometer:
Counter counter = meterRegistry.counter("my.counter");
counter.increment();
counter.increment(2);

What is the value of counter.count() after these calls?
Spring Boot
Counter counter = meterRegistry.counter("my.counter");
counter.increment();
counter.increment(2);
double value = counter.count();
A0.0
B2.0
C1.0
D3.0
Attempts:
2 left
💡 Hint
Remember that each increment adds to the counter's total count.
📝 Syntax
intermediate
2:00remaining
Which option correctly registers a Gauge metric in Micrometer?
You want to register a Gauge metric named "queue.size" that tracks the size of a queue. Which code snippet is correct?
AGauge gauge = Gauge.builder("queue.size", queue, q -> q.size()).register(meterRegistry);
BGauge gauge = meterRegistry.gauge("queue.size", queue.size());
CGauge gauge = Gauge.builder("queue.size", () -> queue.size()).register(meterRegistry);
DGauge gauge = Gauge.builder("queue.size", queue).register(meterRegistry);
Attempts:
2 left
💡 Hint
The builder requires the object and a function to get the value.
🔧 Debug
advanced
2:00remaining
Why does this Timer metric not record durations correctly?
Given this code:
Timer timer = meterRegistry.timer("process.time");
timer.record(() -> {
  // some process
  Thread.sleep(100);
});
System.out.println(timer.count());

The printed count is always 0. What is the cause?
Spring Boot
Timer timer = meterRegistry.timer("process.time");
timer.record(() -> {
  Thread.sleep(100);
});
System.out.println(timer.count());
AThread.sleep throws InterruptedException which is not handled, so the lambda never completes.
BThe timer is not registered properly with meterRegistry.
CThe record method requires a Callable, not a Runnable.
DThe timer.count() returns the number of recorded events, so 0 means no record was made.
Attempts:
2 left
💡 Hint
Check if the lambda handles checked exceptions properly.
state_output
advanced
2:00remaining
What is the value of the Gauge after updating the tracked object?
Consider this code:
AtomicInteger value = new AtomicInteger(5);
Gauge gauge = Gauge.builder("current.value", value, AtomicInteger::get).register(meterRegistry);
value.set(10);
double gaugeValue = gauge.value();

What is the value of gaugeValue?
Spring Boot
AtomicInteger value = new AtomicInteger(5);
Gauge gauge = Gauge.builder("current.value", value, AtomicInteger::get).register(meterRegistry);
value.set(10);
double gaugeValue = gauge.value();
A5.0
B0.0
C10.0
DThrows NullPointerException
Attempts:
2 left
💡 Hint
Gauge reads the current value from the object each time it is queried.
🧠 Conceptual
expert
2:00remaining
Which Micrometer meter type is best to measure the rate of events per second?
You want to monitor how many requests your service receives per second. Which Micrometer meter type should you use?
ADistributionSummary
BCounter
CGauge
DTimer
Attempts:
2 left
💡 Hint
Think about a metric that only increases and can be used to calculate rates.