You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/08/10 02:01:33 UTC

[GitHub] [iotdb] xingtanzjr commented on a diff in pull request #6911: [IOTDB-3980][Metric] Use asynchronous way to collect some predefined metrics.

xingtanzjr commented on code in PR #6911:
URL: https://github.com/apache/iotdb/pull/6911#discussion_r941941356


##########
server/src/main/java/org/apache/iotdb/db/service/metrics/predefined/FileMetrics.java:
##########
@@ -146,4 +98,112 @@ public void bindTo(MetricManager metricManager) {
   public PredefinedMetric getType() {
     return PredefinedMetric.FILE;
   }
+
+  @Override
+  public void startAsyncCollectedMetrics() {
+    ScheduledExecutorUtil.safelyScheduleAtFixedRate(
+        service,
+        this::collect,
+        1,
+        MetricConfigDescriptor.getInstance().getMetricConfig().getAsyncCollectPeriodInSecond(),
+        TimeUnit.SECONDS);
+  }
+
+  @Override
+  public void stopAsyncCollectedMetrics() {
+    service.shutdown();
+  }
+
+  private void collect() {
+    walFileTotalSize = Stream.of(walDirs).mapToLong(FileUtils::getDirSize).sum();
+    sequenceFileTotalSize =
+        Stream.of(dataDirs)
+            .mapToLong(
+                dir -> {
+                  dir += File.separator + IoTDBConstant.SEQUENCE_FLODER_NAME;
+                  return FileUtils.getDirSize(dir);
+                })
+            .sum();
+    unsequenceFileTotalSize =
+        Stream.of(dataDirs)
+            .mapToLong(
+                dir -> {
+                  dir += File.separator + IoTDBConstant.UNSEQUENCE_FLODER_NAME;
+                  return FileUtils.getDirSize(dir);
+                })
+            .sum();
+    walFileTotalCount =

Review Comment:
   Let's use the new interface from WALNode to reduce calculation



-- 
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