0
0
Spring Bootframework~10 mins

Metrics with Micrometer in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a counter metric using Micrometer.

Spring Boot
Counter counter = Counter.builder("[1]")
    .description("Counts user logins")
    .register(meterRegistry);
Drag options to blanks, or click blank then click option'
Auser_logins_total
BloginCounter
CuserLoginCount
DcounterUserLogins
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase instead of snake_case for metric names.
Using variable names instead of metric names.
2fill in blank
medium

Complete the code to increment the counter when a user logs in.

Spring Boot
public void onUserLogin() {
    [1].increment();
}
Drag options to blanks, or click blank then click option'
AmeterRegistry.counter("user_logins_total")
BCounter.builder("user_logins_total")
Ccounter
DmeterRegistry.get("user_logins_total")
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to create a new counter inside the method.
Using meterRegistry.counter() inside the method instead of the existing counter.
3fill in blank
hard

Fix the error in the code to record a timer metric for method execution time.

Spring Boot
Timer timer = Timer.builder("[1]")
    .description("Execution time of processData")
    .register(meterRegistry);

public void processData() {
    timer.[2](() -> {
        // processing logic
    });
}
Drag options to blanks, or click blank then click option'
Aprocess_data_time
Brecord
CrecordCallable
Dtime
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase for metric names.
Using time instead of record for timing code blocks.
4fill in blank
hard

Fill both blanks to create a gauge metric that tracks the current size of a queue.

Spring Boot
Gauge.builder("[1]", queue, [2])
    .description("Current size of the task queue")
    .register(meterRegistry);
Drag options to blanks, or click blank then click option'
Atask_queue_size
Bqueue::size
Cqueue.size()
DgetSize
Attempts:
3 left
💡 Hint
Common Mistakes
Calling queue.size() directly instead of passing a method reference.
Using camelCase for metric names.
5fill in blank
hard

Fill all three blanks to create a custom meter with tags and record a value.

Spring Boot
DistributionSummary summary = DistributionSummary.builder("[1]")
    .description("Response sizes")
    .tags("endpoint", "[2]")
    .register(meterRegistry);

summary.[3](responseSize);
Drag options to blanks, or click blank then click option'
Aresponse_size_bytes
B/api/data
Crecord
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using count instead of record to add values.
Using generic or unclear metric names.