in folsom-semantic-metrics/src/main/java/com/spotify/folsom/client/SemanticFolsomMetrics.java [71:149]
public SemanticFolsomMetrics(final SemanticMetricRegistry registry, final MetricId baseMetricId) {
this.registry = registry;
this.id =
baseMetricId.tagged(
"what", "memcache-results",
"component", "memcache-client");
final MetricId meterId = id.tagged("unit", "operations");
MetricId getId = id.tagged("operation", "get");
this.gets = registry.timer(getId);
// successful gets are broken down by whether a result was found in the cache or not.
// the two meters can be summed to count total number of successes.
MetricId getMetersId = MetricId.join(getId, meterId);
this.getHits = registry.meter(getMetersId.tagged("result", "success", "cache-result", "hit"));
this.getMisses =
registry.meter(getMetersId.tagged("result", "success", "cache-result", "miss"));
this.getFailures = registry.meter(getMetersId.tagged("result", "failure"));
// ratio of cache hits to total attempts
hitRatio =
new RatioGauge() {
@Override
protected Ratio getRatio() {
final double hitRate = getHits.getFiveMinuteRate();
final double missRate = getMisses.getFiveMinuteRate();
return Ratio.of(hitRate, hitRate + missRate);
}
};
// overwrite the 'what' as this metric doesn't make sense to be aggregated against any of the
// other metrics
registry.register(getId.tagged("what", "memcache-hit-ratio", "unit", "%"), hitRatio);
MetricId setId = id.tagged("operation", "set");
this.sets = registry.timer(setId);
MetricId setMetersId = MetricId.join(setId, meterId);
this.setSuccesses = registry.meter(setMetersId.tagged("result", "success"));
this.setFailures = registry.meter(setMetersId.tagged("result", "failure"));
MetricId multigetId = id.tagged("operation", "multiget");
this.multigets = registry.timer(multigetId);
MetricId multigetMetersId = MetricId.join(multigetId, meterId);
this.multigetSuccesses = registry.meter(multigetMetersId.tagged("result", "success"));
this.multigetFailures = registry.meter(multigetMetersId.tagged("result", "failure"));
MetricId deleteId = id.tagged("operation", "delete");
this.deletes = registry.timer(deleteId);
MetricId deleteMetersId = MetricId.join(deleteId, meterId);
this.deleteSuccesses = registry.meter(deleteMetersId.tagged("result", "success"));
this.deleteFailures = registry.meter(deleteMetersId.tagged("result", "failure"));
MetricId incrDecrId = id.tagged("operation", "incr-decr");
this.incrDecrs = registry.timer(incrDecrId);
MetricId incrDecrMetersId = MetricId.join(incrDecrId, meterId);
this.incrDecrSuccesses = registry.meter(incrDecrMetersId.tagged("result", "success"));
this.incrDecrFailures = registry.meter(incrDecrMetersId.tagged("result", "failure"));
MetricId touchId = id.tagged("operation", "touch");
this.touches = registry.timer(touchId);
MetricId touchMetersId = MetricId.join(touchId, meterId);
this.touchSuccesses = registry.meter(touchMetersId.tagged("result", "success"));
this.touchFailures = registry.meter(touchMetersId.tagged("result", "failure"));
final MetricId outstandingRequestGauge =
id.tagged(
"what", "outstanding-requests",
"unit", "requests");
registry.register(
outstandingRequestGauge,
(Gauge<Long>)
() ->
gauges.stream().mapToLong(OutstandingRequestsGauge::getOutstandingRequests).sum());
final MetricId globalConnectionCountGauge =
id.tagged("what", "global-connections", "unit", "connections");
registry.register(globalConnectionCountGauge, (Gauge<Integer>) Utils::getGlobalConnectionCount);
}