Search in sources :

Example 1 with Gauge

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);
    }
}
Also used : SystemStream(org.apache.samza.system.SystemStream) SystemStreamMetadata(org.apache.samza.system.SystemStreamMetadata) HashMap(java.util.HashMap) Map(java.util.Map) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Gauge(org.apache.samza.metrics.Gauge)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Gauge (org.apache.samza.metrics.Gauge)1 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)1 SystemStream (org.apache.samza.system.SystemStream)1 SystemStreamMetadata (org.apache.samza.system.SystemStreamMetadata)1