Last active
May 22, 2017 17:57
-
-
Save scottsauber/ca3f06e2b80b587a06c53a6aa625980f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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