我将kamon(kamon.io)与playframework2.8结合使用。
我试着根据“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="/",span_kind="server",http_status_code="200",error="false",le="0.01",component="play.server.akka-http",http_method="GET"} 3.0
span_processing_time_seconds_bucket{operation="/",span_kind="server",http_status_code="200",error="false",le="0.025",component="play.server.akka-http",http_method="GET"} 3.0
span_processing_time_seconds_bucket{operation="/",span_kind="server",http_status_code="200",error="false",le="0.05",component="play.server.akka-http",http_method="GET"} 3.0
span_processing_time_seconds_bucket{operation="/",span_kind="server",http_status_code="200",error="false",le="0.075",component="play.server.akka-http",http_method="GET"} 3.0
span_processing_time_seconds_bucket{operation="/",span_kind="server",http_status_code="200",error="false",le="0.1",component="play.server.akka-http",http_method="GET"} 3.0
我想得到客户端(即wsclient)的度量,特别是请求的处理时间。
我能得到这些指标吗?如果是,我该怎么做?
基本项目是play2.8.xhelloworld项目。完整项目如下:https://github.com/moznion/play-kamon-prometheus-sample
代码和配置提示如下:
构建.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
应用程序.conf
play.http.secret.key="secret-secret-secret"
kamon {
prometheus {
include-environment-tags = true
embedded-server {
hostname = 0.0.0.0
port = 9095
}
}
}
插件.sbt
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.8")
addSbtPlugin("io.kamon" % "sbt-kanela-runner-play-2.8" % "2.0.10")
家庭控制器.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());
}
}
暂无答案!
目前还没有任何答案,快来回答吧!