Complete the code to create a counter metric using Micrometer.
Counter counter = Counter.builder("[1]") .description("Counts user logins") .register(meterRegistry);
The metric name should be a clear, dot-separated string like user_logins_total to follow Micrometer naming conventions.
Complete the code to increment the counter when a user logs in.
public void onUserLogin() {
[1].increment();
}You increment the existing counter object, not create or get a new one each time.
Fix the error in the code to record a timer metric for method execution time.
Timer timer = Timer.builder("[1]") .description("Execution time of processData") .register(meterRegistry); public void processData() { timer.[2](() -> { // processing logic }); }
time instead of record for timing code blocks.The timer metric name should be descriptive and use underscores. The method to record execution time with a Runnable is record.
Fill both blanks to create a gauge metric that tracks the current size of a queue.
Gauge.builder("[1]", queue, [2]) .description("Current size of the task queue") .register(meterRegistry);
queue.size() directly instead of passing a method reference.The gauge name should be descriptive and use underscores. The method reference queue::size correctly provides the current size.
Fill all three blanks to create a custom meter with tags and record a value.
DistributionSummary summary = DistributionSummary.builder("[1]") .description("Response sizes") .tags("endpoint", "[2]") .register(meterRegistry); summary.[3](responseSize);
count instead of record to add values.The metric name should be descriptive. Tags add context like the endpoint. Use record to add a new value to the summary.