public static double getDiskFreeRatio(String dir) {
    File dirFile = FSFactoryProducer.getFSFactory().getFile(dir);
    if (!dirFile.mkdirs()) {
      // This may solve getFreeSpace() == 0?
      dirFile = new File(dir);
    }
    long freeSpace =
        IOUtils.retryNoException(5, 2000L, dirFile::getFreeSpace, space -> space > 0).orElse(0L);
    if (freeSpace == 0) {
      LOGGER.warn("Cannot get free space for {} after retries, please check the disk status", dir);
    }
    long totalSpace = dirFile.getTotalSpace();
    double ratio = 1.0 * freeSpace / totalSpace;
    if (ratio <= diskSpaceWarningThreshold) {
      LOGGER.warn(
          "{} is above the warning threshold, free space {}, total space {}",
          dir,
          freeSpace,
          totalSpace);
    }
    return ratio;
  }
NOTICE: This method is currently used only for data dir, thus using FSFactory to get file

@param dir directory path
@return
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/utils/JVMCommonUtils.java