Skip to content

Instantly share code, notes, and snippets.

@scottsauber
Last active May 22, 2017 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottsauber/ca3f06e2b80b587a06c53a6aa625980f to your computer and use it in GitHub Desktop.
Save scottsauber/ca3f06e2b80b587a06c53a6aa625980f to your computer and use it in GitHub Desktop.
public class CDriveHasMoreThan1GbFreeHealthCheck : IHealthCheck
{
public ValueTask<IHealthCheckResult> CheckAsync(CancellationToken cancellationToken = default(CancellationToken))
{
long freeSpaceinGb = GetTotalFreeSpaceInGb(@"C:\");
CheckStatus status = freeSpaceinGb > 1 ? CheckStatus.Healthy : CheckStatus.Unhealthy;
return new ValueTask<IHealthCheckResult>(HealthCheckResult.FromStatus(status, $"Free Space in GB: {freeSpaceinGb}"));
}
private long GetTotalFreeSpaceInGb(string driveName)
{
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (drive.IsReady && drive.Name == driveName)
{
return drive.TotalFreeSpace / 1024 / 1024 / 1024;
}
}
throw new ArgumentException($"Invalid Drive Name {driveName}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment