Comments (8)
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
}
}
from metrics-scala.
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()
}
}
from metrics-scala.
Sure, happy to help.
Note the timing of the reporter - .start(1, TimeUnit.MINUTES)
. I believe this will only write to console every minute. If your example doesn't run that long, you wouldn't see anything. You could try a shorter interval and see if that improves things.
from metrics-scala.
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.
from metrics-scala.
Hi @hhadind , can we close this issue?
from metrics-scala.
sure thanks again.
from metrics-scala.
Very helpful. Recommend reopening this, since no Reporter examples are currently in the Manual.
from metrics-scala.
Hi @atz, a pull request would be amazing!
from metrics-scala.
Related Issues (20)
- Add support for Akka Streams HOT 3
- Version for Scala 2.13.0-RC1 HOT 2
- Scala 2.13.0-RC2 HOT 4
- Releasing with sbt fails due to double uploads HOT 1
- Version for Scala 2.13.0 HOT 1
- MetricName.append breaks in v4 HOT 6
- Spark: Exception in thread "main" java.lang.NoSuchMethodError: com.codahale.metrics.MetricRegistry.timer(Ljava/lang/String;Lcom/codahale/metrics/MetricRegistry$MetricSupplier;)Lcom/codahale/metrics/Timer; HOT 5
- Memory leak on re-registering gauges HOT 11
- Using cachedGauge with Futures HOT 1
- Improve compatibility checks HOT 1
- Scala 3 HOT 6
- Create github release HOT 1
- Make constructors of PushGauge and PushGaugeWithTimeout not private HOT 2
- PushGauge should not throw "A metric named foobar already exists " HOT 2
- Plans for "metrics4-pekko" HOT 1
- support for the new pekko open source akka HOT 1
- Scala/Akka/Dropwizard Metrics app hanging for 10s before shutting down HOT 1
- Version Request: 3.5.9_a2.3 (with akka 2.4.19), or 3.5.9_a2.4 (against Scala 2.11) HOT 1
- Wrong artifact name in Wiki HOT 1
- Upgrade to metrics 5 HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from metrics-scala.