I’ve been working with the performance log files perfstat.log and perfstat-ui.log. I’ve noticed though that these don’t log the different types of Rest API calls that we are using (Entity Create/Update, Login, Queries, Service calls). Is there a way to start including the Rest API calls in the performance logs?
Thanks.
gorbunkov
(Maxim Gorbunkov)
December 3, 2018, 8:08am
#3
You can create an aspect for that.
Add an ‘aspectj’ dependency to the web module configuration in the build.gradle:
compile('org.aspectj:aspectjrt:1.9.1')
Create a rest-dispatcher-spring.xml in your project:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<bean id="performanceLogInterceptor" class="com.company.restaop.web.sys.PerformanceLogInterceptor"/>
<aop:config>
<aop:aspect id="myPerformanceLogMethodAspect" ref="performanceLogInterceptor">
<aop:around method="aroundInvoke" pointcut="target(com.haulmont.restapi.controllers.EntitiesController)"/>
</aop:aspect>
</aop:config>
</beans>
Register the rest-dispatcher-spring.xml in web-app.properties:
cuba.restSpringContextConfig = +com/company/restaop/rest-dispatcher-spring.xml
The PerformanceLogInterceptor class:
package com.haulmont.cuba.core.sys;
import org.aspectj.lang.ProceedingJoinPoint;
import org.perf4j.StopWatch;
import org.perf4j.slf4j.Slf4JStopWatch;
public class PerformanceLogInterceptor {
@SuppressWarnings({"UnusedDeclaration", "UnnecessaryLocalVariable"})
private Object aroundInvoke(ProceedingJoinPoint ctx) throws Throwable {
StopWatch stopWatch = new Slf4JStopWatch(ctx.getSignature().toShortString());
try {
stopWatch.start();
Object res = ctx.proceed();
return res;
} finally {
stopWatch.stop();
}
}
}
Change the pointcut of the aspect to make it handle all invocation you need (the example handles only invocations to EntititiesController class)