Metrics not appearing at prometheus endpoint when I'm using micrometer's PrometheusMeterRegistry












0















I'm new to micrometer and prometheus and I'm trying to build my first hello-world application to be monitored using micrometer with prometheus as monitoring backend. But I can't see the metrics by my app (Counters and Timers) appearing on the prometheus endpoint.



I'm following this tutorial for prometheus. I also followed this video for getting started with micrometer.



I downloaded prometheus from this link, extracted it and then ran prometheus to scrap using the command: ./prometheus --config.file=prometheus.yml. I'm having target set in this config file as targets: ['localhost:9090']



Then I ran my Main class which looks like this:



import cern.jet.random.Normal;
import cern.jet.random.engine.MersenneTwister64;
import cern.jet.random.engine.RandomEngine;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.Timer;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
import io.micrometer.core.instrument.logging.LoggingMeterRegistry;
import io.micrometer.jmx.JmxMeterRegistry;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import reactor.core.publisher.Flux;

import java.time.Duration;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {

public static void main(String args) throws InterruptedException {
CompositeMeterRegistry compositeMeterRegistry = new CompositeMeterRegistry();

LoggingMeterRegistry loggingMeterRegistry = SampleMeterRegistries.loggingMeterRegistry();
JmxMeterRegistry jmxMeterRegistry = SampleMeterRegistries.jmxMeterRegistry();
// AtlasMeterRegistry atlasMeterRegistry = SampleMeterRegistries.atlasMeterRegistry();
PrometheusMeterRegistry prometheusMeterRegistry = SampleMeterRegistries.prometheus();

compositeMeterRegistry.add(loggingMeterRegistry);
compositeMeterRegistry.add(jmxMeterRegistry);
// compositeMeterRegistry.add(atlasMeterRegistry);
compositeMeterRegistry.add(prometheusMeterRegistry);


AtomicInteger latencyForThisSecond = new AtomicInteger(0);
Gauge gauge = Gauge.builder("my.guage", latencyForThisSecond, n -> n.get())
.register(compositeMeterRegistry);

Counter counter = Counter
.builder("my.counter")
.description("some description")
.tags("dev", "performance")
.register(compositeMeterRegistry);

Timer timer = Timer.builder("timer")
.publishPercentileHistogram()
.sla(Duration.ofMillis(270))
.register(compositeMeterRegistry);

// colt/colt/1.2.0 is to be added for this.
RandomEngine randomEngine = new MersenneTwister64(0);
Normal incomingRequests = new Normal(0, 1, randomEngine);
Normal duration = new Normal(250, 50, randomEngine);

latencyForThisSecond.set(duration.nextInt());

// For Flux you require io.projectreactor/reactor-core/3.2.3.RELEASE
Flux.interval(Duration.ofSeconds(1))
.doOnEach(d -> {
if (incomingRequests.nextDouble() + 0.4 > 0) {
timer.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS);
}
}).blockLast();

}
}


When I run ./prometheus --config.file=prometheus.yml, I can access the endpoint http://localhost:9090/metrics and also http://localhost:9090/graph. But when I try to execute the query on http://localhost:9090/graph sum(timer_duration_seconds_sum) / sum(timer_duration_seconds_count) it says no datapoints found.



It seems to me that I'm missing something obvious (as I'm a beginner to both of these topics).



Can someone please point out what I'm missing?



I couldn't find (where in my Main class) I have to configure the URI to publish for prometheus. Even if I'm publishing to http://localhost:9090 (which might be default hidden somewhere by micrometer) I couldn't find it.










share|improve this question





























    0















    I'm new to micrometer and prometheus and I'm trying to build my first hello-world application to be monitored using micrometer with prometheus as monitoring backend. But I can't see the metrics by my app (Counters and Timers) appearing on the prometheus endpoint.



    I'm following this tutorial for prometheus. I also followed this video for getting started with micrometer.



    I downloaded prometheus from this link, extracted it and then ran prometheus to scrap using the command: ./prometheus --config.file=prometheus.yml. I'm having target set in this config file as targets: ['localhost:9090']



    Then I ran my Main class which looks like this:



    import cern.jet.random.Normal;
    import cern.jet.random.engine.MersenneTwister64;
    import cern.jet.random.engine.RandomEngine;
    import io.micrometer.core.instrument.Counter;
    import io.micrometer.core.instrument.Gauge;
    import io.micrometer.core.instrument.Timer;
    import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
    import io.micrometer.core.instrument.logging.LoggingMeterRegistry;
    import io.micrometer.jmx.JmxMeterRegistry;
    import io.micrometer.prometheus.PrometheusMeterRegistry;
    import reactor.core.publisher.Flux;

    import java.time.Duration;
    import java.util.concurrent.TimeUnit;
    import java.util.concurrent.atomic.AtomicInteger;

    public class Main {

    public static void main(String args) throws InterruptedException {
    CompositeMeterRegistry compositeMeterRegistry = new CompositeMeterRegistry();

    LoggingMeterRegistry loggingMeterRegistry = SampleMeterRegistries.loggingMeterRegistry();
    JmxMeterRegistry jmxMeterRegistry = SampleMeterRegistries.jmxMeterRegistry();
    // AtlasMeterRegistry atlasMeterRegistry = SampleMeterRegistries.atlasMeterRegistry();
    PrometheusMeterRegistry prometheusMeterRegistry = SampleMeterRegistries.prometheus();

    compositeMeterRegistry.add(loggingMeterRegistry);
    compositeMeterRegistry.add(jmxMeterRegistry);
    // compositeMeterRegistry.add(atlasMeterRegistry);
    compositeMeterRegistry.add(prometheusMeterRegistry);


    AtomicInteger latencyForThisSecond = new AtomicInteger(0);
    Gauge gauge = Gauge.builder("my.guage", latencyForThisSecond, n -> n.get())
    .register(compositeMeterRegistry);

    Counter counter = Counter
    .builder("my.counter")
    .description("some description")
    .tags("dev", "performance")
    .register(compositeMeterRegistry);

    Timer timer = Timer.builder("timer")
    .publishPercentileHistogram()
    .sla(Duration.ofMillis(270))
    .register(compositeMeterRegistry);

    // colt/colt/1.2.0 is to be added for this.
    RandomEngine randomEngine = new MersenneTwister64(0);
    Normal incomingRequests = new Normal(0, 1, randomEngine);
    Normal duration = new Normal(250, 50, randomEngine);

    latencyForThisSecond.set(duration.nextInt());

    // For Flux you require io.projectreactor/reactor-core/3.2.3.RELEASE
    Flux.interval(Duration.ofSeconds(1))
    .doOnEach(d -> {
    if (incomingRequests.nextDouble() + 0.4 > 0) {
    timer.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS);
    }
    }).blockLast();

    }
    }


    When I run ./prometheus --config.file=prometheus.yml, I can access the endpoint http://localhost:9090/metrics and also http://localhost:9090/graph. But when I try to execute the query on http://localhost:9090/graph sum(timer_duration_seconds_sum) / sum(timer_duration_seconds_count) it says no datapoints found.



    It seems to me that I'm missing something obvious (as I'm a beginner to both of these topics).



    Can someone please point out what I'm missing?



    I couldn't find (where in my Main class) I have to configure the URI to publish for prometheus. Even if I'm publishing to http://localhost:9090 (which might be default hidden somewhere by micrometer) I couldn't find it.










    share|improve this question



























      0












      0








      0








      I'm new to micrometer and prometheus and I'm trying to build my first hello-world application to be monitored using micrometer with prometheus as monitoring backend. But I can't see the metrics by my app (Counters and Timers) appearing on the prometheus endpoint.



      I'm following this tutorial for prometheus. I also followed this video for getting started with micrometer.



      I downloaded prometheus from this link, extracted it and then ran prometheus to scrap using the command: ./prometheus --config.file=prometheus.yml. I'm having target set in this config file as targets: ['localhost:9090']



      Then I ran my Main class which looks like this:



      import cern.jet.random.Normal;
      import cern.jet.random.engine.MersenneTwister64;
      import cern.jet.random.engine.RandomEngine;
      import io.micrometer.core.instrument.Counter;
      import io.micrometer.core.instrument.Gauge;
      import io.micrometer.core.instrument.Timer;
      import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
      import io.micrometer.core.instrument.logging.LoggingMeterRegistry;
      import io.micrometer.jmx.JmxMeterRegistry;
      import io.micrometer.prometheus.PrometheusMeterRegistry;
      import reactor.core.publisher.Flux;

      import java.time.Duration;
      import java.util.concurrent.TimeUnit;
      import java.util.concurrent.atomic.AtomicInteger;

      public class Main {

      public static void main(String args) throws InterruptedException {
      CompositeMeterRegistry compositeMeterRegistry = new CompositeMeterRegistry();

      LoggingMeterRegistry loggingMeterRegistry = SampleMeterRegistries.loggingMeterRegistry();
      JmxMeterRegistry jmxMeterRegistry = SampleMeterRegistries.jmxMeterRegistry();
      // AtlasMeterRegistry atlasMeterRegistry = SampleMeterRegistries.atlasMeterRegistry();
      PrometheusMeterRegistry prometheusMeterRegistry = SampleMeterRegistries.prometheus();

      compositeMeterRegistry.add(loggingMeterRegistry);
      compositeMeterRegistry.add(jmxMeterRegistry);
      // compositeMeterRegistry.add(atlasMeterRegistry);
      compositeMeterRegistry.add(prometheusMeterRegistry);


      AtomicInteger latencyForThisSecond = new AtomicInteger(0);
      Gauge gauge = Gauge.builder("my.guage", latencyForThisSecond, n -> n.get())
      .register(compositeMeterRegistry);

      Counter counter = Counter
      .builder("my.counter")
      .description("some description")
      .tags("dev", "performance")
      .register(compositeMeterRegistry);

      Timer timer = Timer.builder("timer")
      .publishPercentileHistogram()
      .sla(Duration.ofMillis(270))
      .register(compositeMeterRegistry);

      // colt/colt/1.2.0 is to be added for this.
      RandomEngine randomEngine = new MersenneTwister64(0);
      Normal incomingRequests = new Normal(0, 1, randomEngine);
      Normal duration = new Normal(250, 50, randomEngine);

      latencyForThisSecond.set(duration.nextInt());

      // For Flux you require io.projectreactor/reactor-core/3.2.3.RELEASE
      Flux.interval(Duration.ofSeconds(1))
      .doOnEach(d -> {
      if (incomingRequests.nextDouble() + 0.4 > 0) {
      timer.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS);
      }
      }).blockLast();

      }
      }


      When I run ./prometheus --config.file=prometheus.yml, I can access the endpoint http://localhost:9090/metrics and also http://localhost:9090/graph. But when I try to execute the query on http://localhost:9090/graph sum(timer_duration_seconds_sum) / sum(timer_duration_seconds_count) it says no datapoints found.



      It seems to me that I'm missing something obvious (as I'm a beginner to both of these topics).



      Can someone please point out what I'm missing?



      I couldn't find (where in my Main class) I have to configure the URI to publish for prometheus. Even if I'm publishing to http://localhost:9090 (which might be default hidden somewhere by micrometer) I couldn't find it.










      share|improve this question
















      I'm new to micrometer and prometheus and I'm trying to build my first hello-world application to be monitored using micrometer with prometheus as monitoring backend. But I can't see the metrics by my app (Counters and Timers) appearing on the prometheus endpoint.



      I'm following this tutorial for prometheus. I also followed this video for getting started with micrometer.



      I downloaded prometheus from this link, extracted it and then ran prometheus to scrap using the command: ./prometheus --config.file=prometheus.yml. I'm having target set in this config file as targets: ['localhost:9090']



      Then I ran my Main class which looks like this:



      import cern.jet.random.Normal;
      import cern.jet.random.engine.MersenneTwister64;
      import cern.jet.random.engine.RandomEngine;
      import io.micrometer.core.instrument.Counter;
      import io.micrometer.core.instrument.Gauge;
      import io.micrometer.core.instrument.Timer;
      import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
      import io.micrometer.core.instrument.logging.LoggingMeterRegistry;
      import io.micrometer.jmx.JmxMeterRegistry;
      import io.micrometer.prometheus.PrometheusMeterRegistry;
      import reactor.core.publisher.Flux;

      import java.time.Duration;
      import java.util.concurrent.TimeUnit;
      import java.util.concurrent.atomic.AtomicInteger;

      public class Main {

      public static void main(String args) throws InterruptedException {
      CompositeMeterRegistry compositeMeterRegistry = new CompositeMeterRegistry();

      LoggingMeterRegistry loggingMeterRegistry = SampleMeterRegistries.loggingMeterRegistry();
      JmxMeterRegistry jmxMeterRegistry = SampleMeterRegistries.jmxMeterRegistry();
      // AtlasMeterRegistry atlasMeterRegistry = SampleMeterRegistries.atlasMeterRegistry();
      PrometheusMeterRegistry prometheusMeterRegistry = SampleMeterRegistries.prometheus();

      compositeMeterRegistry.add(loggingMeterRegistry);
      compositeMeterRegistry.add(jmxMeterRegistry);
      // compositeMeterRegistry.add(atlasMeterRegistry);
      compositeMeterRegistry.add(prometheusMeterRegistry);


      AtomicInteger latencyForThisSecond = new AtomicInteger(0);
      Gauge gauge = Gauge.builder("my.guage", latencyForThisSecond, n -> n.get())
      .register(compositeMeterRegistry);

      Counter counter = Counter
      .builder("my.counter")
      .description("some description")
      .tags("dev", "performance")
      .register(compositeMeterRegistry);

      Timer timer = Timer.builder("timer")
      .publishPercentileHistogram()
      .sla(Duration.ofMillis(270))
      .register(compositeMeterRegistry);

      // colt/colt/1.2.0 is to be added for this.
      RandomEngine randomEngine = new MersenneTwister64(0);
      Normal incomingRequests = new Normal(0, 1, randomEngine);
      Normal duration = new Normal(250, 50, randomEngine);

      latencyForThisSecond.set(duration.nextInt());

      // For Flux you require io.projectreactor/reactor-core/3.2.3.RELEASE
      Flux.interval(Duration.ofSeconds(1))
      .doOnEach(d -> {
      if (incomingRequests.nextDouble() + 0.4 > 0) {
      timer.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS);
      }
      }).blockLast();

      }
      }


      When I run ./prometheus --config.file=prometheus.yml, I can access the endpoint http://localhost:9090/metrics and also http://localhost:9090/graph. But when I try to execute the query on http://localhost:9090/graph sum(timer_duration_seconds_sum) / sum(timer_duration_seconds_count) it says no datapoints found.



      It seems to me that I'm missing something obvious (as I'm a beginner to both of these topics).



      Can someone please point out what I'm missing?



      I couldn't find (where in my Main class) I have to configure the URI to publish for prometheus. Even if I'm publishing to http://localhost:9090 (which might be default hidden somewhere by micrometer) I couldn't find it.







      java prometheus micrometer






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 at 12:20







      Lavish Kothari

















      asked Jan 2 at 8:43









      Lavish KothariLavish Kothari

      865816




      865816
























          1 Answer
          1






          active

          oldest

          votes


















          1















          targets: ['localhost:9090']




          That's Prometheus being asked to scrape itself.



          You need to add a target for the Java application's HTTP endpoint.






          share|improve this answer
























          • @brain-brazil Thanks, that was helpful, now I'm also creating a HttpServer in my Main class as described here. This works for localhost:8080/metrics, but it also gives me the same web-page when I try to access localhost:8080/graph. How can I get the graphs something like this image?

            – Lavish Kothari
            Jan 2 at 12:16






          • 1





            You'll want to use Promethus for that, on localhost:9090

            – brian-brazil
            Jan 2 at 16:03











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003402%2fmetrics-not-appearing-at-prometheus-endpoint-when-im-using-micrometers-prometh%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1















          targets: ['localhost:9090']




          That's Prometheus being asked to scrape itself.



          You need to add a target for the Java application's HTTP endpoint.






          share|improve this answer
























          • @brain-brazil Thanks, that was helpful, now I'm also creating a HttpServer in my Main class as described here. This works for localhost:8080/metrics, but it also gives me the same web-page when I try to access localhost:8080/graph. How can I get the graphs something like this image?

            – Lavish Kothari
            Jan 2 at 12:16






          • 1





            You'll want to use Promethus for that, on localhost:9090

            – brian-brazil
            Jan 2 at 16:03
















          1















          targets: ['localhost:9090']




          That's Prometheus being asked to scrape itself.



          You need to add a target for the Java application's HTTP endpoint.






          share|improve this answer
























          • @brain-brazil Thanks, that was helpful, now I'm also creating a HttpServer in my Main class as described here. This works for localhost:8080/metrics, but it also gives me the same web-page when I try to access localhost:8080/graph. How can I get the graphs something like this image?

            – Lavish Kothari
            Jan 2 at 12:16






          • 1





            You'll want to use Promethus for that, on localhost:9090

            – brian-brazil
            Jan 2 at 16:03














          1












          1








          1








          targets: ['localhost:9090']




          That's Prometheus being asked to scrape itself.



          You need to add a target for the Java application's HTTP endpoint.






          share|improve this answer














          targets: ['localhost:9090']




          That's Prometheus being asked to scrape itself.



          You need to add a target for the Java application's HTTP endpoint.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 2 at 11:48









          brian-brazilbrian-brazil

          15.5k13040




          15.5k13040













          • @brain-brazil Thanks, that was helpful, now I'm also creating a HttpServer in my Main class as described here. This works for localhost:8080/metrics, but it also gives me the same web-page when I try to access localhost:8080/graph. How can I get the graphs something like this image?

            – Lavish Kothari
            Jan 2 at 12:16






          • 1





            You'll want to use Promethus for that, on localhost:9090

            – brian-brazil
            Jan 2 at 16:03



















          • @brain-brazil Thanks, that was helpful, now I'm also creating a HttpServer in my Main class as described here. This works for localhost:8080/metrics, but it also gives me the same web-page when I try to access localhost:8080/graph. How can I get the graphs something like this image?

            – Lavish Kothari
            Jan 2 at 12:16






          • 1





            You'll want to use Promethus for that, on localhost:9090

            – brian-brazil
            Jan 2 at 16:03

















          @brain-brazil Thanks, that was helpful, now I'm also creating a HttpServer in my Main class as described here. This works for localhost:8080/metrics, but it also gives me the same web-page when I try to access localhost:8080/graph. How can I get the graphs something like this image?

          – Lavish Kothari
          Jan 2 at 12:16





          @brain-brazil Thanks, that was helpful, now I'm also creating a HttpServer in my Main class as described here. This works for localhost:8080/metrics, but it also gives me the same web-page when I try to access localhost:8080/graph. How can I get the graphs something like this image?

          – Lavish Kothari
          Jan 2 at 12:16




          1




          1





          You'll want to use Promethus for that, on localhost:9090

          – brian-brazil
          Jan 2 at 16:03





          You'll want to use Promethus for that, on localhost:9090

          – brian-brazil
          Jan 2 at 16:03




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003402%2fmetrics-not-appearing-at-prometheus-endpoint-when-im-using-micrometers-prometh%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

          Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

          A Topological Invariant for $pi_3(U(n))$