我正在学习如何使用Kamon库进行仪器化。
这是我的build.sbt
libraryDependencies ++= Seq(
"io.kamon" %% "kamon-core" % "0.6.7"
)
这是我的plugins.sbt(在项目文件夹中)
addSbtPlugin("io.kamon" % "sbt-aspectj-runner" % "1.0.1")
这是我的代码
import kamon.Kamon
object KamonTest extends App {
Kamon.start()
val counter = Kamon.metrics.counter("foo")
1 to 100000 foreach { x =>
Thread.sleep(10)
counter.increment()
}
readLine()
print("press any key to exit")
readLine()
Kamon.shutdown()
}
现在,当我运行此应用并运行jmc
然后进入MBEAN浏览器时。我看到了这个
所以我找不到我在代码中定义的计数器“foo”。
答案 0 :(得分:0)
我能够通过Kamon的gitter频道帮助解决这个问题
为了发布到JMX控制台,我们在build.sbt中需要以下两个依赖项
"io.kamon" %% "kamon-scala" % "0.6.7",
"io.kamon" %% "kamon-jmx" % "0.6.7"
我们还需要application.conf
中的以下条目kamon.jmx {
subscriptions {
histogram = [ "**" ]
min-max-counter = [ "**" ]
gauge = [ "**" ]
counter = [ "**" ]
trace = [ "**" ]
trace-segment = [ "**" ]
system-metric = [ "**" ]
http-server = [ "**" ]
kamon-mxbeans = [ "**" ]
}
}
kamon.modules {
kamon-mxbeans {
auto-start = yes
requires-aspectj = no
extension-class = "kamon.jmx.extension.JMXMetricImporter"
}
}
kamon.kamon-mxbeans {
mbeans = [
{ "name": "example-mbean", "jmxQuery": "example:type=myBean,name=*",
"attributes": [
{ "name": "foo", "type": "counter" }
]
}
],
identify-delay-interval-ms = 1000,
identify-interval-ms = 1000,
value-check-interval-ms = 1000
}