You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2022/05/20 01:13:32 UTC

[GitHub] [ozone] kerneltime commented on a diff in pull request #3430: HDDS-6705 Add metrics for volume statistics including disk capacity, usage, Reserved

kerneltime commented on code in PR #3430:
URL: https://github.com/apache/ozone/pull/3430#discussion_r877651130


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/VolumeInfoStats.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.container.common.volume;
+
+import org.apache.hadoop.metrics2.MetricsSystem;
+import org.apache.hadoop.metrics2.annotation.Metric;
+import org.apache.hadoop.metrics2.annotation.Metrics;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
+import org.apache.hadoop.ozone.OzoneConsts;
+
+/**
+ * This class is used to track Volume IO stats for each HDDS Volume.
+ */
+@Metrics(about = "Ozone Volume Information Metrics", context = OzoneConsts.OZONE)
+public class VolumeInfoStats {
+
+    private String metricsSourceName = VolumeInfoStats.class.getSimpleName();
+    private String VolumeRootStr;
+    private HddsVolume volume;
+
+    private @Metric MutableGaugeLong spaceUsed;
+    private @Metric MutableGaugeLong spaceAvailable;
+    private @Metric MutableGaugeLong spaceReserved;
+    private @Metric MutableGaugeLong capacity;
+    private @Metric MutableGaugeLong totalCapacity;
+
+
+    @Deprecated
+    public VolumeInfoStats() {
+        init();
+    }
+
+    /**
+     * @param identifier Typically, path to volume root. e.g. /data/hdds
+     */
+    public VolumeInfoStats(String identifier, HddsVolume ref) {
+        this.metricsSourceName += '-' + identifier;
+        this.VolumeRootStr = identifier;
+        this.volume = ref;
+        init();
+    }
+
+    public void init() {
+        MetricsSystem ms = DefaultMetricsSystem.instance();
+        ms.register(metricsSourceName, "Volume Info Statistics", this);
+        spaceUsed.set(volume.getVolumeInfo().getScmUsed());
+        spaceAvailable.set(volume.getVolumeInfo().getAvailable());
+        spaceReserved.set(volume.getVolumeInfo().getReservedInBytes());
+        capacity.set(spaceUsed.value() + spaceAvailable.value());
+        totalCapacity.set(
+                spaceUsed.value() + spaceAvailable.value() + spaceReserved.value());
+    }
+
+    public void unregister() {
+        MetricsSystem ms = DefaultMetricsSystem.instance();
+        ms.unregisterSource(metricsSourceName);
+    }
+
+    public String getMetricsSourceName() {
+        return metricsSourceName;
+    }
+
+    /**
+     * Test conservative avail space.
+     * |----used----|   (avail)   |++++++++reserved++++++++|
+     * |<------- capacity ------->|
+     * |<------------------- Total capacity -------------->|
+     * A) avail = capacity - used
+     * B) avail = fsAvail - Max(reserved - other, 0);
+     */

Review Comment:
   This comment seems out of place. The diagram of how space is broken up is quite useful though.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org