Practice
1. What is the primary role of Prometheus in a Spring Boot application monitoring setup?
easy
Solution
Step 1: Understand Prometheus function
Prometheus collects metrics by scraping HTTP endpoints exposed by applications.Step 2: Differentiate roles of tools
Grafana is used for visualization, not collection. Spring Boot exposes metrics but does not collect them.Final Answer:
To collect metrics by scraping the application's exposed endpoint -> Option AQuick Check:
Prometheus collects metrics = A [OK]
Hint: Remember: Prometheus scrapes, Grafana shows [OK]
Common Mistakes:
- Confusing Grafana as the collector
- Thinking Spring Boot collects metrics
- Assuming Prometheus sends alerts directly
2. Which dependency must be added to a Spring Boot project to expose metrics for Prometheus scraping?
easy
Solution
Step 1: Identify metrics registry dependency
Micrometer provides metrics support; the Prometheus registry enables exposing metrics in Prometheus format.Step 2: Exclude unrelated dependencies
Web starter is for REST APIs, JPA for database, Security for auth; none expose Prometheus metrics.Final Answer:
micrometer-registry-prometheus -> Option CQuick Check:
Prometheus metrics need micrometer-registry-prometheus [OK]
Hint: Add micrometer-registry-prometheus for Prometheus metrics [OK]
Common Mistakes:
- Adding only spring-boot-starter-web without metrics registry
- Confusing JPA or Security starters as metrics providers
- Forgetting to include Prometheus registry dependency
3. Given this Spring Boot application.properties snippet:
What will be the URL path to scrape metrics for Prometheus?
management.endpoints.web.exposure.include=health,prometheus
management.endpoint.prometheus.enabled=trueWhat will be the URL path to scrape metrics for Prometheus?
medium
Solution
Step 1: Understand actuator endpoint exposure
Spring Boot exposes actuator endpoints under /actuator by default.Step 2: Identify Prometheus endpoint path
Prometheus metrics endpoint is /actuator/prometheus when enabled and exposed.Final Answer:
/actuator/prometheus -> Option DQuick Check:
Prometheus metrics at /actuator/prometheus [OK]
Hint: Actuator endpoints default under /actuator [OK]
Common Mistakes:
- Using /metrics instead of /actuator/prometheus
- Assuming /prometheus/metrics is default
- Forgetting to enable prometheus endpoint
4. You configured Prometheus to scrape your Spring Boot app, but metrics are not appearing in Grafana. Which is the most likely cause?
medium
Solution
Step 1: Check Prometheus scraping configuration
If Prometheus scrapes wrong URL, no metrics collected, so Grafana shows nothing.Step 2: Exclude other causes
Grafana supports Prometheus; database unrelated; if Prometheus down, Grafana shows errors.Final Answer:
Prometheus is not scraping the correct endpoint URL -> Option BQuick Check:
Wrong scrape URL blocks metrics flow [OK]
Hint: Verify Prometheus scrape URL matches app endpoint [OK]
Common Mistakes:
- Blaming Grafana for lack of support
- Assuming database affects metrics exposure
- Ignoring Prometheus scrape configuration
5. You want to create a Grafana dashboard showing the average response time of your Spring Boot app over the last 5 minutes. Which Prometheus query should you use?
hard
Solution
Step 1: Understand metrics for response time
http_server_requests_seconds_sum is total time; count is number of requests.Step 2: Calculate average over 5 minutes
Use rate() to get per-second increase, then divide sum by count for average.Final Answer:
rate(http_server_requests_seconds_sum[5m]) / rate(http_server_requests_seconds_count[5m]) -> Option AQuick Check:
Average = sum rate / count rate [OK]
Hint: Divide sum rate by count rate for average response time [OK]
Common Mistakes:
- Using sum without rate causes wrong aggregation
- Using avg_over_time on sum metric alone
- Counting requests instead of averaging time
