-
Notifications
You must be signed in to change notification settings - Fork 769
Fix heartbeat monitoring on Windows - replace deprecated wmic with PowerShell #13555
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
Conversation
Co-authored-by: davidfowl <[email protected]>
…ady handles trimming Co-authored-by: davidfowl <[email protected]>
Co-authored-by: davidfowl <[email protected]>
Co-authored-by: davidfowl <[email protected]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13555Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13555" |
|
WNIC is deprecated - may want to use another command instead https://techcommunity.microsoft.com/blog/windows-itpro-blog/wmi-command-line-wmic-utility-deprecation-next-steps/4039242 |
|
@copilot It's still |
Co-authored-by: davidfowl <[email protected]>
…rsing Co-authored-by: davidfowl <[email protected]>
Co-authored-by: davidfowl <[email protected]>
|
Working: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes heartbeat monitoring on Windows by replacing deprecated wmic commands with modern PowerShell cmdlets using the CIM (Common Information Model) API. The changes address issues where CPU usage showed "N/A" and DCP process detection showed "none" on Windows GitHub Actions runners.
Key changes:
- Replace
wmic cpu get loadpercentagewithGet-CimInstance Win32_Processorand average LoadPercentage across processors - Replace
wmic OS get FreePhysicalMemory,TotalVisibleMemorySizewithGet-CimInstance Win32_OperatingSystem - Replace
wmic processwithGet-Process -Name 'dcp*'using pipe-delimited output for robust parsing
| long.TryParse(parts[0].Trim(), out var freeKb) && | ||
| long.TryParse(parts[1].Trim(), out var totalKb)) |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The long.TryParse calls should specify NumberStyles.Integer and CultureInfo.InvariantCulture to ensure consistent parsing across different system locales. This prevents potential parsing failures on systems with non-English regional settings. Change to long.TryParse(parts[0].Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var freeKb) and long.TryParse(parts[1].Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var totalKb) for consistency with other parsing operations in this file.
| long.TryParse(parts[0].Trim(), out var freeKb) && | |
| long.TryParse(parts[1].Trim(), out var totalKb)) | |
| long.TryParse(parts[0].Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var freeKb) && | |
| long.TryParse(parts[1].Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var totalKb)) |
| int.TryParse(parts[1], out var pid) && | ||
| long.TryParse(parts[2], out var workingSet)) |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The int.TryParse and long.TryParse calls should specify NumberStyles and CultureInfo.InvariantCulture to ensure consistent parsing across different system locales. This prevents potential parsing failures on systems with non-English regional settings. Change to int.TryParse(parts[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var pid) and long.TryParse(parts[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out var workingSet) for consistency with other parsing operations in this file.
| int.TryParse(parts[1], out var pid) && | |
| long.TryParse(parts[2], out var workingSet)) | |
| int.TryParse(parts[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var pid) && | |
| long.TryParse(parts[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out var workingSet)) |
| var match = System.Text.RegularExpressions.Regex.Match(output, @"LoadPercentage=(\d+)"); | ||
| if (match.Success) | ||
| var trimmed = output.Trim(); | ||
| if (double.TryParse(trimmed, out var loadPercentage)) |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The double.TryParse call should specify CultureInfo.InvariantCulture to ensure consistent parsing across different system locales. PowerShell may output decimal numbers with culture-specific separators (e.g., comma vs. period), which could cause parsing to fail on systems with non-English locales. Change to double.TryParse(trimmed, NumberStyles.Float, CultureInfo.InvariantCulture, out var loadPercentage) for consistency with other parsing operations in this file (see lines 130, 194, 222).
| if (double.TryParse(trimmed, out var loadPercentage)) | |
| if (double.TryParse(trimmed, NumberStyles.Float, CultureInfo.InvariantCulture, out var loadPercentage)) |
Description
The heartbeat monitoring tool showed
CPU: N/AandDCP: noneon Windows becausewmic(Windows Management Instrumentation Command-line) is deprecated and not functioning properly on GitHub Actions runners. Replaced allwmiccommands with modern PowerShell cmdlets using CIM (Common Information Model) API.Changes
Get-CimInstance Win32_ProcessorwithMeasure-Object -Averageto handle multi-processor systems correctlyGet-CimInstance Win32_OperatingSystemto get FreePhysicalMemory and TotalVisibleMemorySizeGet-Process -Name 'dcp*'with pipe-delimited output for robust parsing (avoids CSV quoting issues)Key Improvements
Measure-Object -Average|) instead of CSV to avoid issues with commas/quotes in process names-Nameparameter and-ErrorAction SilentlyContinuefor error handlingBefore:
After (expected):
Checklist
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.