问题描述
我在 Play framework 2.8 中使用 kamon (kamon.io)。
我尝试根据“Play Framework Instrumentation”和“Exposing Metrics for Prometheus”设置 kamon,然后它将指标公开为 Prometheus 格式。
但是,它公开了唯一与服务器相关的指标,如下所示:
span_processing_time_seconds_bucket{operation="/",span_kind="server",http_status_code="200",error="false",le="0.005",component="play.server.akka-http",http_method="GET"} 2.0
span_processing_time_seconds_bucket{operation="/",le="0.01",http_method="GET"} 3.0
span_processing_time_seconds_bucket{operation="/",le="0.025",le="0.05",le="0.075",le="0.1",http_method="GET"} 3.0
我想获取客户端(即 WSClient)指标,尤其是请求的处理时间。
我可以获得这些指标吗?如果是这样,我该怎么做?
基础项目是 Play 2.8.x Hello World Projects。完整项目在这里:https://github.com/moznion/play-kamon-prometheus-sample
build.sbt
name := """play-java-hello-world-tutorial"""
organization := "com.example"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava,JavaAgent)
scalaVersion := "2.13.5"
val kamonVersion = "2.1.15"
libraryDependencies += guice
libraryDependencies += ws
libraryDependencies += "io.kamon" %% "kamon-bundle" % kamonVersion
libraryDependencies += "io.kamon" %% "kamon-prometheus" % kamonVersion
application.conf
play.http.secret.key="secret-secret-secret"
kamon {
prometheus {
include-environment-tags = true
embedded-server {
hostname = 0.0.0.0
port = 9095
}
}
}
plugins.sbt
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.8")
addSbtPlugin("io.kamon" % "sbt-kanela-runner-play-2.8" % "2.0.10")
HomeController.java
package controllers;
import play.mvc.*;
import play.libs.ws.WSClient;
import com.google.inject.Inject;
import java.util.concurrent.ExecutionException;
public class HomeController extends Controller {
private static WSClient ws;
@Inject
public HomeController(final WSClient wsClient) {
this.ws = wsClient;
}
public Result index() throws ExecutionException,InterruptedException {
return ok(ws.url("http://127.0.0.1:9095/metrics").get().toCompletableFuture().get().getBody());
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)