Bird
Raised Fist0
Spring Bootframework~20 mins

Prometheus and Grafana integration concept in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Prometheus and Grafana Integration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the primary role of Prometheus in monitoring a Spring Boot application?

Choose the best description of what Prometheus does when integrated with a Spring Boot app.

AIt deploys the Spring Boot application to the cloud.
BIt visualizes the metrics data using dashboards and charts.
CIt collects and stores metrics data from the application for analysis.
DIt automatically fixes performance issues detected in the app.
Attempts:
2 left
💡 Hint

Think about which tool is responsible for gathering data versus showing it.

💻 Command Output
intermediate
1:30remaining
What output does this Prometheus scrape config produce?

Given this Prometheus scrape configuration snippet, what is the target URL Prometheus will scrape?

Spring Boot
scrape_configs:
  - job_name: 'springboot-app'
    static_configs:
      - targets: ['localhost:8080']
APrometheus scrapes metrics from http://localhost:8080/metrics
BPrometheus scrapes metrics from http://localhost:8080/api/metrics
CPrometheus scrapes metrics from http://localhost:9090/metrics
DPrometheus scrapes metrics from http://localhost:8080/monitor
Attempts:
2 left
💡 Hint

Prometheus defaults to scraping the /metrics path unless overridden.

❓ Configuration
advanced
1:30remaining
Which Spring Boot property enables Prometheus metrics endpoint?

Select the correct property to enable Prometheus metrics endpoint in application.properties.

Amanagement.endpoints.web.exposure.include=prometheus
Bspring.metrics.export.prometheus.enabled=false
Cmanagement.endpoint.prometheus.enabled=false
Dspring.boot.metrics.prometheus.endpoint=true
Attempts:
2 left
💡 Hint

Look for the property that exposes endpoints over web.

🔀 Workflow
advanced
2:00remaining
What is the correct order to integrate Prometheus and Grafana with Spring Boot?

Arrange these steps in the right order to set up monitoring with Prometheus and Grafana for a Spring Boot app.

A1,3,2,4
B3,1,2,4
C2,1,3,4
D1,2,3,4
Attempts:
2 left
💡 Hint

Think about enabling metrics first, then scraping, then visualization.

❓ Troubleshoot
expert
2:00remaining
Why does Grafana show 'No data' for Spring Boot metrics despite Prometheus scraping successfully?

Prometheus scrapes Spring Boot metrics without errors, but Grafana dashboards show 'No data'. What is the most likely cause?

ASpring Boot metrics endpoint is disabled
BGrafana data source is not set to Prometheus or has wrong URL
CPrometheus scrape interval is too long
DGrafana dashboards are not refreshed automatically
Attempts:
2 left
💡 Hint

Check the connection between Grafana and Prometheus.

Practice

(1/5)
1. What is the primary role of Prometheus in a Spring Boot application monitoring setup?
easy
A. To collect metrics by scraping the application's exposed endpoint
B. To visualize metrics using dashboards
C. To expose application metrics automatically
D. To send alerts directly to users

Solution

  1. Step 1: Understand Prometheus function

    Prometheus collects metrics by scraping HTTP endpoints exposed by applications.
  2. Step 2: Differentiate roles of tools

    Grafana is used for visualization, not collection. Spring Boot exposes metrics but does not collect them.
  3. Final Answer:

    To collect metrics by scraping the application's exposed endpoint -> Option A
  4. Quick 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
A. spring-boot-starter-web
B. spring-boot-starter-data-jpa
C. micrometer-registry-prometheus
D. spring-boot-starter-security

Solution

  1. Step 1: Identify metrics registry dependency

    Micrometer provides metrics support; the Prometheus registry enables exposing metrics in Prometheus format.
  2. Step 2: Exclude unrelated dependencies

    Web starter is for REST APIs, JPA for database, Security for auth; none expose Prometheus metrics.
  3. Final Answer:

    micrometer-registry-prometheus -> Option C
  4. Quick 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:
management.endpoints.web.exposure.include=health,prometheus
management.endpoint.prometheus.enabled=true

What will be the URL path to scrape metrics for Prometheus?
medium
A. /metrics
B. /actuator/metrics
C. /prometheus/metrics
D. /actuator/prometheus

Solution

  1. Step 1: Understand actuator endpoint exposure

    Spring Boot exposes actuator endpoints under /actuator by default.
  2. Step 2: Identify Prometheus endpoint path

    Prometheus metrics endpoint is /actuator/prometheus when enabled and exposed.
  3. Final Answer:

    /actuator/prometheus -> Option D
  4. Quick 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
A. Prometheus server is down but Grafana is running
B. Prometheus is not scraping the correct endpoint URL
C. Spring Boot app does not have a database connection
D. Grafana does not support Prometheus data sources

Solution

  1. Step 1: Check Prometheus scraping configuration

    If Prometheus scrapes wrong URL, no metrics collected, so Grafana shows nothing.
  2. Step 2: Exclude other causes

    Grafana supports Prometheus; database unrelated; if Prometheus down, Grafana shows errors.
  3. Final Answer:

    Prometheus is not scraping the correct endpoint URL -> Option B
  4. Quick 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
A. rate(http_server_requests_seconds_sum[5m]) / rate(http_server_requests_seconds_count[5m])
B. sum(http_server_requests_seconds_sum) / sum(http_server_requests_seconds_count)
C. avg_over_time(http_server_requests_seconds_sum[5m])
D. count_over_time(http_server_requests_seconds_count[5m])

Solution

  1. Step 1: Understand metrics for response time

    http_server_requests_seconds_sum is total time; count is number of requests.
  2. Step 2: Calculate average over 5 minutes

    Use rate() to get per-second increase, then divide sum by count for average.
  3. Final Answer:

    rate(http_server_requests_seconds_sum[5m]) / rate(http_server_requests_seconds_count[5m]) -> Option A
  4. Quick 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
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard