2

我正在尝试使用prometheus 导出器来检测 java 应用程序sbt-native-packager

这就是我所拥有的:

插件.sbt

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.5.1")

构建.sbt

import com.typesafe.sbt.packager.docker.DockerChmodType
dockerChmodType := DockerChmodType.UserGroupWriteExecute
enablePlugins(JavaServerAppPackaging, AshScriptPlugin, DockerPlugin)
settings(moduleName := "my-test")
settings(mainClass in Compile := Some("org.name.demo.stream.MyTestClass"))
dockerBaseImage := "openjdk:8-jre-alpine"
daemonUser in Docker    := "test"

根据普罗米修斯出口商文档,我想将出口商作为一个 java 代理:

java -javaagent:./jmx_prometheus_javaagent-0.12.0.jar=8080:config.yaml -jar my-test_2.12-0.1.jar

我可以通过 来做这个仪器sbt-native-packager吗?欣赏输入。

4

1 回答 1

0

plugins.sbt中使用https://github.com/sbt/sbt-javaagent

addSbtPlugin("com.lightbend.sbt" % "sbt-javaagent" % "0.1.6")

然后在build.sbt

val MyAppSettings = Seq(
  name := "My",
  dockerBaseImage := "adoptopenjdk:11-jre-hotspot",
  mainClass := Some("com.MyClass"),
  packageName in Docker := "mycontainer",
  libraryDependencies ++= myDependencies,
  javaAgents += JavaAgent("io.prometheus.jmx" % "jmx_prometheus_javaagent" % "0.16.1", arguments = "33002:/opt/docker/jmx-exporter.yaml"),
  mappings in Universal ++= Seq(
    file("jmx-exporter.yaml") -> "jmx-exporter.yaml"
  )
)

lazy val myProject = (project in file("my-project"))
  .settings(MyAppSettings)
  .enablePlugins(JavaAppPackaging, JavaAgent)

于 2021-08-19T19:46:30.913 回答