Skip to content
Snippets Groups Projects
Commit c7dccc69 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Fix space comparison expression and use gigabytes for threshold.

Megabytes have shown to be a bit clumsy in the configuration files, so
simply switch to the more useful Gigabytes unit.

Fixes #39
parent e73ae489
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@
public string DriveName { get; set; }
/// <summary>
/// Limit (in MB) of free space, lower values will trigger a notification.
/// Limit (in GB) of free space, lower values will trigger a notification.
/// </summary>
public long SpaceThreshold { get; set; }
}
......
......@@ -489,7 +489,7 @@ namespace ATxCommon.Serializables
var space = "";
foreach (var drive in SpaceMonitoring) {
space += $" DriveName: {drive.DriveName} " +
$"(threshold: {Conv.MegabytesToString(drive.SpaceThreshold)})\n";
$"(threshold: {Conv.GigabytesToString(drive.SpaceThreshold)})\n";
}
if (!string.IsNullOrWhiteSpace(space))
msg += $"SpaceMonitoring:\n{space}";
......
......@@ -80,12 +80,16 @@ namespace ATxCommon
var msg = "";
foreach (var driveToCheck in drives) {
var freeSpace = GetFreeDriveSpace(driveToCheck.DriveName);
if (freeSpace >= driveToCheck.SpaceThreshold)
if (freeSpace >= driveToCheck.SpaceThreshold * Conv.GigaBytes) {
Log.Trace("Drive [{0}] free space: {1}, above threshold ({2})",
driveToCheck.DriveName, Conv.BytesToString(freeSpace),
Conv.GigabytesToString(driveToCheck.SpaceThreshold));
continue;
}
msg += "Drive '" + driveToCheck.DriveName +
"' - free space: " + Conv.BytesToString(freeSpace) +
" (threshold: " + Conv.BytesToString(driveToCheck.SpaceThreshold) + ")\n";
msg += $"Drive [{driveToCheck.DriveName}] " +
$"free space: {Conv.BytesToString(freeSpace)} " +
$"(threshold: {Conv.GigabytesToString(driveToCheck.SpaceThreshold)})\n";
}
return msg;
......
......@@ -104,12 +104,14 @@ namespace ATxService
/// </summary>
/// <param name="spaceDetails">String describing the drives being low on space.</param>
private void SendLowSpaceMail(string spaceDetails) {
if (string.IsNullOrWhiteSpace(spaceDetails))
if (string.IsNullOrWhiteSpace(spaceDetails)) {
Log.Trace("SendLowSpaceMail(): spaceDetails emtpy!");
return;
}
var delta = TimeUtils.MinutesSince(_status.LastStorageNotification);
if (delta < _config.StorageNotificationDelta) {
Log.Trace("Only {0} since last low-space-notification, skipping.",
Log.Trace("Last low-space-notification was {0}, skipping.",
TimeUtils.MinutesToHuman(delta));
return;
}
......
......@@ -20,12 +20,12 @@
<DriveToCheck>
<!-- DriveName: the drive letter followed by a colon -->
<DriveName>C:</DriveName>
<!-- SpaceThreshold: minimum amount of free megabytes -->
<SpaceThreshold>14000</SpaceThreshold>
<!-- SpaceThreshold: minimum amount of free gigabytes -->
<SpaceThreshold>14</SpaceThreshold>
</DriveToCheck>
<!--><DriveToCheck>
<DriveName>D:</DriveName>
<SpaceThreshold>120000</SpaceThreshold>
<SpaceThreshold>120</SpaceThreshold>
</DriveToCheck><-->
</SpaceMonitoring>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment