问题
I tried to integrate kamon-prometheus with akka stream project but at http://localhost:9095/ it loads an empty page.In the console I could see the message that metrics information is available at http://localhost:9095/. When I tried with akka quickstart project, it worked fine.
Is kamon supported for akka streams?
回答1:
Kamon uses aspecj heavily to gather some of the metrics. Please make sure that java agent aspectj-weaver is added to the boot of you JVM. See different options in this documentation.
You also need to add dependencies to build.sbt
libraryDependencies += "io.kamon" %% "kamon-core" % "1.1.0"
libraryDependencies += "io.kamon" %% "kamon-prometheus" % "1.0.0"
Disable built-in server in kamon-prometheus by changing this setting key in application.conf file.
kamon.prometheus.start-embedded-http-server = no
Add PrometheusReporter to Kamon
    import kamon.Kamon
    import kamon.prometheus.PrometheusReporter
    
    private val reporter = new PrometheusReporter()
    private val registry = Kamon.addReporter(reporter)
And serve results of metrics with akka-http by defining a route and getting data from reporter.scrapeData().
     val metrics = path("metrics") {
      encodeResponse {
        val prometheusContentType: ContentType.NonBinary = {
          ContentType.parse("text/plain; version=0.0.4; charset=utf-8").right.get.asInstanceOf[ContentType.NonBinary]
        }
        Kamon.gauge("metrics_called").increment()
        complete(
          HttpResponse(
            status = StatusCodes.OK,
            entity = HttpEntity(prometheusContentType, reporter.scrapeData())
          )
        )
      }
    }
Or serve metrics to any incoming http request with code
    akka.http.scaladsl
      .Http(actorSystem)
      .bindAndHandleSync(
        _ => {
          Kamon.gauge("metrics_called").increment()
          HttpResponse(
            status = StatusCodes.OK,
            entity = HttpEntity(prometheusContentType, reporter.scrapeData())
          )
        },
        "0.0.0.0",
        9015
      )
In case if you receive blank page, make sure that Kamon gathers some metrics in the system. You could test this by adding Kamon.gauge("metrics_called").increment() into a http route for example.
回答2:
I was trying to run Main from Intellij and that was the reason why I did not get the metrics.With the suggestion from @Ivan Stanislavciuc , I tried sbt run and it worked.
来源:https://stackoverflow.com/questions/54072038/akka-stream-kamon-prometheus-not-returning-any-metrics-but-loads-an-empty-page