use of org.apache.samza.metrics.Gauge in project samza by apache.
the class StreamPartitionCountMonitor method updatePartitionCountMetric.
/**
* Fetches the current partition count for each system stream from the cache, compares the current count to the
* original count and updates the metric for that system stream with the delta.
*/
void updatePartitionCountMetric() {
try {
Map<SystemStream, SystemStreamMetadata> currentMetadata = getMetadata(streamsToMonitor, metadataCache);
for (Map.Entry<SystemStream, SystemStreamMetadata> metadataEntry : initialMetadata.entrySet()) {
SystemStream systemStream = metadataEntry.getKey();
SystemStreamMetadata metadata = metadataEntry.getValue();
int currentPartitionCount = currentMetadata.get(systemStream).getSystemStreamPartitionMetadata().keySet().size();
int prevPartitionCount = metadata.getSystemStreamPartitionMetadata().keySet().size();
Gauge gauge = gauges.get(systemStream);
gauge.set(currentPartitionCount - prevPartitionCount);
}
} catch (Exception e) {
log.error("Exception while updating partition count metric.", e);
}
}
Aggregations