performancecopilot/parfait

Automatic Totalizer AggregateCounter

tallpsmith opened this issue · 0 comments

From tallpsm...@gmail.com on December 20, 2010 13:37:41

Cowan had a nice idea for an AggregateCounter that does in built totalizing of a set of ‘Instance Domains":

Counter bulkCounter = AggregatedCounters.aggregate(registry, "elasticsearch.index.bulk", "elasticsearch.index.buik.shard" + shardId, Unit.ONE, ...);

with something like:

CompositeCounter aggregate(MonitorableRegistry registry, String topLevel, String subLevel, Unit...) { Monitorable existingCounter = registry.getMonitorable(topLevel);
if (existingCounter == null) {
// Create the counter
} else if (! existingCounter instanceof Counter) {
// Uh-oh, there's an existing metric that's not actually a counter. What idiot made that?
throw new IdiotException();
}

  Counter newCounter = new MonitoredCounter(subLevel, registry, unit....);
  return CompositeCounter.of((Counter) existingCounter, newCounter);
}

? It's not THAT clean but I think it works fine in this case -- just specify the 'bulk' counter at 'sub' counter creation time, but if it already exists reuse it.

Original issue: http://code.google.com/p/parfait/issues/detail?id=5