-
Notifications
You must be signed in to change notification settings - Fork 222
Description
I am trying to record metrics of aerospike via micrometer client.
So for example if I need to record the connections stats as a gauge I would need to declare it like
Gauge.builder(MetricName.AEROSPIKE_SYNC_CONNECTION_STATS, node, c -> c.sync.closed)
.tags("state", CLOSED)
.description("Aerospike sync connection closed stats")
.register(meterRegistry);Node I can touch the node instance here, once the guage is configured it is done, it will keep monitoring the node.
I can set this up at the start of the client, but when new nodes get added or removed, this is not changed.
If I would have had a listener of when the node is added or removed, I can create a new gauge with the new instance and remove the old one respectively from recording via micrometer.
There exists a MetricListener with the help of which I can somewhat achieve this, in a way:
public class AerospikeMetricListener implements MetricsListener {
private final Map<String, Node> nodeMap = new ConcurrentHashMap<>();
@Override
public void onEnable(Cluster cluster, MetricsPolicy policy) {
for (var node : cluster.getNodes()) {
nodeMap.put(node.getName(), node);
}
}
@Override
public void onSnapshot(Cluster cluster) {
for (var node : cluster.getNodes()) {
nodeMap.putIfAbsent(node.getName(), node);
}
}
@Override
public void onNodeClose(Node node) {
nodeMap.remove(node.getName());
}
@Override
public void onDisable(Cluster cluster) {
nodeMap.clear();
}
}Now when I know there is a new entry, I can start tracking the gauge. But this metric listener also starts recording the aerospike internal latency metrics as well on which I don't have much control and managing this listener is like an added responsibility for the client.
I think aerospike can provide listeners on addition and deletion of new nodes and moreover if possible I would say do provide the micromerter implementation itself, because that will help larger audience to consistently track client metrics.