我正在尝试配置基于 Akka 2.6.10 的项目,以将度量值公开给 Prometheus。我看到了这个使用Kamon的问题,但我无法弄清楚我的配置中缺少什么。我的文件具有以下配置:build.sbt
name := """explore-akka"""
version := "1.1"
scalaVersion := "2.12.7"
val akkaVersion = "2.6.10"
lazy val kamonVersion = "2.1.9"
libraryDependencies ++= Seq(
// Akka basics
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion,
// Metrics: Kamon + Prometheus
"io.kamon" %% "kamon-core" % kamonVersion,
"io.kamon" %% "kamon-akka" % kamonVersion,
"io.kamon" %% "kamon-prometheus" % kamonVersion
)
和plugins.sbt
:
resolvers += Resolver.bintrayRepo("kamon-io", "sbt-plugins")
addSbtPlugin("io.kamon" % "sbt-aspectj-runner" % "1.1.1")
我添加了application.conf
:
kamon.instrumentation.akka.filters {
actors.track {
includes = [ "CounterSystem/user/Counter**" ]
}
}
然后我启动一个调用 counterActor 的 MainClass:
object MainClass extends App {
Kamon.registerModule("akka-test", new PrometheusReporter())
Kamon.init()
CounterActor.run()
}
import akka.actor.{Actor, ActorSystem, Props}
import kamon.Kamon
object CounterActor extends App {
run()
def run() = {
import Counter._
val actorSystem = ActorSystem("CounterSystem")
val countActor = actorSystem.actorOf(Props[Counter], "Counter")
(1 to 100).foreach { v =>
Thread.sleep(1000)
countActor ! Increment
}
(1 to 50).foreach { v =>
Thread.sleep(1000)
countActor ! Decrement
}
countActor ! Print
}
class Counter extends Actor {
import Counter._
val counter = Kamon.counter("my-counter")
var count = 0
override def receive: Receive = {
case Increment =>
count += 1
println(s"incrementing... $count")
counter.withoutTags().increment()
case Decrement =>
count -= 1
println(s"decrementing... $count")
counter.withoutTags().increment()
case Print =>
sender() ! count
println(s"[counter] current count is: $count")
}
}
object Counter {
case object Increment
case object Decrement
case object Print
}
}
我认为在此之后我可以使用Prometheus 控制台 ( http://127.0.0.1:9090/graphsbt run
) 启动应用程序并收听指标,但我看不到任何与我的演员相关的指标。我的猜测是我必须在 prometheus 文件中配置。我对吗?我应该如何配置它?scrape_config
/etc/prometheus/prometheus.yml