Created
January 12, 2012 14:19
-
-
Save huljas/1600772 to your computer and use it in GitHub Desktop.
Aspect for monitoring all @controller spring controllers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.jamonapi.Monitor; | |
import com.jamonapi.MonitorFactory; | |
import org.apache.commons.lang.StringUtils; | |
import org.aspectj.lang.ProceedingJoinPoint; | |
import org.aspectj.lang.annotation.Around; | |
import org.aspectj.lang.annotation.Aspect; | |
import org.aspectj.lang.reflect.MethodSignature; | |
import org.springframework.stereotype.Component; | |
import java.util.regex.Pattern; | |
/** | |
* @author huljas | |
*/ | |
@Component | |
@Aspect | |
public class MonitoredSpringBeanAspect { | |
@Around(value = "@within(org.springframework.stereotype.Controller)") | |
public Object monitorClass(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { | |
return doMonitor(proceedingJoinPoint, "Controller"); | |
} | |
protected Object doMonitor(ProceedingJoinPoint proceedingJoinPoint, String label) throws Throwable { | |
MethodSignature signature = (MethodSignature) proceedingJoinPoint.getSignature(); | |
// In case of proxies we split the ugly $$ part away | |
String className = proceedingJoinPoint.getTarget().getClass().getSimpleName().split(Pattern.quote("$$"))[0]; | |
String methodName = signature.getMethod().getName(); | |
Monitor monitor = MonitorFactory.startPrimary(label + ": " + className + "." + methodName); | |
try { | |
return proceedingJoinPoint.proceed(); | |
} finally { | |
monitor.stop(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment