prathmesh12-coder commented on code in PR #10576: URL: https://github.com/apache/ozone/pull/10576#discussion_r3459820047
########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/VolumeUtilizationMetrics.java: ########## @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.ozone.om; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import org.apache.hadoop.hdds.annotation.InterfaceAudience; +import org.apache.hadoop.hdds.utils.db.cache.CacheKey; +import org.apache.hadoop.hdds.utils.db.cache.CacheValue; +import org.apache.hadoop.metrics2.MetricsCollector; +import org.apache.hadoop.metrics2.MetricsInfo; +import org.apache.hadoop.metrics2.MetricsSource; +import org.apache.hadoop.metrics2.MetricsSystem; +import org.apache.hadoop.metrics2.annotation.Metrics; +import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; +import org.apache.hadoop.ozone.OzoneConsts; +import org.apache.hadoop.ozone.om.helpers.OmBucketInfo; +import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs; + +/** + * A class for collecting and reporting volume utilization metrics. + * <p> + * Available metrics: + * <ul> + * <li>Volume quota in bytes. + * <li>Volume used bytes (aggregated from all buckets in the volume). + * <li>Volume available bytes. Calculated from difference between volume quota and used bytes. + * If volume quota is not set then this metric shows -1 as value. + * <li>Volume quota in namespace (maximum number of buckets). + * <li>Volume used namespace (current number of buckets). + * </ul> + */ [email protected] +@Metrics(about = "Ozone Volume Utilization Metrics", context = OzoneConsts.OZONE) +public class VolumeUtilizationMetrics implements MetricsSource { + + private static final String SOURCE = VolumeUtilizationMetrics.class.getSimpleName(); + + private final OMMetadataManager metadataManager; + + public VolumeUtilizationMetrics(OMMetadataManager metadataManager) { + this.metadataManager = metadataManager; + } + + public static VolumeUtilizationMetrics create(OMMetadataManager metadataManager) { + MetricsSystem ms = DefaultMetricsSystem.instance(); + return ms.register(SOURCE, "Volume Utilization Metrics", new VolumeUtilizationMetrics(metadataManager)); + } + + @Override + public void getMetrics(MetricsCollector collector, boolean all) { + Map<String, OmVolumeArgs> volumes = new HashMap<>(); + Iterator<Entry<CacheKey<String>, CacheValue<OmVolumeArgs>>> volumeIterator = metadataManager.getVolumeIterator(); + while (volumeIterator.hasNext()) { + Entry<CacheKey<String>, CacheValue<OmVolumeArgs>> entry = volumeIterator.next(); + OmVolumeArgs volumeArgs = entry.getValue().getCacheValue(); + if (volumeArgs != null) { + volumes.put(volumeArgs.getVolume(), volumeArgs); + } + } + + Map<String, Long> usedBytesPerVolume = new HashMap<>(); + Iterator<Entry<CacheKey<String>, CacheValue<OmBucketInfo>>> bucketIterator = metadataManager.getBucketIterator(); + while (bucketIterator.hasNext()) { + Entry<CacheKey<String>, CacheValue<OmBucketInfo>> entry = bucketIterator.next(); + OmBucketInfo bucketInfo = entry.getValue().getCacheValue(); + if (bucketInfo == null) { + continue; + } + usedBytesPerVolume.merge(bucketInfo.getVolumeName(), bucketInfo.getUsedBytes(), Long::sum); + } Review Comment: Hi @errose28, Thanks for the feedback! Removed the VolumeUsedBytes and VolumeAvailableBytes metrics along with the aggregation logic. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
