Kamon uses aspecj heavily to gather some of the metrics. Please make sure that java agent aspectj-weaver is added to the boot of you JVM. See different options in this documentation.
You also need to add dependencies to build.sbt
libraryDependencies += "io.kamon" %% "kamon-core" % "1.1.0"
libraryDependencies += "io.kamon" %% "kamon-prometheus" % "1.0.0"
Disable built-in server in kamon-prometheus
by changing this setting key in application.conf
file.
kamon.prometheus.start-embedded-http-server = no
Add PrometheusReporter
to Kamon
import kamon.Kamon
import kamon.prometheus.PrometheusReporter
private val reporter = new PrometheusReporter()
private val registry = Kamon.addReporter(reporter)
And serve results of metrics with akka-http
by defining a route and getting data from reporter.scrapeData()
.
val metrics = path("metrics") {
encodeResponse {
val prometheusContentType: ContentType.NonBinary = {
ContentType.parse("text/plain; version=0.0.4; charset=utf-8").right.get.asInstanceOf[ContentType.NonBinary]
}
Kamon.gauge("metrics_called").increment()
complete(
HttpResponse(
status = StatusCodes.OK,
entity = HttpEntity(prometheusContentType, reporter.scrapeData())
)
)
}
}
Or serve metrics to any incoming http request with code
akka.http.scaladsl
.Http(actorSystem)
.bindAndHandleSync(
_ => {
Kamon.gauge("metrics_called").increment()
HttpResponse(
status = StatusCodes.OK,
entity = HttpEntity(prometheusContentType, reporter.scrapeData())
)
},
"0.0.0.0",
9015
)
In case if you receive blank page, make sure that Kamon
gathers some metrics in the system. You could test this by adding Kamon.gauge("metrics_called").increment()
into a http route for example.