blob: a823d5b9f45dec99491aeab5cce27adaad58e21c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
package akka
import org.aspectj.lang.annotation._
import scala.concurrent.duration._
import com.newrelic.api.agent.NewRelic
@Aspect("perthis(mailboxMonitor())")
class MailboxAspect extends ActorSystemHolder {
@Pointcut("execution(akka.dispatch.Mailbox.new(..)) && !within(MailboxAspect)")
protected def mailboxMonitor():Unit = {}
@Before("mailboxMonitor() && this(mb)")
def before(mb: akka.dispatch.Mailbox) : Unit = {
actorSystem.scheduler.schedule(5 seconds, 6 second, new Runnable {
def run() {
val actorName = mb.actor.self.path.toString
println(s"Sending metrics to Newrelic MailBoxMonitor -> ${actorName}")
NewRelic.recordMetric(s"${actorName}:Mailbox:NumberOfMessages",mb.numberOfMessages)
NewRelic.recordMetric(s"${actorName}:Mailbox:MailboxDispatcherThroughput",mb.dispatcher.throughput)
NewRelic.addCustomParameter(s"${actorName}:Mailbox:Status", mb.hasMessages.toString)
NewRelic.addCustomParameter(s"${actorName}:Mailbox:HasMessages", mb.hasMessages.toString)
}
})
}
}
|