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 @@ ...@@ -11,7 +11,7 @@
public string DriveName { get; set; } public string DriveName { get; set; }
/// <summary> /// <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> /// </summary>
public long SpaceThreshold { get; set; } public long SpaceThreshold { get; set; }
} }
......
...@@ -489,7 +489,7 @@ namespace ATxCommon.Serializables ...@@ -489,7 +489,7 @@ namespace ATxCommon.Serializables
var space = ""; var space = "";
foreach (var drive in SpaceMonitoring) { foreach (var drive in SpaceMonitoring) {
space += $" DriveName: {drive.DriveName} " + space += $" DriveName: {drive.DriveName} " +
$"(threshold: {Conv.MegabytesToString(drive.SpaceThreshold)})\n"; $"(threshold: {Conv.GigabytesToString(drive.SpaceThreshold)})\n";
} }
if (!string.IsNullOrWhiteSpace(space)) if (!string.IsNullOrWhiteSpace(space))
msg += $"SpaceMonitoring:\n{space}"; msg += $"SpaceMonitoring:\n{space}";
......
...@@ -80,12 +80,16 @@ namespace ATxCommon ...@@ -80,12 +80,16 @@ namespace ATxCommon
var msg = ""; var msg = "";
foreach (var driveToCheck in drives) { foreach (var driveToCheck in drives) {
var freeSpace = GetFreeDriveSpace(driveToCheck.DriveName); 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; continue;
}
msg += "Drive '" + driveToCheck.DriveName + msg += $"Drive [{driveToCheck.DriveName}] " +
"' - free space: " + Conv.BytesToString(freeSpace) + $"free space: {Conv.BytesToString(freeSpace)} " +
" (threshold: " + Conv.BytesToString(driveToCheck.SpaceThreshold) + ")\n"; $"(threshold: {Conv.GigabytesToString(driveToCheck.SpaceThreshold)})\n";
} }
return msg; return msg;
......
...@@ -104,12 +104,14 @@ namespace ATxService ...@@ -104,12 +104,14 @@ namespace ATxService
/// </summary> /// </summary>
/// <param name="spaceDetails">String describing the drives being low on space.</param> /// <param name="spaceDetails">String describing the drives being low on space.</param>
private void SendLowSpaceMail(string spaceDetails) { private void SendLowSpaceMail(string spaceDetails) {
if (string.IsNullOrWhiteSpace(spaceDetails)) if (string.IsNullOrWhiteSpace(spaceDetails)) {
Log.Trace("SendLowSpaceMail(): spaceDetails emtpy!");
return; return;
}
var delta = TimeUtils.MinutesSince(_status.LastStorageNotification); var delta = TimeUtils.MinutesSince(_status.LastStorageNotification);
if (delta < _config.StorageNotificationDelta) { 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)); TimeUtils.MinutesToHuman(delta));
return; return;
} }
......
...@@ -20,12 +20,12 @@ ...@@ -20,12 +20,12 @@
<DriveToCheck> <DriveToCheck>
<!-- DriveName: the drive letter followed by a colon --> <!-- DriveName: the drive letter followed by a colon -->
<DriveName>C:</DriveName> <DriveName>C:</DriveName>
<!-- SpaceThreshold: minimum amount of free megabytes --> <!-- SpaceThreshold: minimum amount of free gigabytes -->
<SpaceThreshold>14000</SpaceThreshold> <SpaceThreshold>14</SpaceThreshold>
</DriveToCheck> </DriveToCheck>
<!--><DriveToCheck> <!--><DriveToCheck>
<DriveName>D:</DriveName> <DriveName>D:</DriveName>
<SpaceThreshold>120000</SpaceThreshold> <SpaceThreshold>120</SpaceThreshold>
</DriveToCheck><--> </DriveToCheck><-->
</SpaceMonitoring> </SpaceMonitoring>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment