@Override public Long invoke(File f, VirtualChannel channel) throws IOException { return f.getUsableSpace(); } }
public long getUsableSpace(File targetFolder) { long usableSpace = targetFolder.getUsableSpace(); if (usableSpace < 0) { // See https://bugs.openjdk.java.net/browse/JDK-8162520 usableSpace = Long.MAX_VALUE; } return usableSpace; } }
/** * Returns the amount of usable space remaining. * * @return the amount of usable space remaining */ public long getUsableSpace() { return file.getUsableSpace(); }
@Override public long getUsableSpace() { return _root.getUsableSpace(); }
/** @return the usable space remaining on the filesystem in bytes. */ public long getAvailable() { return dirFile.getUsableSpace(); }
/** * Returns the free capacity for a given path * @param path path * @return usable space */ public static long getContainerUsableSpace(final Path path) { return path.toFile().getUsableSpace(); }
public DiskSpace invoke(File f, VirtualChannel channel) throws IOException { // if the disk is really filled up we can't even create a single file, // so calling File.createTempFile and figuring out the directory won't reliably work. f = new File(System.getProperty("java.io.tmpdir")); long s = f.getUsableSpace(); if(s<=0) return null; return new DiskSpace(f.getCanonicalPath(), s); } private static final long serialVersionUID = 1L;
public DiskSpace invoke(File f, VirtualChannel channel) throws IOException { long s = f.getUsableSpace(); if(s<=0) return null; return new DiskSpace(f.getCanonicalPath(), s); } private static final long serialVersionUID = 1L;
public static long usableSpace(String currentWorkingDir) { File file = new File(currentWorkingDir, "pipelines"); if (!file.exists()) { LOGGER.warn("the [{}] should be created when agent starts up, but it seems missing at the moment. Cruise should be able to automatically create it later", file.getAbsolutePath()); } return file.getUsableSpace(); }
CachedFSUsableSpace(File fs, long interval) { this.fs = fs; this.interval = interval; this.value = new AtomicLong(fs.getUsableSpace()); this.lastRefresh = new AtomicLong(System.currentTimeMillis()); }
long getUsableSpace() { long now = System.currentTimeMillis(); if (now - interval > lastRefresh.get()) { value.set(fs.getUsableSpace()); lastRefresh.set(now); } return Math.max(value.get(), 0L); } }
/** * Wrapper to enable stubbing of static method call for unit testing */ long getLocalDiskAvailable() { return FileUtils.getUserDirectory().getUsableSpace(); }
System.out.println("Total space (bytes): " + root.getTotalSpace()); System.out.println("Free space (bytes): " + root.getFreeSpace()); System.out.println("Usable space (bytes): " + root.getUsableSpace());
public String availableDiskSpace() { File artifactsDir = artifactsDirHolder.getArtifactsDir(); return FileUtils.byteCountToDisplaySize(artifactsDir.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); } }
protected void doRun() { long free = Jenkins.getInstance().getRootDir().getUsableSpace(); long total = Jenkins.getInstance().getRootDir().getTotalSpace(); if(free<=0 || total<=0) { // information unavailable. pointless to try. LOGGER.info("JENKINS_HOME disk usage information isn't available. aborting to monitor"); cancel(); return; } LOGGER.fine("Monitoring disk usage of JENKINS_HOME. total="+total+" free="+free); // if it's more than 90% full and less than the minimum, activate // it's AND and not OR so that small Hudson home won't get a warning, // and similarly, if you have a 1TB disk, you don't get a warning when you still have 100GB to go. HudsonHomeDiskUsageMonitor.get().activated = (total/free>10 && free< FREE_SPACE_THRESHOLD); }
/** * Asserts that enough disk space is available to allocate a new segment. */ private void assertDiskSpace() { if (directory().getUsableSpace() < maxSegmentSize() * SEGMENT_BUFFER_FACTOR) { throw new StorageException.OutOfDiskSpace("Not enough space to allocate a new journal segment"); } }
@Test public void updateSendsUsableSpaceToRecordsStats() { File dir = mock(File.class); when(dir.exists()).thenReturn(true); final long expectedFree = 456; when(dir.getUsableSpace()).thenReturn(expectedFree); TestableDiskUsage diskUsage = new TestableDiskUsage(dir); diskUsage.update(0.0f, 1.0f); assertThat(diskUsage.getFree()).isEqualTo(expectedFree); }
@Test public void criticalMessageStatesUsageExceedsCritical() { File dir = mock(File.class); when(dir.exists()).thenReturn(true); when(dir.getTotalSpace()).thenReturn(1024L * 1024L * 3L); when(dir.getUsableSpace()).thenReturn(1024L * 1024L * 2L); TestableDiskUsage diskUsage = new TestableDiskUsage(dir, 1/* one megabyte */); assertThat(diskUsage.update(0.0f, 33.2f)).isEqualTo(DiskState.CRITICAL); assertThat(diskUsage.getNext()).isEqualTo(DiskState.CRITICAL); assertThat(diskUsage.getPct()).isEqualTo("33.3%"); assertThat(diskUsage.getCriticalMessage()) .isEqualTo("the file system is 33.3% full, which reached the critical threshold of 33.2%."); }
@Test public void criticalMessageStatesUsageExceedsCriticalWithManyDigits() { File dir = mock(File.class); when(dir.exists()).thenReturn(true); when(dir.getTotalSpace()).thenReturn(1024L * 1024L * 3L); when(dir.getUsableSpace()).thenReturn(1024L * 1024L * 2L); TestableDiskUsage diskUsage = new TestableDiskUsage(dir, 1/* one megabyte */); assertThat(diskUsage.update(0.0f, 33.25783495783648593746336f)).isEqualTo(DiskState.CRITICAL); assertThat(diskUsage.getNext()).isEqualTo(DiskState.CRITICAL); assertThat(diskUsage.getPct()).isEqualTo("33.3%"); assertThat(diskUsage.getCriticalMessage()) .isEqualTo("the file system is 33.3% full, which reached the critical threshold of 33.3%."); }