[英]Akka Stream & Kamon-Prometheus not returning any metrics but loads an empty page
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/ .我尝试将 kamon-prometheus 与 akka 流项目集成,但在http://localhost:9095/它加载了一个空页面。在控制台中,我可以看到度量信息在http://localhost:9095/可用的消息。 When I tried with akka quickstart project, it worked fine.
当我尝试使用 akka quickstart 项目时,它运行良好。
Is kamon supported for akka streams? akka 流是否支持 kamon?
Kamon uses aspecj heavily to gather some of the metrics. Kamon 大量使用 aspecj 来收集一些指标。 Please make sure that java agent aspectj-weaver is added to the boot of you JVM.
请确保将 java 代理 aspectj-weaver 添加到您的 JVM 启动中。 See different options in this documentation .
请参阅本文档中的不同选项。
You also need to add dependencies to build.sbt
您还需要向
build.sbt
添加依赖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.通过更改
application.conf
文件中的此设置键,禁用kamon-prometheus
的内置服务器。
kamon.prometheus.start-embedded-http-server = no
Add PrometheusReporter
to Kamon
将
PrometheusReporter
添加到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()
.并通过定义路由并从
akka-http
reporter.scrapeData()
获取数据来使用akka-http
提供度量结果。
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或使用代码为任何传入的 http 请求提供指标
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.如果您收到空白页,请确保
Kamon
在系统中收集一些指标。 You could test this by adding Kamon.gauge("metrics_called").increment()
into a http route for example.例如,您可以通过将
Kamon.gauge("metrics_called").increment()
到 http 路由来测试这一点。
我试图从 Intellij 运行 Main,这就是我没有得到指标的原因。根据@Ivan Stanislavciuc 的建议,我尝试了sbt run
并且它起作用了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.