-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FDP-94: Add monitoring and small fixes #9
Changes from 9 commits
46408ff
e6b053a
4ee659a
3e77b6a
17b5deb
5fe8938
bb3dff0
537a951
1d14ae8
72682d2
abd1b02
dfed231
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is dit voldoende om ook bijv. fail-rates uit te halen? Of moeten we wat counters toeveoegen? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is het überhaupt nodig om fouten te timen? Kunnen we niet gerichter timeouts, technische exceptions etc. 'counten'? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.gxf.soapbridge.monitoring | ||
|
||
import io.micrometer.core.instrument.Gauge | ||
import io.micrometer.core.instrument.MeterRegistry | ||
import io.micrometer.core.instrument.Timer | ||
import org.springframework.stereotype.Service | ||
import java.time.Duration | ||
import java.time.Instant | ||
|
||
@Service | ||
class MonitoringService( | ||
private val registry: MeterRegistry | ||
) { | ||
|
||
companion object { | ||
private const val METRIC_PREFIX = "gxf.soap.bridge" | ||
const val CACHE_SIZE_METRIC = "${METRIC_PREFIX}.cache.size" | ||
const val CONNECTION_TIMER_METRIC = "${METRIC_PREFIX}.cache.size" | ||
|
||
const val CONNECTION_TIMER_CONTEXT_TAG = "context" | ||
const val CONNECTION_TIMER_SUCCESSFUL_TAG = "successful" | ||
|
||
} | ||
|
||
/** | ||
* Creates a gauge to monitor the size of a cache. | ||
* | ||
* @param cache The cache to monitor, represented as a Map. | ||
* @return A Gauge object that measures the size of the cache. | ||
*/ | ||
fun monitorCacheSize(cache: Map<*, *>) = | ||
Gauge | ||
.builder(CACHE_SIZE_METRIC, cache) { it.size.toDouble() } | ||
.register(registry) | ||
|
||
/** | ||
* Records the connection time for a request. | ||
* | ||
* @param startTime The start time of the request. | ||
* @param context The context of the request. | ||
* @param successful Flag indicating if the request was successful. | ||
*/ | ||
fun recordConnectionTime(startTime: Instant, context: String, successful: Boolean) { | ||
sanderv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val duration = Duration.between(startTime, Instant.now()) | ||
|
||
Timer | ||
.builder(CONNECTION_TIMER_METRIC) | ||
.description("Counts the request time of a soap call") | ||
.tag(CONNECTION_TIMER_CONTEXT_TAG, context) | ||
.tag(CONNECTION_TIMER_SUCCESSFUL_TAG, successful.toString()) | ||
.register(registry) | ||
.record(duration) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mogelijk is het nuttiger om errors te tellen. Eventueel naast het meten van de duratie.