0

我正在使用带有 Play 框架 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="/",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)指标,尤其是请求的处理时间。

我能得到这些指标吗?如果是这样,我该怎么做?


基础项目是Play 2.8.x Hello World Projects。完整项目在这里: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());
    }
}
4

0 回答 0