You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "OneSizeFitsQuorum (via GitHub)" <gi...@apache.org> on 2023/02/17 09:15:12 UTC

[GitHub] [iotdb] OneSizeFitsQuorum commented on a diff in pull request #9054: [IOTDB-5517] Add metrics for disk io

OneSizeFitsQuorum commented on code in PR #9054:
URL: https://github.com/apache/iotdb/pull/9054#discussion_r1109433781


##########
server/src/main/java/org/apache/iotdb/db/service/metrics/DataNodeMetricsHelper.java:
##########
@@ -39,6 +40,7 @@ public static void bind() {
     MetricService.getInstance().addMetricSet(new CompactionMetrics());
     MetricService.getInstance().addMetricSet(new ProcessMetrics());
     MetricService.getInstance().addMetricSet(new SystemMetrics(true));
+    MetricService.getInstance().addMetricSet(new DiskMetrics("DataNode"));

Review Comment:
   "DataNode" -> IoTDBConstant.DN_ROLE?



##########
confignode/src/main/java/org/apache/iotdb/confignode/service/ConfigNode.java:
##########
@@ -231,6 +232,7 @@ private void setUpInternalServices() throws StartupException, IOException {
     MetricService.getInstance().addMetricSet(new LogbackMetrics());
     MetricService.getInstance().addMetricSet(new ProcessMetrics());
     MetricService.getInstance().addMetricSet(new SystemMetrics(false));
+    MetricService.getInstance().addMetricSet(new DiskMetrics("ConfigNode"));

Review Comment:
   "ConfigNode" -> IoTDBConstant.CN_ROLE?



##########
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/disk/MacDiskMetricsManager.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * 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.iotdb.metrics.metricsets.disk;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+/** Disk Metrics Manager for macOS, not implemented yet. */
+public class MacDiskMetricsManager implements IDiskMetricsManager {

Review Comment:
   How about add these function as default function in `IDiskMetricsManager`, Please see [blog](https://blog.csdn.net/Code_My_Life/article/details/51891520)



##########
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/disk/WindowsDiskMetricsManager.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * 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.iotdb.metrics.metricsets.disk;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+/** Disk Metrics Manager for Windows system, not implemented yet. */
+public class WindowsDiskMetricsManager implements IDiskMetricsManager {

Review Comment:
   Same as above



##########
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/disk/LinuxDiskMetricsManager.java:
##########
@@ -0,0 +1,397 @@
+/*
+ * 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.iotdb.metrics.metricsets.disk;
+
+import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Scanner;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * All data metrics are collected from <b>/proc/</b>.
+ *
+ * <p><b>/proc/diskstats</b> is a file in Linux, it contains the running information of the disks,
+ * including device name, read operation count, merged read operation count, write operation count,
+ * merged write operation count etc. This class collects the data periodically and analyzes the
+ * changes in each pieces of data to gain an insight of the disks of status.
+ *
+ * <p><b>/proc/[PID]/io</b> is also a file in Linux, it indicates the io status of a specific
+ * process. The content of it contains following items: actual read byte, actual write byte, read
+ * system call count, write system call count, byte attempt to read, byte attempt to write,
+ * cancelled write byte.
+ */
+public class LinuxDiskMetricsManager implements IDiskMetricsManager {
+  private final Logger log = LoggerFactory.getLogger(LinuxDiskMetricsManager.class);
+
+  @SuppressWarnings("squid:S1075")
+  private static final String DISK_STATUS_FILE_PATH = "/proc/diskstats";
+
+  @SuppressWarnings("squid:S1075")
+  private static final String DISK_ID_PATH = "/sys/block";
+
+  private final String processIoStatusPath;
+  private static final int DISK_ID_OFFSET = 3;
+  private static final int DISK_READ_COUNT_OFFSET = 4;
+  private static final int DISK_MERGED_READ_COUNT_OFFSET = 5;
+  private static final int DISK_SECTOR_READ_COUNT_OFFSET = 6;
+  private static final int DISK_READ_TIME_OFFSET = 7;
+  private static final int DISK_WRITE_COUNT_OFFSET = 8;
+  private static final int DISK_MERGED_WRITE_COUNT_OFFSET = 9;
+  private static final int DISK_SECTOR_WRITE_COUNT_OFFSET = 10;
+  private static final int DISK_WRITE_TIME_COST_OFFSET = 11;
+  private static final int DISK_QUEUE_SIZE_OFFSET = 12;
+  private static final int DISK_IO_TOTAL_TIME_OFFSET = 13;
+  private static final long UPDATE_SMALLEST_INTERVAL = 10000L;
+  private Set<String> diskIdSet;
+  private long lastUpdateTime = 0L;
+  private long updateInterval = 1L;
+
+  // Disk IO status structure
+  private final Map<String, Long> lastReadOperationCountForDisk = new HashMap<>();
+  private final Map<String, Long> lastWriteOperationCountForDisk = new HashMap<>();
+  private final Map<String, Long> lastReadTimeCostForDisk = new HashMap<>();
+  private final Map<String, Long> lastWriteTimeCostForDisk = new HashMap<>();
+  private final Map<String, Long> lastMergedReadCountForDisk = new HashMap<>();
+  private final Map<String, Long> lastMergedWriteCountForDisk = new HashMap<>();
+  private final Map<String, Long> lastReadSectorCountForDisk = new HashMap<>();
+  private final Map<String, Long> lastWriteSectorCountForDisk = new HashMap<>();
+  private final Map<String, Long> queueSizeMap = new HashMap<>();
+  private final Map<String, Long> lastIoBusyTimeForDisk = new HashMap<>();
+  private final Map<String, Long> incrementReadOperationCountForDisk = new HashMap<>();
+  private final Map<String, Long> incrementWriteOperationCountForDisk = new HashMap<>();
+  private final Map<String, Long> incrementReadTimeCostForDisk = new HashMap<>();
+  private final Map<String, Long> incrementWriteTimeCostForDisk = new HashMap<>();
+  private final Map<String, Long> incrementReadSectorCountForDisk = new HashMap<>();
+  private final Map<String, Long> incrementWriteSectorCountForDisk = new HashMap<>();
+  private final Map<String, Long> incrementIoBusyTimeForDisk = new HashMap<>();
+
+  // Process IO status structure
+  private long lastReallyReadSizeForProcess = 0L;
+  private long lastReallyWriteSizeForProcess = 0L;
+  private long lastAttemptReadSizeForProcess = 0L;
+  private long lastAttemptWriteSizeForProcess = 0L;
+  private long lastReadOpsCountForProcess = 0L;
+  private long lastWriteOpsCountForProcess = 0L;
+
+  public LinuxDiskMetricsManager() {
+    super();
+    processIoStatusPath =
+        String.format(
+            "/proc/%s/io", MetricConfigDescriptor.getInstance().getMetricConfig().getPid());
+  }
+
+  @Override
+  public Map<String, Long> getReadDataSizeForDisk() {
+    checkUpdate();
+    Map<String, Long> readDataMap = new HashMap<>();
+    for (Map.Entry<String, Long> entry : lastReadSectorCountForDisk.entrySet()) {
+      // the data size in each sector is 512 byte
+      readDataMap.put(entry.getKey(), entry.getValue() * 512 / 1024);
+    }
+    return readDataMap;
+  }
+
+  @Override
+  public Map<String, Long> getWriteDataSizeForDisk() {
+    checkUpdate();
+    Map<String, Long> writeDataMap = new HashMap<>();
+    for (Map.Entry<String, Long> entry : lastWriteSectorCountForDisk.entrySet()) {
+      // the data size in each sector is 512 byte
+      writeDataMap.put(entry.getKey(), entry.getValue() * 512 / 1024);
+    }
+    return writeDataMap;
+  }
+
+  @Override
+  public Map<String, Long> getReadOperationCountForDisk() {
+    checkUpdate();
+    return lastReadOperationCountForDisk;
+  }
+
+  @Override
+  public Map<String, Long> getWriteOperationCountForDisk() {
+    return lastWriteOperationCountForDisk;
+  }
+
+  @Override
+  public Map<String, Long> getReadCostTimeForDisk() {
+    return lastReadTimeCostForDisk;
+  }
+
+  @Override
+  public Map<String, Long> getWriteCostTimeForDisk() {
+    return lastWriteTimeCostForDisk;
+  }
+
+  @Override
+  public Map<String, Long> getIoUtilsPercentage() {
+    Map<String, Long> utilsMap = new HashMap<>();

Review Comment:
   init capacity with `incrementIoBusyTimeForDisk.size()`?



##########
metrics/interface/src/main/java/org/apache/iotdb/metrics/metricsets/disk/LinuxDiskMetricsManager.java:
##########
@@ -0,0 +1,397 @@
+/*
+ * 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.iotdb.metrics.metricsets.disk;
+
+import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Scanner;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * All data metrics are collected from <b>/proc/</b>.
+ *
+ * <p><b>/proc/diskstats</b> is a file in Linux, it contains the running information of the disks,
+ * including device name, read operation count, merged read operation count, write operation count,
+ * merged write operation count etc. This class collects the data periodically and analyzes the
+ * changes in each pieces of data to gain an insight of the disks of status.
+ *
+ * <p><b>/proc/[PID]/io</b> is also a file in Linux, it indicates the io status of a specific
+ * process. The content of it contains following items: actual read byte, actual write byte, read
+ * system call count, write system call count, byte attempt to read, byte attempt to write,
+ * cancelled write byte.
+ */
+public class LinuxDiskMetricsManager implements IDiskMetricsManager {
+  private final Logger log = LoggerFactory.getLogger(LinuxDiskMetricsManager.class);
+
+  @SuppressWarnings("squid:S1075")
+  private static final String DISK_STATUS_FILE_PATH = "/proc/diskstats";
+
+  @SuppressWarnings("squid:S1075")
+  private static final String DISK_ID_PATH = "/sys/block";
+
+  private final String processIoStatusPath;
+  private static final int DISK_ID_OFFSET = 3;
+  private static final int DISK_READ_COUNT_OFFSET = 4;
+  private static final int DISK_MERGED_READ_COUNT_OFFSET = 5;
+  private static final int DISK_SECTOR_READ_COUNT_OFFSET = 6;
+  private static final int DISK_READ_TIME_OFFSET = 7;
+  private static final int DISK_WRITE_COUNT_OFFSET = 8;
+  private static final int DISK_MERGED_WRITE_COUNT_OFFSET = 9;
+  private static final int DISK_SECTOR_WRITE_COUNT_OFFSET = 10;
+  private static final int DISK_WRITE_TIME_COST_OFFSET = 11;
+  private static final int DISK_QUEUE_SIZE_OFFSET = 12;
+  private static final int DISK_IO_TOTAL_TIME_OFFSET = 13;
+  private static final long UPDATE_SMALLEST_INTERVAL = 10000L;
+  private Set<String> diskIdSet;
+  private long lastUpdateTime = 0L;
+  private long updateInterval = 1L;
+
+  // Disk IO status structure
+  private final Map<String, Long> lastReadOperationCountForDisk = new HashMap<>();

Review Comment:
   How about use `getDiskIds().size()` to be the initial capacity of these maps as `DEFAULT_INITIAL_CAPACITY` in HashMap is 16, which is usually bigger than the number of disks 



-- 
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: reviews-unsubscribe@iotdb.apache.org

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