diff options
author | Diego Parra <dparra@despegar.com> | 2013-05-31 16:10:50 -0300 |
---|---|---|
committer | Diego Parra <dparra@despegar.com> | 2013-05-31 16:10:50 -0300 |
commit | e737bdf5cf87e2ce6a03754a88b68bd87a78678b (patch) | |
tree | a600a0f5b5d6fd37fa18ccd4ac1f0f3891404854 /src/main/scala | |
parent | 38316a2b0b3a58b81cf7458b0a719980136bbb97 (diff) | |
download | Kamon-e737bdf5cf87e2ce6a03754a88b68bd87a78678b.tar.gz Kamon-e737bdf5cf87e2ce6a03754a88b68bd87a78678b.tar.bz2 Kamon-e737bdf5cf87e2ce6a03754a88b68bd87a78678b.zip |
WIP:Metrics2 to Metrics3 Migration
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/akka/ActorAspect.scala | 48 | ||||
-rw-r--r-- | src/main/scala/kamon/metric/AkkaMetrics.scala | 1 | ||||
-rw-r--r-- | src/main/scala/kamon/metric/Metrics.scala | 48 | ||||
-rw-r--r-- | src/main/scala/kamon/metric/MetricsUtils.scala | 42 | ||||
-rw-r--r-- | src/main/scala/kamon/metric/NewRelicReporter.scala | 41 |
5 files changed, 98 insertions, 82 deletions
diff --git a/src/main/scala/akka/ActorAspect.scala b/src/main/scala/akka/ActorAspect.scala index 05a7bc0a..ae21aa13 100644 --- a/src/main/scala/akka/ActorAspect.scala +++ b/src/main/scala/akka/ActorAspect.scala @@ -1,26 +1,46 @@ package akka -import org.aspectj.lang.annotation.{Around, Pointcut, Aspect} +import actor.ActorCell +import org.aspectj.lang.annotation.{After, Around, Pointcut, Aspect} import org.aspectj.lang.ProceedingJoinPoint -import kamon.metric.Metrics +import kamon.metric.Metrics.{ metricsRegistry => meterRegistry } +import com.codahale.metrics.Meter +import kamon.metric.MetricsUtils._ -@Aspect -class ActorAspect extends Metrics { - println("Created ActorAspect") +@Aspect("perthis(actorCellCreation(*))") +class ActorAspect { - @Pointcut("execution(* akka.actor.ActorCell+.receiveMessage(..))") - protected def actorReceive:Unit = {} + /** + * Aspect members + */ - @Around("sendingMessageToActorRef() && this(actor)") - def around(pjp: ProceedingJoinPoint, actor: akka.actor.ActorCell): AnyRef = { + private val actorMeter:Meter = new Meter - //println("The path is: "+actor.self.path.) - val actorName:String = actor.self.path.toString + /** + * Pointcuts + */ + @Pointcut("execution(akka.actor.ActorCell+.new(..)) && this(actor)") + def actorCellCreation(actor:ActorCell):Unit = {} + @Pointcut("execution(* akka.actor.ActorCell+.receiveMessage(..))") + def actorReceive():Unit = {} - markAndCountMeter(actorName){ - pjp.proceed - } + /** + * Advices + */ + @After("actorCellCreation(actor)") + def afterCellCreation(actor:ActorCell):Unit ={ + val actorName:String = actor.self.path.toString + + meterRegistry.register(s"meter-for-${actorName}", actorMeter) + } + @Around("actorReceive()") + def around(pjp: ProceedingJoinPoint) = { + import pjp._ + + markMeter(actorMeter) { + proceed + } } }
\ No newline at end of file diff --git a/src/main/scala/kamon/metric/AkkaMetrics.scala b/src/main/scala/kamon/metric/AkkaMetrics.scala deleted file mode 100644 index de647c07..00000000 --- a/src/main/scala/kamon/metric/AkkaMetrics.scala +++ /dev/null @@ -1 +0,0 @@ -package kamon.metric diff --git a/src/main/scala/kamon/metric/Metrics.scala b/src/main/scala/kamon/metric/Metrics.scala index 4cbe25e1..cf04659b 100644 --- a/src/main/scala/kamon/metric/Metrics.scala +++ b/src/main/scala/kamon/metric/Metrics.scala @@ -1,48 +1,14 @@ package kamon.metric -import com.yammer.metrics.core.{MetricName, MetricsRegistry} -import scala.collection.mutable.{HashMap,SynchronizedMap} -import com.yammer.metrics.scala.{Meter, Counter, MetricsGroup, Timer} -import com.yammer.metrics.reporting.{ConsoleReporter, JmxReporter} -import scala.collection.mutable import java.util.concurrent.TimeUnit +import com.codahale.metrics._ -class Metrics { - private lazy val metricsRegistry: MetricsRegistry = new MetricsRegistry() - private lazy val metricsGroup = new MetricsGroup(this.getClass, metricsRegistry) +object Metrics { + val metricsRegistry: MetricRegistry = new MetricRegistry - private lazy val meters = new mutable.HashMap[String, Meter] with SynchronizedMap[String, Meter] - private lazy val timers = new HashMap[String, Timer] with SynchronizedMap[String, Timer] - private lazy val counters = new HashMap[String, Counter] with SynchronizedMap[String, Counter] + val consoleReporter = ConsoleReporter.forRegistry(metricsRegistry) + val newrelicReporter = NewRelicReporter(metricsRegistry) - val consoleReporter = ConsoleReporter.enable(metricsRegistry, 1, TimeUnit.SECONDS) - val newrelicReport = new NewRelicReporter(metricsRegistry, "newrelic-reporter"); - - newrelicReport.run() - newrelicReport.start(1, TimeUnit.SECONDS) - - def incrementCounter(key: String) { - counters.getOrElseUpdate(key, (metricsGroup.counter(s"${key}-counter"))).count - } - - def markMeter(key: String) { - meters.getOrElseUpdate(key, metricsGroup.meter(s"${key}-meter", "actor", "actor-message-counter", TimeUnit.SECONDS)).mark() - } - - def trace[T](key: String)(f: => T): T = { - val timer = timers.getOrElseUpdate(key, (metricsGroup.timer(s"${key}-timer")) ) - timer.time(f) - } - - def markAndCountMeter[T](key: String)(f: => T): T = { - markMeter(key) - f - } - - def traceAndCount[T](key: String)(f: => T): T = { - incrementCounter(key) - trace(key) { - f - } - } + newrelicReporter.start(5, TimeUnit.SECONDS) + consoleReporter.build().start(5, TimeUnit.SECONDS) }
\ No newline at end of file diff --git a/src/main/scala/kamon/metric/MetricsUtils.scala b/src/main/scala/kamon/metric/MetricsUtils.scala new file mode 100644 index 00000000..fc72dcf3 --- /dev/null +++ b/src/main/scala/kamon/metric/MetricsUtils.scala @@ -0,0 +1,42 @@ +package kamon.metric + +import com.codahale.metrics._ + +object MetricsUtils { + + def markMeter[T](meter:Meter)(f: => T): T = { + meter.mark() + f + } +// +// def incrementCounter(key: String) { +// counters.getOrElseUpdate(key, (metricsGroup.counter(s"${key}-counter"))).count +// } +// +// def markMeter(key: String) { +// meters.getOrElseUpdate(key, metricsGroup.meter(s"${key}-meter", "actor", "actor-message-counter", TimeUnit.SECONDS)).mark() +// } +// +// def trace[T](key: String)(f: => T): T = { +// val timer = timers.getOrElseUpdate(key, (metricsGroup.timer(s"${key}-timer")) ) +// timer.time(f) +// } + +// def markAndCountMeter[T](key: String)(f: => T): T = { +// markMeter(key) +// f +// } +// +// def traceAndCount[T](key: String)(f: => T): T = { +// incrementCounter(key) +// trace(key) { +// f +// } + //} + +// private val actorCounter:Counter = new Counter +// private val actorTimer:Timer = new Timer +// +// metricsRegistry.register(s"counter-for-${actorName}", actorCounter) +// metricsRegistry.register(s"timer-for-${actorName}", actorTimer) +}
\ No newline at end of file diff --git a/src/main/scala/kamon/metric/NewRelicReporter.scala b/src/main/scala/kamon/metric/NewRelicReporter.scala index 7684a746..76c901f5 100644 --- a/src/main/scala/kamon/metric/NewRelicReporter.scala +++ b/src/main/scala/kamon/metric/NewRelicReporter.scala @@ -1,36 +1,25 @@ package kamon.metric +import com.codahale.metrics._ +import java.util.concurrent.TimeUnit +import java.util import com.newrelic.api.agent.NewRelic -import com.yammer.metrics.reporting.AbstractPollingReporter -import com.yammer.metrics.core._ -import scala.collection.JavaConversions._ - - -class NewRelicReporter(registry: MetricsRegistry, name: String) extends AbstractPollingReporter(registry, name) with MetricProcessor[String] { - - def processMeter(name: MetricName, meter: Metered, context: String) { - println(s"Logging to NewRelic: ${meter.count()}") - NewRelic.recordMetric("Custom/Actor/MessagesPerSecond", meter.meanRate().toFloat) +import scala.collection.JavaConverters._ +class NewRelicReporter(registry: MetricRegistry, name: String,filter: MetricFilter, rateUnit: TimeUnit, durationUnit: TimeUnit) extends ScheduledReporter(registry, name, filter, rateUnit, durationUnit) { + def processMeter(name: String, meter: Meter) { + println(s"Logging to NewRelic: ${meter.getCount()}") + NewRelic.recordMetric("Custom/Actor/MessagesPerSecond", meter.getMeanRate().toFloat) } - - def processCounter(name: MetricName, counter: Counter, context: String) {} - - def processHistogram(name: MetricName, histogram: Histogram, context: String) {} - - def processTimer(name: MetricName, timer: Timer, context: String) {} - - def processGauge(name: MetricName, gauge: Gauge[_], context: String) {} - - - def run() { - for (entry <- getMetricsRegistry.groupedMetrics(MetricPredicate.ALL).entrySet) { - for (subEntry <- entry.getValue.entrySet) { - subEntry.getValue.processWith(this, subEntry.getKey, "") - } - } + def report(gauges: util.SortedMap[String, Gauge[_]], counters: util.SortedMap[String, Counter], histograms: util.SortedMap[String, Histogram], meters: util.SortedMap[String, Meter], timers: util.SortedMap[String, Timer]) { + //Process Meters + meters.asScala.map{case(k,v) => processMeter(k,v)} } } + +object NewRelicReporter { + def apply(registry: MetricRegistry) = new NewRelicReporter(registry, "NewRelic-reporter", MetricFilter.ALL, TimeUnit.SECONDS, TimeUnit.MILLISECONDS) +}
\ No newline at end of file |