Skip to content

Commit

Permalink
FDP-1811: Add cache size monitoring
Browse files Browse the repository at this point in the history
Signed-off-by: Jasper Kamerling <[email protected]>
  • Loading branch information
jasperkamerling committed Dec 7, 2023
1 parent 17b5deb commit 5fe8938
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
package org.gxf.soapbridge.application.services;

import java.util.concurrent.ConcurrentHashMap;

import jakarta.annotation.PostConstruct;
import org.gxf.soapbridge.monitoring.MonitoringService;
import org.gxf.soapbridge.soap.clients.Connection;
import org.gxf.soapbridge.soap.exceptions.ConnectionNotFoundInCacheException;
import org.slf4j.Logger;
Expand All @@ -21,6 +24,17 @@ public class ConnectionCacheService {
*/
private static final ConcurrentHashMap<String, Connection> cache = new ConcurrentHashMap<>();

private final MonitoringService monitoringService;

public ConnectionCacheService(MonitoringService monitoringService) {
this.monitoringService = monitoringService;
}

@PostConstruct
public void postConstructor() {
monitoringService.monitorCacheSize(cache);
}

/**
* Creates a connection and puts it in the cache.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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
Expand All @@ -15,6 +16,11 @@ class MonitoringService(
private const val METRIC_PREFIX = "gxf.soap.bridge"
}

fun monitorCacheSize(cache: Map<*, *>) =
Gauge
.builder("${METRIC_PREFIX}.cache.size", cache) { it.size.toDouble() }
.register(registry)

fun recordConnectionTime(startTime: Instant, context: String, successful: Boolean) {
val duration = Duration.between(startTime, Instant.now())

Expand Down

0 comments on commit 5fe8938

Please sign in to comment.