I would like to add metrics to track the size of number of operations and number of sites, which are stored in values in a service:
import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.stereotype.Service;
@Service
public class TrackerService {
private final AtomicInteger sitesInProgress = new AtomicInteger(0);
private static AtomicInteger amountOfExecutingOperations = new AtomicInteger(0);
public AtomicInteger getSitesInProgress() {
return sitesInProgress;
}
public static AtomicInteger getAmountOfExecutingOperations() {
return amountOfExecutingOperations;
}
}
Is it enough just create a service like that in order to be able to track these values?
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.codahale.metrics.MetricRegistry;
@Service
public class GaugeMetricService {
@Autowired
public GaugeMetricService(final MetricRegistry metricRegistry, final TrackerService trackerService) {
metricRegistry.gauge(MetricRegistry.name("tracker", "sitesInProgress"), () -> () -> trackerServicerackerService.getSitesInProgress());
metricRegistry.gauge(MetricRegistry.name("deviceoperationtracker", "numberOfExecutingOperations"), () -> () -> trackerServicerackerService.getAmountOfExecutingOperations());
}
}
Thanks in advance!