@Test void testThatHealthCheckNameDoesNotChange() { DiskSpaceHealthCheck check = new DiskSpaceHealthCheck(fileStore, THRESHOLD_PERCENT); HealthCheckResponse response = check.call(); assertThat("diskSpace", is(response.getName())); }
@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 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(); }
DiskSpaceHealthCheck implements HealthCheck { @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 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(); } }
DiskSpaceHealthCheck implements HealthCheck { @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 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(); } DiskSpaceHealthCheck(FileStore fileStore, double thresholdPercent); @Inject  DiskSpaceHealthCheck(
            @ConfigProperty(name = CONFIG_KEY_PATH, defaultValue = DEFAULT_PATH) File path,
            @ConfigProperty(name = CONFIG_KEY_THRESHOLD_PERCENT, defaultValue = "99.999") double thresholdPercent
    ); private  DiskSpaceHealthCheck(Builder builder); }
DiskSpaceHealthCheck implements HealthCheck { @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 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(); } DiskSpaceHealthCheck(FileStore fileStore, double thresholdPercent); @Inject  DiskSpaceHealthCheck(
            @ConfigProperty(name = CONFIG_KEY_PATH, defaultValue = DEFAULT_PATH) File path,
            @ConfigProperty(name = CONFIG_KEY_THRESHOLD_PERCENT, defaultValue = "99.999") double thresholdPercent
    ); private  DiskSpaceHealthCheck(Builder builder); static Builder builder(); static DiskSpaceHealthCheck create(); @Override HealthCheckResponse call(); }
DiskSpaceHealthCheck implements HealthCheck { @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 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(); } DiskSpaceHealthCheck(FileStore fileStore, double thresholdPercent); @Inject  DiskSpaceHealthCheck(
            @ConfigProperty(name = CONFIG_KEY_PATH, defaultValue = DEFAULT_PATH) File path,
            @ConfigProperty(name = CONFIG_KEY_THRESHOLD_PERCENT, defaultValue = "99.999") double thresholdPercent
    ); private  DiskSpaceHealthCheck(Builder builder); static Builder builder(); static DiskSpaceHealthCheck create(); @Override HealthCheckResponse call(); static final String DEFAULT_PATH; static final double DEFAULT_THRESHOLD; static final String CONFIG_KEY_PATH; static final String CONFIG_KEY_THRESHOLD_PERCENT; }