// process.events.processed will have a tag like "input.queue://PurchaseFlow/reader/queue" which indicates
// where the processed event came from. So first get the aggregate count for events processed and all the
// queues they came from. Next, for all those queues, get the aggregate count for events they wrote,
// and subtract the two to get queue length.
AggregatesScanner scanner = aggregatesTable.scan(metricsRequest.getContextPrefix(),
"process.events.processed",
metricsRequest.getRunId(),
"input");
long processed = 0;
Set<String> streamNames = Sets.newHashSet();
Set<ImmutablePair<String, String>> queueNameContexts = Sets.newHashSet();
while (scanner.hasNext()) {
AggregatesScanResult scanResult = scanner.next();
processed += scanResult.getValue();
// tag is of the form input.[queueURI]. ex: input.queue://PurchaseFlow/reader/queue
String tag = scanResult.getTag();
// strip the preceding "input." from the tag.
QueueName queueName = QueueName.from(URI.create(tag.substring(6, tag.length())));