Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use workFolder root as target for disk space monitoring #4609

Merged
14 changes: 5 additions & 9 deletions src/Agent.Worker/ResourceMetricsManager.cs
Expand Up @@ -102,7 +102,7 @@ public async Task RunDiskSpaceUtilizationMonitor()

if (freeDiskSpacePercentage <= AVAILABLE_DISK_SPACE_PERCENTAGE_THRESHOLD)
{
_context.Warning(StringUtil.Loc("ResourceMonitorFreeDiskSpaceIsLowerThanThreshold", diskInfo.VolumeLabel, AVAILABLE_DISK_SPACE_PERCENTAGE_THRESHOLD, $"{usedDiskSpacePercentage:0.00}"));
_context.Warning(StringUtil.Loc("ResourceMonitorFreeDiskSpaceIsLowerThanThreshold", diskInfo.VolumeRoot, AVAILABLE_DISK_SPACE_PERCENTAGE_THRESHOLD, $"{usedDiskSpacePercentage:0.00}"));

break;
}
Expand Down Expand Up @@ -180,23 +180,19 @@ private struct DiskInfo
{
public long TotalDiskSpaceMB;
public long FreeDiskSpaceMB;
public string VolumeLabel;
public string VolumeRoot;
}

private DiskInfo GetDiskInfo()
{
DiskInfo diskInfo = new();

string root = Path.GetPathRoot(System.Reflection.Assembly.GetEntryAssembly().Location);
string root = Path.GetPathRoot(_context.GetVariableValueOrDefault(Constants.Variables.Agent.WorkFolder));
var driveInfo = new DriveInfo(root);

diskInfo.TotalDiskSpaceMB = driveInfo.TotalSize / 1048576;
diskInfo.FreeDiskSpaceMB = driveInfo.AvailableFreeSpace / 1048576;

if (PlatformUtil.RunningOnWindows)
{
diskInfo.VolumeLabel = $"{root} {driveInfo.VolumeLabel}";
}
diskInfo.VolumeRoot = root;

return diskInfo;
}
Expand All @@ -207,7 +203,7 @@ private string GetDiskInfoString()
{
var diskInfo = GetDiskInfo();

return StringUtil.Loc("ResourceMonitorDiskInfo", diskInfo.VolumeLabel, $"{diskInfo.FreeDiskSpaceMB:0.00}", $"{diskInfo.TotalDiskSpaceMB:0.00}");
return StringUtil.Loc("ResourceMonitorDiskInfo", diskInfo.VolumeRoot, $"{diskInfo.FreeDiskSpaceMB:0.00}", $"{diskInfo.TotalDiskSpaceMB:0.00}");

}
catch (Exception ex)
Expand Down
6 changes: 3 additions & 3 deletions src/Misc/layoutbin/en-US/strings.json
Expand Up @@ -489,11 +489,11 @@
"Replace": "replace? (Y/N)",
"RepositoryNotExist": "Can't update repository, the repository does not exist.",
"ResourceMonitorAgentEnvironmentResource": "Agent environment resources - {0}, {1}, {2}",
"ResourceMonitorCPUInfo": "CPU: usage - {0}",
"ResourceMonitorCPUInfo": "CPU: Usage {0}%",
"ResourceMonitorCPUInfoError": "Unable to get CPU info, exception: {0}",
"ResourceMonitorDiskInfo": "Disk: Volume {0} - Available {1} MB out of {2} MB",
"ResourceMonitorDiskInfo": "Disk: {0} Available {1} MB out of {2} MB",
"ResourceMonitorDiskInfoError": "Unable to get disk info, exception: {0}",
"ResourceMonitorFreeDiskSpaceIsLowerThanThreshold": "Free disk space on volume {0} is lower than {1}%; Currently used: {2}%",
"ResourceMonitorFreeDiskSpaceIsLowerThanThreshold": "Free disk space on {0} is lower than {1}%; Currently used: {2}%",
"ResourceMonitorMemoryInfo": "Memory: Used {0} MB out of {1} MB",
"ResourceMonitorMemoryInfoError": "Unable to get memory info, exception: {0}",
"ResourceMonitorMemorySpaceIsLowerThanThreshold": "Free memory is lower than {0}%; Currently used: {1}%",
Expand Down