Reputation: 119
I'm implementing Hazelcast caching in my service using Spring boot cache and I want to send hit and miss metrics to my Datadog.
I tried to enable statistics and JMX but it didn't work.
my hazelcast.yaml
:
hazelcast:
network:
join:
multicast:
enabled: false
tcp-ip:
enabled: false
# change these 2 lines and set kubernetes enabled to false for local debug
# enabled: true
# members: 127.0.0.1
kubernetes:
enabled: true
namespace: my-namespace
service-name: my-service
metrics:
enabled: true
jmx:
enabled: true
map:
default:
statistics-enabled: true
time-to-live-seconds: 86400
eviction:
max-size-policy: PER_NODE
eviction-policy: LFU
size: 200000
application.yaml:
management:
endpoint:
health:
probes:
enabled: true
metrics:
export:
statsd:
enabled: true
flavor: datadog
port: 8125
host: ${HOST_IP}
The cache is working properly, and other metrics are being sent to datadog as expected
I Then found that there is a way to add a custom listener for example EntryListener but I'm not sure how to utilize it to send hit and miss since it listens on added, update, removed, evicted, expired and cleared events so added probably can be utilized to send miss event, but what about update?
My last resort is to create a sync method that send periodically map metrics to DD which I really want to avoid
Upvotes: 0
Views: 428
Reputation: 119
Found a solution for that -
Micrometer provides HazelcastCacheMetrics
that let's you monitor Hazelcast caches to a MeterRegistry
in the following way:
import com.hazelcast.core.HazelcastInstance;
import io.micrometer.core.instrument.ImmutableTag;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.binder.cache.HazelcastCacheMetrics;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.List;
@Component
@RequiredArgsConstructor
public class HazelcastMetricBinder {
public static String My_CACHE_NAME = "MyCacheName";
private final MeterRegistry meterRegistry;
private final HazelcastInstance hazelcastInstance;
@PostConstruct
void monitorHazelcastCacheMetrics() {
List<Tag> tags = List.of(new ImmutableTag("cacheName", My_CACHE_NAME));
HazelcastCacheMetrics.monitor(meterRegistry, hazelcastInstance.getMap(My_CACHE_NAME), tags);
}
}
Upvotes: 1