title: How do you configure prometheus.yml file to collect Prometheus metrics in a Spring-Boot application?
body: <p>I have a simple Maven Spring-Boot Application (Java) and am using Prometheus to collect metric information from it. I have all of the necessary Prometheus dependencies in my pom file, and I have included the @EnablePrometheusEndpoint annotation to my @SpringBootApplication class, and have included "metrics_path: '/prometheus' " in my prometheus.yml file (as shown below), but am receiving a 406 error when I try to access the metrics (on localhost:8080/prometheus). How should i modify my prometheus.yml file to see my exported metrics? </p>
  
  <p>Below is all of the (simple) spring boot code I am looking to instrument:</p>
  
  <pre><code>@SpringBootApplication
  @RestController
  @EnablePrometheusEndpoint
  public class Example {
  
      //Just a logger that keeps track of relevant information:
      private static final Logger LOGGER = Logger.getLogger(Example.class.getName());
  
      //counter for counting how many times an endpoint has been hit
      static final Counter myCounter = Counter.build()    
                                                .name("CounterName") //note: by convention, counters should have "_total" suffix
                                                .help("Total requests recorded by a specific endpoint")
                                                .labelNames("status")
                                                .register();
      @RequestMapping("/hello")
      String hello() {
  
          myCounter.labels("customLabel1").inc(); //increment the number of requests by one
          LOGGER.log(Level.INFO, "Number of times /hello has been hit: " + myCounter.labels("customLabel1").get());
  
          return "Hello world! This is an example response!";
      }
  
      @RequestMapping("/homepage")
      String homePage() {
  
          myCounter.labels("customLabel2").inc(); //increment the number of requests by one
          LOGGER.log(Level.INFO, "Number of times /homepage has been hit: " + myCounter.labels("customLabel2").get());
  
          return "this is the home page!!";
      }
  
  
      public static void main(String[] args) throws Exception {
          SpringApplication.run(Example.class, args);
      }
  
  }
  </code></pre>
  
  <p>pom.xml file with all required prometheus dependencies:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;springboot&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.5.8.RELEASE&lt;/version&gt;
      &lt;/parent&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
  
          &lt;!-- Prometheus dependencies --&gt;
          &lt;!-- The client --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.prometheus&lt;/groupId&gt;
              &lt;artifactId&gt;simpleclient&lt;/artifactId&gt;
              &lt;version&gt;0.1.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;io.prometheus&lt;/groupId&gt;
              &lt;artifactId&gt;simpleclient_spring_boot&lt;/artifactId&gt;
              &lt;version&gt;0.1.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;io.prometheus&lt;/groupId&gt;
              &lt;artifactId&gt;simpleclient_servlet&lt;/artifactId&gt;
              &lt;version&gt;0.1.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- Hotspot JVM metrics --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.prometheus&lt;/groupId&gt;
              &lt;artifactId&gt;simpleclient_hotspot&lt;/artifactId&gt;
              &lt;version&gt;0.1.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- Exposition HTTPServer --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.prometheus&lt;/groupId&gt;
              &lt;artifactId&gt;simpleclient_httpserver&lt;/artifactId&gt;
              &lt;version&gt;0.1.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- Pushgateway exposition --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.prometheus&lt;/groupId&gt;
              &lt;artifactId&gt;simpleclient_pushgateway&lt;/artifactId&gt;
              &lt;version&gt;0.1.0&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Spring Boot Actuator for exposing metrics --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
              &lt;version&gt;1.5.8.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
  
      &lt;/dependencies&gt;
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p>And below is my prometheus.yml file. note, the last few lines are where I specified to prometheus what to scrape, and i suspect this is where my problem is: </p>
  
  <pre><code># my global config
  global:
    scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
    evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
    # scrape_timeout is set to the global default (10s).
  
    # Attach these labels to any time series or alerts when communicating with
    # external systems (federation, remote storage, Alertmanager).
    external_labels:
        monitor: 'codelab-monitor'
  
  # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
  rule_files:
    # - "first.rules"
    # - "second.rules"
  
  # A scrape configuration containing exactly one endpoint to scrape:
  # Here it's Prometheus itself.
  scrape_configs:
    # The job name is added as a label `job=&lt;job_name&gt;` to any timeseries scraped from this config.
    - job_name: 'prometheus'
  
      # metrics_path defaults to '/metrics'
      # scheme defaults to 'http'.
      scrape_interval: 5s
  
      static_configs:
        - targets: ['localhost:9090']
  
  #The following lines are meant to monitor my  spring boot app
    - job_name: 'hello_world_spring_boot'
      scrape_interval: 5s
  
      metrics_path: '/prometheus'
  
      static_configs:
        - targets: ['localhost:8080']
  </code></pre>