@Test public void testGeneratesMessageIfTooFull() { final AtomicInteger callCounter = new AtomicInteger(0); final ComponentLog logger = Mockito.mock(ComponentLog.class); Mockito.doAnswer(invocation -> { final String message = (String) invocation.getArguments()[0]; System.out.println(message); callCounter.incrementAndGet(); return null; }).when(logger).warn(Mockito.anyString()); MonitorDiskUsage.checkThreshold("Test Path", Paths.get("."), 0, logger); assertEquals(1, callCounter.get()); }
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); } }
MonitorDiskUsage extends AbstractReportingTask { 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); } } }
MonitorDiskUsage extends AbstractReportingTask { 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); } }  }
MonitorDiskUsage extends AbstractReportingTask { 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); } }  @Override void onTrigger(final ReportingContext context); }
MonitorDiskUsage extends AbstractReportingTask { 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); } }  @Override void onTrigger(final ReportingContext context); static final PropertyDescriptor DIR_THRESHOLD; static final PropertyDescriptor DIR_LOCATION; static final PropertyDescriptor DIR_DISPLAY_NAME; }