-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
code example for Reporters #63
Comments
They're fairly straight-forward to set up. Enhancing the manual example a little bit: object YourApplication {
/** The application wide metrics registry. */
val metricRegistry = {
val registry = new com.codahale.metrics.MetricRegistry()
ConsoleReporter.forRegistry(registry)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build()
.start(1, TimeUnit.MINUTES)
registry
}
} |
thank you @scullxbones for responding. I am still new to this package so excuse the basic question, when I integrated your code above into the example, I still do not see anything being sent to the console , here is the code : import com.codahale.metrics.ConsoleReporter
import com.codahale.metrics.Timer
import java.util.concurrent.TimeUnit;
object YourApplication {
/** The application wide metrics registry. */
val metricRegistry = {
val registry = new com.codahale.metrics.MetricRegistry()
ConsoleReporter.forRegistry(registry)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build()
.start(1, TimeUnit.MINUTES)
registry
}
}
trait Instrumented extends nl.grons.metrics.scala.InstrumentedBuilder {
val metricRegistry = YourApplication.metricRegistry
}
class Example(db: List[Int]) extends Instrumented {
private[this] val loading = metrics.timer("loading")
def loadStuff(): Seq[Int] = loading.time {
val k = (1 to 100)
k.toSeq
}
}
object metric extends Instrumented {
def main(args: Array[String]) {
val o = new Example(List(1)).loadStuff()
}
}
|
Sure, happy to help. Note the timing of the reporter - |
uh... that was really a rocky mistake :) modified my code as such and it worked fine : import com.codahale.metrics.ConsoleReporter
import com.codahale.metrics.Timer
import java.util.concurrent.TimeUnit;
object YourApplication {
/** The application wide metrics registry. */
val metricRegistry = {
val registry = new com.codahale.metrics.MetricRegistry()
ConsoleReporter.forRegistry(registry)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build()
.start(1, TimeUnit.SECONDS) //changed the interval to seconds instead of minutes
registry
}
}
trait Instrumented extends nl.grons.metrics.scala.InstrumentedBuilder {
val metricRegistry = YourApplication.metricRegistry
}
class Example(db: List[Int]) extends Instrumented {
private[this] val loading = metrics.timer("loading")
def loadStuff(): Seq[Int] = loading.time {
val k = (1 to 100)
k.toSeq
}
}
object metric extends Instrumented {
def wait5Seconds() {
try {
Thread.sleep(5 * 1000);
} catch {
case e: InterruptedException =>
}
}
def main(args: Array[String]) {
val o = new Example(List(1)).loadStuff()
wait5Seconds //forced program to wait for 5 seconds
}
} thanks again. |
Hi @hhadind , can we close this issue? |
sure thanks again. |
Very helpful. Recommend reopening this, since no Reporter examples are currently in the Manual. |
Hi @atz, a pull request would be amazing! |
any examples for using reporters like the ConsoleReporter or the CvsReporter ?
thanks in advance.
The text was updated successfully, but these errors were encountered: