use of io.micrometer.core.annotation.Timed in project micrometer by micrometer-metrics.
the class ScheduledMethodMetrics method timeScheduledOperation.
@Around("execution (@org.springframework.scheduling.annotation.Scheduled * *.*(..))")
public Object timeScheduledOperation(ProceedingJoinPoint pjp) throws Throwable {
Method method = ((MethodSignature) pjp.getSignature()).getMethod();
String signature = pjp.getSignature().toShortString();
if (method.getDeclaringClass().isInterface()) {
try {
method = pjp.getTarget().getClass().getDeclaredMethod(pjp.getSignature().getName(), method.getParameterTypes());
} catch (final SecurityException | NoSuchMethodException e) {
logger.warn("Unable to perform metrics timing on " + signature, e);
return pjp.proceed();
}
}
Timer shortTaskTimer = null;
LongTaskTimer longTaskTimer = null;
for (Timed timed : TimedUtils.findTimedAnnotations(method)) {
if (timed.longTask())
longTaskTimer = LongTaskTimer.builder(timed.value()).tags(timed.extraTags()).description("Timer of @Scheduled long task").register(registry);
else {
Timer.Builder timerBuilder = Timer.builder(timed.value()).tags(timed.extraTags()).description("Timer of @Scheduled task");
if (timed.percentiles().length > 0) {
timerBuilder = timerBuilder.publishPercentiles(timed.percentiles());
}
shortTaskTimer = timerBuilder.register(registry);
}
}
if (shortTaskTimer != null && longTaskTimer != null) {
final Timer finalTimer = shortTaskTimer;
// noinspection NullableProblems
return recordThrowable(longTaskTimer, () -> recordThrowable(finalTimer, pjp::proceed));
} else if (shortTaskTimer != null) {
// noinspection NullableProblems
return recordThrowable(shortTaskTimer, pjp::proceed);
} else if (longTaskTimer != null) {
// noinspection NullableProblems
return recordThrowable(longTaskTimer, pjp::proceed);
}
return pjp.proceed();
}
use of io.micrometer.core.annotation.Timed in project micrometer by micrometer-metrics.
the class TimedUtils method findTimedAnnotations.
public static Set<Timed> findTimedAnnotations(AnnotatedElement element) {
Timed t = AnnotationUtils.findAnnotation(element, Timed.class);
// noinspection ConstantConditions
if (t != null)
return Collections.singleton(t);
TimedSet ts = AnnotationUtils.findAnnotation(element, TimedSet.class);
if (ts != null) {
return Arrays.stream(ts.value()).collect(Collectors.toSet());
}
return Collections.emptySet();
}
Aggregations