Skip to content

Commit b9068e1

Browse files
committed
Add database query monitoring metrics
1 parent 53818ef commit b9068e1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.springframework.samples.petclinic.monitoring;
2+
3+
import io.micrometer.core.instrument.MeterRegistry;
4+
import io.micrometer.core.instrument.Timer;
5+
import org.aspectj.lang.ProceedingJoinPoint;
6+
import org.aspectj.lang.annotation.Around;
7+
import org.aspectj.lang.annotation.Aspect;
8+
import org.springframework.stereotype.Component;
9+
10+
@Aspect
11+
@Component
12+
public class DatabaseMetrics {
13+
private final MeterRegistry registry;
14+
15+
public DatabaseMetrics(MeterRegistry registry) {
16+
this.registry = registry;
17+
}
18+
19+
@Around("execution(* org.springframework.samples.petclinic.activity.ClinicActivityController.*(..))")
20+
public Object measureQueryTime(ProceedingJoinPoint joinPoint) throws Throwable {
21+
Timer.Sample sample = Timer.start(registry);
22+
try {
23+
return joinPoint.proceed();
24+
} finally {
25+
sample.stop(Timer.builder("clinic.activity.query.time")
26+
.description("Time taken for clinic activity queries")
27+
.tag("method", joinPoint.getSignature().getName())
28+
.register(registry));
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)