-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move CheckFreeDiskSpace into persistence layer
- Loading branch information
1 parent
edf5fb0
commit 6e75e86
Showing
4 changed files
with
71 additions
and
100 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/ServiceControl.Audit.Persistence.RavenDB/CustomChecks/CheckFreeDiskSpace.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
namespace ServiceControl.Audit.Persistence.RavenDB.CustomChecks | ||
{ | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using NServiceBus.CustomChecks; | ||
using NServiceBus.Logging; | ||
using RavenDB; | ||
|
||
class CheckFreeDiskSpace : CustomCheck | ||
{ | ||
public CheckFreeDiskSpace(DatabaseConfiguration databaseConfiguration) : base("ServiceControl.Audit database", "Storage space", TimeSpan.FromMinutes(5)) | ||
{ | ||
dataPath = databaseConfiguration.ServerConfiguration.DbPath; | ||
percentageThreshold = databaseConfiguration.MinimumStorageLeftRequiredForIngestion / 100m; | ||
Logger.Debug($"Check ServiceControl data drive space remaining custom check starting. Threshold {percentageThreshold:P0}"); | ||
} | ||
|
||
public override Task<CheckResult> PerformCheck(CancellationToken cancellationToken = default) | ||
{ | ||
var dataPathRoot = Path.GetPathRoot(dataPath); | ||
|
||
if (dataPathRoot == null) | ||
{ | ||
throw new Exception($"Unable to find the root of the data path {dataPath}"); | ||
} | ||
|
||
var dataDriveInfo = new DriveInfo(dataPathRoot); | ||
var availableFreeSpace = (decimal)dataDriveInfo.AvailableFreeSpace; | ||
var totalSpace = (decimal)dataDriveInfo.TotalSize; | ||
|
||
var percentRemaining = (decimal)dataDriveInfo.AvailableFreeSpace / dataDriveInfo.TotalSize; | ||
|
||
if (Logger.IsDebugEnabled) | ||
{ | ||
Logger.Debug($"Free space: {availableFreeSpace:N0}B | Total: {totalSpace:N0}B | Percent remaining {percentRemaining:P1}"); | ||
} | ||
|
||
return percentRemaining > percentageThreshold | ||
? CheckResult.Pass | ||
: CheckResult.Failed($"{percentRemaining:P0} disk space remaining on data drive '{dataDriveInfo.VolumeLabel} ({dataDriveInfo.RootDirectory})' on '{Environment.MachineName}'."); | ||
} | ||
|
||
readonly string dataPath; | ||
readonly decimal percentageThreshold; | ||
|
||
static readonly ILog Logger = LogManager.GetLogger(typeof(CheckFreeDiskSpace)); | ||
} | ||
} |
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
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
62 changes: 0 additions & 62 deletions
62
src/ServiceControl.Audit/Infrastructure/CheckFreeDiskSpace.cs
This file was deleted.
Oops, something went wrong.