Project:
I use Sflow + Ganglia to monitor JVM metrics of Websphere Application Server (WAS). WAS is instrumented using AspectJ aspects. I have added an aspect to measure all application method runtimes.
I use Hsflowd as a JVM metrics collector. Hsflowd internally uses the JMX-SflowAgent javaagent to hook into the JVM to collect metrics using MXBeans (RuntimeMXBean, GarbageCollectorMXBean, CompilationMXBean and ThreadMXBean).
Issue:
When I run WAS without aspectjweaver hook I can see all metrics (CPU, desk, memory, process etc.) in Ganglia web continuously. But when aspectjweaver is added to JVM args and after restarting the server I can see the metrics for 10 mins, but after that it doesn't report JVM metrics in Ganglia web.
In the Aspectj weaving logs I can see that AspectJ is weaving the JMXsflowAgent code. Even though it is exclued via !call(* com.sflow.JMX.SFlowAgent(..))
.
Aspect:
package com.foo.main;
import java.io.*;
import java.lang.reflect.Method;
import java.security.Signature;
import java.util.*;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.osgi.service.application.ApplicationAdminPermission;
@Aspect
public class ResponseTimeAspect {
@Pointcut(
"execution(* com.foo.*(..)) && " +
"!within(com.foo.main.ResponseTimeAspect) && " +
"!within(ThreadLocal+) && " +
"!within(&& !within(*..*Aspect)) && " +
"!within(com.foo.main.AppInformationReader) && " +
"!within(@org.aspectj.lang.annotation.Aspect *) && " +
"!within(com.sflow.jmx.SFlowAgent) && " +
"!(call( * com.sflow.jmx.SFlowAgent(..)))"
)
public void loggingResponseTime() {}
private static ThreadLocal<String> uuidContainer = new ThreadLocal<String>() {
@Override
protected String initialValue(){
return UUID.randomUUID().toString();
}
};
AppInformationReader logWriter = AppInformationReader.getInstance();
@Around("loggingResponseTime()")
public Object tracing(ProceedingJoinPoint thisJoinPoint) throws Throwable {
Long startTime= System.currentTimeMillis();
Long startTotalMemory = Runtime.getRuntime().totalMemory();
Long startFreeMemory = Runtime.getRuntime().freeMemory();
Object ret = thisJoinPoint.proceed();
Long elapsedTime=System.currentTimeMillis() - startTime;
Long endTotalMemory = Runtime.getRuntime().totalMemory();
Long endFreeMemory = Runtime.getRuntime().freeMemory();
String methodSignature=thisJoinPoint.getSignature().toString();
String classname=methodSignature.split("\\.")[thisJoinPoint.getSignature().toString().split("\\.").length-1];
String methodName =thisJoinPoint.getSignature().getDeclaringType().getCanonicalName();
logWriter.writeLog(uuidContainer.get().toString(), startTime, System.currentTimeMillis(), elapsedTime, classname, methodName);
return ret;
}
}
The JMX packages are under com.sflow.jmx.SFlowAgent
.