<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nitish</title>
    <description>The latest articles on DEV Community by Nitish (@nitish_95c3a169c005f1d4fe).</description>
    <link>https://dev.to/nitish_95c3a169c005f1d4fe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3972040%2F2c2ef8e0-6271-462e-a118-b7e777d3fe85.png</url>
      <title>DEV Community: Nitish</title>
      <link>https://dev.to/nitish_95c3a169c005f1d4fe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nitish_95c3a169c005f1d4fe"/>
    <language>en</language>
    <item>
      <title>Spring Boot Observability: Real-Time Monitoring with Micrometer and Grafana</title>
      <dc:creator>Nitish</dc:creator>
      <pubDate>Sat, 13 Jun 2026 06:25:26 +0000</pubDate>
      <link>https://dev.to/nitish_95c3a169c005f1d4fe/spring-boot-observability-real-time-monitoring-with-micrometer-and-grafana-38j3</link>
      <guid>https://dev.to/nitish_95c3a169c005f1d4fe/spring-boot-observability-real-time-monitoring-with-micrometer-and-grafana-38j3</guid>
      <description>&lt;p&gt;&lt;br&gt;
Okay, I need to write a technical article about Spring Boot observability with Micrometer and Grafana. The user specified a specific structure, so I should follow that closely. Let me start by understanding the requirements.&lt;/p&gt;

&lt;p&gt;First, the title needs to be SEO-friendly and specific. Maybe something like "Spring Boot Observability: Real-Time Monitoring with Micrometer and Grafana". That's clear and includes the main keywords.&lt;/p&gt;

&lt;p&gt;The pain points: Developers struggle with monitoring Spring Boot apps in production, lack real-time insights, and have difficulty setting up dashboards. I need to phrase this in two sentences.&lt;/p&gt;

&lt;p&gt;Prerequisites: Java 17, Spring Boot 3.x, Docker, Grafana and Prometheus setup, basic Micrometer knowledge. That's three to five bullet points.&lt;/p&gt;

&lt;p&gt;Main section: Explaining how to integrate Micrometer, export to Prometheus, and visualize in Grafana. Need a complete code example. Let me outline the steps. Create a Spring Boot app, add Micrometer and Prometheus dependencies, configure properties, create a sample controller with metrics, set up Prometheus and Grafana via Docker Compose, and create a dashboard.&lt;/p&gt;

&lt;p&gt;Common mistakes: Three mistakes. Maybe not configuring the actuator endpoints, not registering custom metrics correctly, and incorrect Grafana configuration. For each mistake, explain what's wrong and show the fix.&lt;/p&gt;

&lt;p&gt;Summary: Key takeaways about the importance of observability, avoiding common mistakes, and leveraging Grafana for visualization.&lt;/p&gt;

&lt;p&gt;Now, let me structure each part. The code examples need to be complete and compilable. For the main code example, a controller with a custom metric. The dependencies in build.gradle or pom.xml. Since the user didn't specify build tool, maybe use Maven as it's common. But wait, the user mentioned "exact code example". Let me check the Spring Boot 3.x setup. The main class is straightforward. The controller should have a counter metric. Also, the application.properties for enabling actuator endpoints.&lt;/p&gt;

&lt;p&gt;For common mistakes:&lt;/p&gt;

&lt;p&gt;Mistake 1: Not exposing actuator endpoints. The fix is adding management.endpoints.web.exposure.include=prometheus,metrics in properties.&lt;/p&gt;

&lt;p&gt;Mistake 2: Incorrect metric registration. Using Metrics.globalRegistry instead of MeterRegistry. Show the wrong code and then the corrected version with @Autowired MeterRegistry.&lt;/p&gt;

&lt;p&gt;Mistake 3: Not configuring Grafana data source properly. The fix is ensuring Prometheus URL is correct in Grafana's data source config.&lt;/p&gt;

&lt;p&gt;I need to make sure all code snippets have the correct imports. For example, the controller imports io.micrometer.core.instrument.Counter and MeterRegistry.&lt;/p&gt;

&lt;p&gt;Also, the Docker Compose file for Prometheus and Grafana. The Prometheus config file needs to target the Spring Boot app. Grafana's default credentials.&lt;/p&gt;

&lt;p&gt;Check word count. The article should be between 950-1200 words. Each section needs to be concise but thorough.&lt;/p&gt;

&lt;p&gt;Let me start drafting each part step by step, ensuring all rules are followed. No placeholders, all code must be complete. Make sure to use Spring Boot 3.x APIs. For example, in the controller, use @RestController and @GetMapping with Spring Web.&lt;/p&gt;

&lt;p&gt;Double-check the Prometheus configuration YAML file. The scrape config should point to localhost:8080/actuator/prometheus.&lt;/p&gt;

&lt;p&gt;In the Grafana section, explain importing the dashboard ID 4701, which is the Micrometer dashboard.&lt;/p&gt;

&lt;p&gt;For common mistake 2, the incorrect code would be using a global registry without injection, and the fix is using the MeterRegistry bean provided by Spring.&lt;/p&gt;

&lt;p&gt;Alright, putting it all together now. Make sure each code block has the correct language tag. Java for Java code, yaml for application.properties and Prometheus config, and text for Docker Compose maybe? Wait, Docker Compose is YAML as well. So all YAML files use yaml tags.&lt;/p&gt;

&lt;p&gt;Check that all code is correct. For example, the Maven dependencies for Spring Boot Actuator and Micrometer Registry Prometheus.&lt;/p&gt;

&lt;p&gt;Yes, the dependencies would be:&lt;/p&gt;

&lt;p&gt;&lt;br&gt;
    org.springframework.boot&lt;br&gt;
    spring-boot-starter-actuator&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
    io.micrometer&lt;br&gt;
    micrometer-registry-prometheus&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;In the application.properties, management.endpoints.web.exposure.include=prometheus,metrics.&lt;/p&gt;

&lt;p&gt;The controller code with a counter that increments on each request.&lt;/p&gt;

&lt;p&gt;The Prometheus config scrape job.&lt;/p&gt;

&lt;p&gt;Docker Compose file with Prometheus and Grafana services, volumes for config and data.&lt;/p&gt;

&lt;p&gt;Grafana setup steps: login, add data source, import dashboard.&lt;/p&gt;

&lt;p&gt;Common mistakes with code examples showing the wrong and right way.&lt;/p&gt;

&lt;p&gt;Finally, the summary with key points.&lt;/p&gt;

&lt;p&gt;I think that covers all the requirements. Now, write the article following this structure and content.&lt;br&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  Spring Boot Observability: Real-Time Monitoring with Micrometer and Grafana
&lt;/h1&gt;

&lt;p&gt;Production debugging without metrics is like flying blind. This guide solves two critical pain points: instrumenting Spring Boot applications for meaningful metrics collection, and transforming raw data into actionable Grafana dashboards without complex infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Java 17+ and Spring Boot 3.x&lt;/li&gt;
&lt;li&gt;Docker installed for monitoring stack&lt;/li&gt;
&lt;li&gt;Basic understanding of Micrometer metrics&lt;/li&gt;
&lt;li&gt;Grafana Cloud account or local installation&lt;/li&gt;
&lt;li&gt;curl/postman for endpoint testing&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Implementing Metrics Export with Micrometer
&lt;/h2&gt;

&lt;p&gt;First, create a new Spring Boot 3.x application with these dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- pom.xml --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;dependencies&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.springframework.boot&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;spring-boot-starter-web&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.springframework.boot&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;spring-boot-starter-actuator&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;io.micrometer&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;micrometer-registry-prometheus&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependencies&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure actuator endpoints in application.properties:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# application.properties&lt;/span&gt;
&lt;span class="s"&gt;management.endpoints.web.exposure.include=health,info,prometheus,metrics&lt;/span&gt;
&lt;span class="s"&gt;management.metrics.export.prometheus.enabled=true&lt;/span&gt;
&lt;span class="s"&gt;server.port=8080&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a controller with custom metrics:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;io.micrometer.core.instrument.Counter&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;io.micrometer.core.instrument.MeterRegistry&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.web.bind.annotation.GetMapping&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.web.bind.annotation.RestController&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@RestController&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderController&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;Counter&lt;/span&gt; &lt;span class="n"&gt;orderCounter&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;OrderController&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MeterRegistry&lt;/span&gt; &lt;span class="n"&gt;registry&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;orderCounter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Counter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;builder&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"orders.total"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
                                  &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Total orders processed"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
                                  &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;register&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;registry&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/order"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;placeOrder&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;orderCounter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;increment&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Order placed!"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the application and verify metrics at &lt;code&gt;http://localhost:8080/actuator/prometheus&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Monitoring Stack Setup
&lt;/h2&gt;

&lt;p&gt;Create a Docker compose file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# docker-compose.yml&lt;/span&gt;
&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3.8'&lt;/span&gt;

&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;prometheus&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;prom/prometheus:latest&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;9090:9090"&lt;/span&gt;
    &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;./prometheus.yml:/etc/prometheus/prometheus.yml&lt;/span&gt;

  &lt;span class="na"&gt;grafana&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;grafana/grafana-enterprise:latest&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;3000:3000"&lt;/span&gt;
    &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;grafana_data:/var/lib/grafana&lt;/span&gt;

&lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;grafana_data&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure Prometheus scraping:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# prometheus.yml&lt;/span&gt;
&lt;span class="na"&gt;global&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;scrape_interval&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;5s&lt;/span&gt;

&lt;span class="na"&gt;scrape_configs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;job_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;spring-boot'&lt;/span&gt;
    &lt;span class="na"&gt;metrics_path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/actuator/prometheus'&lt;/span&gt;
    &lt;span class="na"&gt;static_configs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;targets&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;host.docker.internal:8080'&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start the stack with &lt;code&gt;docker-compose up -d&lt;/code&gt;. Access Prometheus at &lt;code&gt;http://localhost:9090&lt;/code&gt; and Grafana at &lt;code&gt;http://localhost:3000&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Mistakes
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Mistake 1: Missing Actuator Exposure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Developers enable Micrometer but forget to expose endpoints:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Wrong configuration&lt;/span&gt;
&lt;span class="s"&gt;management.endpoints.web.exposure.include=health,info&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fix by including Prometheus endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# application.properties&lt;/span&gt;
&lt;span class="s"&gt;management.endpoints.web.exposure.include=health,info,prometheus,metrics&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Mistake 2: Manual Metric Registration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Creating metrics without proper Spring integration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Wrong approach&lt;/span&gt;
&lt;span class="nc"&gt;Counter&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Counter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;builder&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"api.calls"&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;register&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Metrics&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;globalRegistry&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inject MeterRegistry instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Correct implementation&lt;/span&gt;
&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;Counter&lt;/span&gt; &lt;span class="n"&gt;apiCounter&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;OrderController&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MeterRegistry&lt;/span&gt; &lt;span class="n"&gt;registry&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;apiCounter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Counter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;builder&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"api.calls"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
                            &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;register&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;registry&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Mistake 3: Grafana Data Source Misconfiguration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using &lt;code&gt;localhost&lt;/code&gt; in Prometheus URL inside Docker:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Wrong Grafana data source
http://localhost:9090
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use Docker's internal networking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Correct configuration
http://prometheus:9090
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Micrometer provides standardized metrics collection across JVM applications&lt;/li&gt;
&lt;li&gt;Proper actuator configuration is crucial for Prometheus scraping&lt;/li&gt;
&lt;li&gt;Grafana dashboards require correct data source networking in containerized environments&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;The author publishes Spring Boot starter templates at &lt;a href="https://gumroad.com" rel="noopener noreferrer"&gt;https://gumroad.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>springboot</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
