NumberFormat nf = NumberFormat.getNumberInstance(); for (Path root : FileSystems.getDefault().getRootDirectories()) { System.out.print(root + ": "); try { FileStore store = Files.getFileStore(root); System.out.println("available=" + nf.format(store.getUsableSpace()) + ", total=" + nf.format(store.getTotalSpace())); } catch (IOException e) { System.out.println("error querying space: " + e.toString()); } }
@Override public long getStorageCapacity() throws IOException { long capacity = 0L; for (final File file : flowFileRepositoryPaths) { capacity += Files.getFileStore(file.toPath()).getTotalSpace(); } return capacity; }
private boolean hasEnoughDiskSpace(Path path) { try { FileStore fileStore = getFileStore(path); return fileStore.getUsableSpace() > fileStore.getTotalSpace() * (1.0 - maxUsedSpaceThreshold); } catch (IOException e) { throw new PrestoException(OUT_OF_SPILL_SPACE, "Cannot determine free space for spill", e); } } }
public FileSystemProps perform() { try { Path target = vertx.resolveFile(path).toPath(); FileStore fs = Files.getFileStore(target); return new FileSystemPropsImpl(fs.getTotalSpace(), fs.getUnallocatedSpace(), fs.getUsableSpace()); } catch (IOException e) { throw new FileSystemException(e); } } };
@Override public HealthCheckResponse call() { long diskFreeInBytes; long totalInBytes; try { diskFreeInBytes = fileStore.getUsableSpace(); totalInBytes = fileStore.getTotalSpace(); } catch (IOException e) { throw new HealthCheckException("Failed to obtain disk space data", e); } long usedInBytes = totalInBytes - diskFreeInBytes; long threshold = (long) ((thresholdPercent / 100) * totalInBytes); //Formatter ensures that returned delimiter will be always the same Formatter formatter = new Formatter(Locale.US); return HealthCheckResponse.named("diskSpace") .state(threshold >= usedInBytes) .withData("percentFree", formatter.format("%.2f%%", 100 * ((double) diskFreeInBytes / totalInBytes)).toString()) .withData("free", DiskSpaceHealthCheck.format(diskFreeInBytes)) .withData("freeBytes", diskFreeInBytes) .withData("total", DiskSpaceHealthCheck.format(totalInBytes)) .withData("totalBytes", totalInBytes) .build(); }
@Override public long getTotalSpace() throws IOException { long result = in.getTotalSpace(); if (result < 0) { // see https://bugs.openjdk.java.net/browse/JDK-8162520: result = Long.MAX_VALUE; } return result; }
public static FsInfo.Path getFSInfo(NodePath nodePath) throws IOException { FsInfo.Path fsPath = new FsInfo.Path(); fsPath.path = nodePath.path.toAbsolutePath().toString(); // NOTE: we use already cached (on node startup) FileStore and spins // since recomputing these once per second (default) could be costly, // and they should not change: fsPath.total = adjustForHugeFilesystems(nodePath.fileStore.getTotalSpace()); fsPath.free = adjustForHugeFilesystems(nodePath.fileStore.getUnallocatedSpace()); fsPath.available = adjustForHugeFilesystems(nodePath.fileStore.getUsableSpace()); fsPath.type = nodePath.fileStore.type(); fsPath.mount = nodePath.fileStore.toString(); return fsPath; }
public FileSystemProps perform() { try { Path target = vertx.resolveFile(path).toPath(); FileStore fs = Files.getFileStore(target); return new FileSystemPropsImpl(fs.getTotalSpace(), fs.getUnallocatedSpace(), fs.getUsableSpace()); } catch (IOException e) { throw new FileSystemException(e); } } };
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { long diskFreeInBytes = fileStore.getUnallocatedSpace(); if (diskFreeInBytes >= thresholdBytes) { builder.up(); } else { builder.down(); } long totalSpaceInBytes = fileStore.getTotalSpace(); builder.withDetail("disk.free", diskFreeInBytes); builder.withDetail("disk.total", totalSpaceInBytes); } }
private double getTotalSpace(FileStore store) throws IOException { double totalSpace = (double) store.getTotalSpace(); if (totalSpace < 0) { totalSpace = Long.MAX_VALUE; } return totalSpace; }
@Override public long getTotalSpace() throws IOException { return handleLargeFileSystem(fileStore.getTotalSpace()); }
@Override public long getTotalSpace() throws IOException { return fileStore.getTotalSpace(); }
System.out.print(root + ": "); try { FileStore store = Files.getFileStore(root); System.out.println("available space" + numFormat.format(store.getUsableSpace())); System.out.println(", total=" + numFormat.format(store.getTotalSpace())); } catch (IOException e) { System.out.println("error: " + e.toString()); } }
public SpaceAvailableExtensionInfo(FileStore store) throws IOException { bytesOnDevice = store.getTotalSpace(); long unallocated = store.getUnallocatedSpace(); long usable = store.getUsableSpace(); unusedBytesOnDevice = Math.max(unallocated, usable); // the rest are intentionally left zero indicating "UNKNOWN" }
DiskStatus(FileStore fileStore) throws IOException { this(fileStore.type(), BytesValues.of(fileStore.getUsableSpace()), BytesValues.of(fileStore.getTotalSpace()), BytesValues.of(fileStore.getTotalSpace() - fileStore.getUnallocatedSpace()), (float) (fileStore.getTotalSpace() - fileStore.getUnallocatedSpace()) / fileStore.getTotalSpace() * 100); } }
@Override public long getTotalSpace() { try { return getFileStore().getTotalSpace(); } catch (IOException e) { throw new StorageException(e); } }
@Override public long getTotalSpace() { try { return Filess.getFileStore( root ).getTotalSpace(); } catch( IOException e ) { throw u( e ); } }
private boolean hasEnoughDiskSpace(Path path) { try { FileStore fileStore = getFileStore(path); return fileStore.getUsableSpace() > fileStore.getTotalSpace() * (1.0 - maxUsedSpaceThreshold); } catch (IOException e) { throw new PrestoException(OUT_OF_SPILL_SPACE, "Cannot determine free space for spill", e); } } }
@Test @Category( FileStores.class ) public void testFileStoreTotalSpaceIsNonNegative() throws IOException { for( FileStore store : FS.getFileStores() ) { assertThat( store.getTotalSpace()).isGreaterThanOrEqualTo( 0L ); } }
@Override public Space get() throws BackgroundException { final Path home = new DefaultHomeFinderService(session).find(); try { final FileStore store = Files.getFileStore(session.toPath(home)); return new Space(store.getTotalSpace() - store.getUnallocatedSpace(), store.getUnallocatedSpace()); } catch(IOException e) { throw new LocalExceptionMappingService().map("Failure to read attributes of {0}", e, home); } } }