-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from Lukinhasssss/feature/custom-metrics
Feature/custom metrics
- Loading branch information
Showing
2 changed files
with
28 additions
and
6 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...re/src/main/kotlin/com/lukinhasssss/admin/catalogo/infrastructure/utils/metrics/Metric.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.lukinhasssss.admin.catalogo.infrastructure.utils.metrics | ||
|
||
import io.micrometer.core.instrument.MeterRegistry | ||
import io.micrometer.core.instrument.Timer | ||
import org.springframework.stereotype.Component | ||
import java.util.concurrent.TimeUnit | ||
import kotlin.system.measureTimeMillis | ||
|
||
@Component | ||
class Metric(private val meterRegistry: MeterRegistry) { | ||
|
||
fun <T> measureExecutionTime(processName: String, block: () -> T): T { | ||
val timer: Timer = meterRegistry.timer("metric_name") | ||
|
||
val result: T | ||
|
||
val duration = measureTimeMillis { | ||
result = block() | ||
} | ||
|
||
timer.record(duration, TimeUnit.MILLISECONDS) | ||
|
||
println(processName) | ||
|
||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters