File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
src/main/java/org/springframework/samples/petclinic/monitoring Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments