From 62d473c7846da206d8de92c59e870463c913b271 Mon Sep 17 00:00:00 2001 From: Maksim Petrov <47208721+vmapetr@users.noreply.github.com> Date: Wed, 7 Feb 2024 18:30:32 +0100 Subject: [PATCH] Use workFolder root as target for disk space monitoring (#4609) * Use workFolder root as target for disk space monitoring * Change disk info output * Minor fixes --- src/Agent.Worker/ResourceMetricsManager.cs | 14 +++++--------- src/Misc/layoutbin/en-US/strings.json | 6 +++--- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Agent.Worker/ResourceMetricsManager.cs b/src/Agent.Worker/ResourceMetricsManager.cs index 06642db97c..68d1071d51 100644 --- a/src/Agent.Worker/ResourceMetricsManager.cs +++ b/src/Agent.Worker/ResourceMetricsManager.cs @@ -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; } @@ -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; } @@ -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) diff --git a/src/Misc/layoutbin/en-US/strings.json b/src/Misc/layoutbin/en-US/strings.json index 7d432ef097..bddbbf382d 100644 --- a/src/Misc/layoutbin/en-US/strings.json +++ b/src/Misc/layoutbin/en-US/strings.json @@ -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}%",