0

I try to setup a performance metrics tool with one of our new service built with Scala. I use Dropwizard Metrics since it is a popular one. The following code can't get compiled

@Timed
get("/greeting", operation(dummy)){
  val name: Option[String] = params.get("name")
  Ok(String.format("Hello %s", name.getOrElse(defaultName)))
} 

and the error message is

[error] ... expected start of definition
[error]   get("/greeting", operation(dummy)){
[error]   ^
[error] one error found

Can Dropwizard Metrics be integrated with Scalatra? If yes, what is the right way to integrate?

TeeKai
  • 671
  • 2
  • 10
  • 20

2 Answers2

0

There is already built in support for metrics:

http://www.scalatra.org/2.4/guides/monitoring/metrics.html

About your code, it is not working with the annotation because you are not defining a method here, but invoking one.

marcospereira
  • 12,045
  • 3
  • 46
  • 52
  • Thanks for the info. I will look into the document. Not follow the last comment though. – TeeKai Aug 08 '16 at 15:24
  • The document isn't correct in regarding of the library. "org.scalatra" %% "scalatra-metrics" % "2.4.0-SNAPSHOT" yields a unfound dependency error. It should be "org.scalatra" %% "scalatra-metrics" % "2.4.1". – TeeKai Aug 08 '16 at 17:23
  • Also, none of context.mountMetricsAdminServlet("/metrics-admin") context.mountHealthCheckServlet("/health") context.mountMetricsServlet("/metrics") context.mountThreadDumpServlet("/thread-dump") context.installInstrumentedFilter("/test/*") (stated in the document )are valid code. – TeeKai Aug 08 '16 at 18:10
0

As of version "org.scalatra" % "scalatra-metrics_2.11" % "2.5.0" you can make context.mountMetricsAdminServlet("/metrics-admin") working by adding next import:

import org.scalatra.metrics.MetricsSupportExtensions.metricsSupportExtensions

It will implicitly run this:

metricsSupportExtensions(context).mountMetricsAdminServlet("/metrics-admin")
pringi
  • 3,987
  • 5
  • 35
  • 45
Yuriy P
  • 1,330
  • 9
  • 16