@Override public Long invoke(File f, VirtualChannel channel) throws IOException { return f.getFreeSpace(); } }
/** * Returns the amount of free space remaining. * * @return the amount of free space remaining */ public long getFreeSpace() { return file.getFreeSpace(); }
/** @return the total used space on the filesystem in bytes. */ public long getUsed() { return dirFile.getTotalSpace() - dirFile.getFreeSpace(); }
@Override public long percentAvailable(File file) { return Math.round(((double) file.getFreeSpace() / file.getTotalSpace()) * 100); } }
public static double getDiskPartitionSpaceUsedPercent(final String path) { if (null == path || path.isEmpty()) return -1; try { File file = new File(path); if (!file.exists()) return -1; long totalSpace = file.getTotalSpace(); if (totalSpace > 0) { long freeSpace = file.getFreeSpace(); long usedSpace = totalSpace - freeSpace; return usedSpace / (double) totalSpace; } } catch (Exception e) { return -1; } return -1; }
private static String getDiskSpace( DatabaseLayout databaseLayout ) { File directory = databaseLayout.databaseDirectory(); long free = directory.getFreeSpace(); long total = directory.getTotalSpace(); long percentage = total != 0 ? (free * 100 / total) : 0; return String.format( "Disk space on partition (Total / Free / Free %%): %s / %s / %s", total, free, percentage ); }
@Override public long getSpace(String path, SpaceType type) throws IOException { path = stripPath(path); File file = new File(path); switch (type) { case SPACE_TOTAL: return file.getTotalSpace(); case SPACE_FREE: return file.getFreeSpace(); case SPACE_USED: return file.getTotalSpace() - file.getFreeSpace(); default: throw new IOException("Unknown space type: " + type); } }
@Override public FsStatus getStatus(Path p) throws IOException { File partition = pathToFile(p == null ? new Path("/") : p); //File provides getUsableSpace() and getFreeSpace() //File provides no API to obtain used space, assume used = total - free return new FsStatus(partition.getTotalSpace(), partition.getTotalSpace() - partition.getFreeSpace(), partition.getFreeSpace()); }
public String check(String folder) { if (folder == null) throw new IllegalArgumentException("folder"); File f = new File(folder); folderSize = getFileSize(f); usage = 1.0*(f.getTotalSpace() - f.getFreeSpace())/ f.getTotalSpace(); return String.format("used %d files %d disk in use %f", folderSize, fileCount, usage); }
public static Memory disk_free_space(String path) { return LongMemory.valueOf(new File(path).getFreeSpace()); }
System.out.println("File system root: " + root.getAbsolutePath()); System.out.println("Total space (bytes): " + root.getTotalSpace()); System.out.println("Free space (bytes): " + root.getFreeSpace()); System.out.println("Usable space (bytes): " + root.getUsableSpace());
@Override public FsStats fsStats() { final Map<String, FsStats.Filesystem> filesystems = new HashMap<>(locations.size()); for (File location : locations) { final String path = location.getAbsolutePath(); final long total = location.getTotalSpace(); final long free = location.getFreeSpace(); final long available = location.getUsableSpace(); final long used = total - free; final short usedPercent = (short) ((double) used / total * 100); final FsStats.Filesystem filesystem = FsStats.Filesystem.create( path, total, free, available, used, usedPercent); filesystems.put(path, filesystem); } return FsStats.create(filesystems); } }
System.out.println("File system root: " + root.getAbsolutePath()); System.out.println("Total space (bytes): " + root.getTotalSpace()); System.out.println("Free space (bytes): " + root.getFreeSpace()); System.out.println("Usable space (bytes): " + root.getUsableSpace());
private void estimateSizeAndCheckAvailableDiskSpace( Path destination, DiagnosticsReporterProgress progress, List<DiagnosticsReportSource> sources, Path destinationFolder, boolean force ) throws IOException { if ( force ) { return; } long estimatedFinalSize = 0; for ( DiagnosticsReportSource source : sources ) { estimatedFinalSize += source.estimatedSize( progress ); } long freeSpace = destinationFolder.toFile().getFreeSpace(); if ( estimatedFinalSize > freeSpace ) { String message = String.format( "Free available disk space for %s is %s, worst case estimate is %s. To ignore add '--force' to the command.", destination.getFileName(), Format.bytes( freeSpace ), Format.bytes( estimatedFinalSize ) ); throw new RuntimeException( message ); } }
static void checkThreshold(final String pathName, final Path path, final int threshold, final ComponentLog logger) { final File file = path.toFile(); final long totalBytes = file.getTotalSpace(); final long freeBytes = file.getFreeSpace(); final long usedBytes = totalBytes - freeBytes; final double usedPercent = (double) usedBytes / (double) totalBytes * 100D; if (usedPercent >= threshold) { final String usedSpace = FormatUtils.formatDataSize(usedBytes); final String totalSpace = FormatUtils.formatDataSize(totalBytes); final String freeSpace = FormatUtils.formatDataSize(freeBytes); final double freePercent = (double) freeBytes / (double) totalBytes * 100D; final String message = String.format("%1$s exceeds configured threshold of %2$s%%, having %3$s / %4$s (%5$.2f%%) used and %6$s (%7$.2f%%) free", pathName, threshold, usedSpace, totalSpace, usedPercent, freeSpace, freePercent); logger.warn(message); } } }
private StorageLocation fakeLocation(long total, long free, long max, Double percent) { File file = EasyMock.mock(File.class); EasyMock.expect(file.getTotalSpace()).andReturn(total).anyTimes(); EasyMock.expect(file.getFreeSpace()).andReturn(free).anyTimes(); EasyMock.replay(file); return new StorageLocation(file, max, percent); }
runtimeInfo.put("commitLogDirCapacity", String.format("Total : %s, Free : %s.", MixAll.humanReadableByteCount(commitLogDir.getTotalSpace(), false), MixAll.humanReadableByteCount(commitLogDir.getFreeSpace(), false)));
@Test public void shouldPrintDiskUsage() { // Not sure how to get around this w/o spying. The method that we're unit testing will construct // other File instances with this guy as parent and internally the File constructor uses the field 'path' // which, if purely mocked, won't be assigned. At the same time we want to control the total/free space methods // and what they return... a tough one. File storeDir = Mockito.spy( new File( "storeDir" ) ); DatabaseLayout layout = mock( DatabaseLayout.class ); when( layout.databaseDirectory() ).thenReturn( storeDir ); when( storeDir.getTotalSpace() ).thenReturn( 100L ); when( storeDir.getFreeSpace() ).thenReturn( 40L ); AssertableLogProvider logProvider = new AssertableLogProvider(); KernelDiagnostics.StoreFiles storeFiles = new KernelDiagnostics.StoreFiles( layout ); storeFiles.dump( logProvider.getLog( getClass() ).debugLogger() ); logProvider.assertContainsMessageContaining( "100 / 40 / 40" ); }
@Override public Cursor queryRoots(String[] projection) throws FileNotFoundException { final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION); @SuppressWarnings("ConstantConditions") final String applicationName = getContext().getString(R.string.application_name); final MatrixCursor.RowBuilder row = result.newRow(); row.add(Root.COLUMN_ROOT_ID, getDocIdForFile(BASE_DIR)); row.add(Root.COLUMN_DOCUMENT_ID, getDocIdForFile(BASE_DIR)); row.add(Root.COLUMN_SUMMARY, null); row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_SEARCH); row.add(Root.COLUMN_TITLE, applicationName); row.add(Root.COLUMN_MIME_TYPES, ALL_MIME_TYPES); row.add(Root.COLUMN_AVAILABLE_BYTES, BASE_DIR.getFreeSpace()); row.add(Root.COLUMN_ICON, R.drawable.ic_launcher); return result; }
boolean canHandle(DataSegment segment) { if (available() < segment.getSize()) { log.warn( "Segment[%s:%,d] too large for storage[%s:%,d]. Check your druid.segmentCache.locations maxSize param", segment.getId(), segment.getSize(), getPath(), available() ); return false; } if (freeSpaceToKeep > 0) { long currFreeSpace = path.getFreeSpace(); if ((freeSpaceToKeep + segment.getSize()) > currFreeSpace) { log.warn( "Segment[%s:%,d] too large for storage[%s:%,d] to maintain suggested freeSpace[%d], current freeSpace is [%d].", segment.getId(), segment.getSize(), getPath(), available(), freeSpaceToKeep, currFreeSpace ); return false; } } return true; }