Skip to content

Instantly share code, notes, and snippets.

@markon
Created April 29, 2018 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markon/c3cecdf12f083484d0a8fa5d6f987d54 to your computer and use it in GitHub Desktop.
Save markon/c3cecdf12f083484d0a8fa5d6f987d54 to your computer and use it in GitHub Desktop.
AspectJ instrumentation to collect custom metrics for user actors
package metrics.instrumentation
import com.typesafe.config.ConfigFactory
import org.aspectj.lang.annotation._
import org.slf4j.LoggerFactory
import models.messages.CustomActorEvent
import metrics.CustomMetrics
@Aspect
class CustomActorInstrumentation {
private val config = ConfigFactory.load()
@Pointcut("execution(* org.mypackage.actors.CustomActor.aroundReceive(..)) && args(*, msg)")
def onCustomActorMessagePointcut(msg: Any): Unit = {}
@Before("onCustomActorMessagePointcut(msg)")
def onCustomActorMessageHandler(msg: Any): Unit = {
val customMetrics = CustomMetrics.forSystem("my-system")
msg match {
case e: CustomActorEvent =>
customMetrics.customEvent.increment()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment