Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 14, 2025

Description

The heartbeat monitoring tool showed CPU: N/A and DCP: none on Windows because wmic (Windows Management Instrumentation Command-line) is deprecated and not functioning properly on GitHub Actions runners. Replaced all wmic commands with modern PowerShell cmdlets using CIM (Common Information Model) API.

Changes

  • CPU detection: Use Get-CimInstance Win32_Processor with Measure-Object -Average to handle multi-processor systems correctly
  • Memory detection: Use Get-CimInstance Win32_OperatingSystem to get FreePhysicalMemory and TotalVisibleMemorySize
  • DCP process detection: Use Get-Process -Name 'dcp*' with pipe-delimited output for robust parsing (avoids CSV quoting issues)

Key Improvements

  1. Multi-processor support: CPU load is averaged across all processors using Measure-Object -Average
  2. Robust parsing: DCP process info uses pipe delimiter (|) instead of CSV to avoid issues with commas/quotes in process names
  3. Modern API: CIM cmdlets work reliably on all Windows versions (Windows Server 2016+, Windows 10+)
  4. Efficient queries: Direct filtering with -Name parameter and -ErrorAction SilentlyContinue for error handling

Before:

HEARTBEAT | CPU: N/A | Mem: 0 MB (process) | ... | DCP: none

After (expected):

HEARTBEAT | CPU: 15.2% | Mem: 8.5/16.0 GB (53%) | ... | DCP: 2 procs (150MB) [dcp(1234):75MB, ...]

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No
Original prompt

The heartbeat we added to the run-tests github workflow doesnt work on windows. Ir shows rhis


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix heartbeat issue in run-tests workflow for Windows Fix heartbeat monitoring on Windows - handle wmic output formatting Dec 14, 2025
Copilot AI requested a review from davidfowl December 14, 2025 15:17
@github-actions
Copy link
Contributor

github-actions bot commented Dec 14, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13555

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13555"

@afscrome
Copy link
Contributor

@davidfowl
Copy link
Member

@copilot It's still

Copy link
Contributor Author

Copilot AI commented Dec 14, 2025

@copilot It's still

Fixed in 1ac9379. The issue was that wmic is deprecated and not working properly on Windows. Replaced with PowerShell cmdlets:

  • CPU: Get-CimInstance Win32_Processor
  • Memory: Get-CimInstance Win32_OperatingSystem
  • DCP processes: Get-Process with CSV output

Copilot AI changed the title Fix heartbeat monitoring on Windows - handle wmic output formatting Fix heartbeat monitoring on Windows - replace deprecated wmic with PowerShell Dec 14, 2025
@radical
Copy link
Member

radical commented Dec 15, 2025

Working: [2025-12-14T23:07:16.2765285Z] HEARTBEAT | CPU: 3.0% | Mem: 4.0/16.0 GB (25%) | Net: 22 est, 46 listen, 1 tw | Docker: 0 containers | DCP: 1 procs (22MB) [dcp(5728):22MB]

@radical radical marked this pull request as ready for review December 15, 2025 00:37
Copilot AI review requested due to automatic review settings December 15, 2025 00:37
@radical radical merged commit 54e0a00 into main Dec 15, 2025
565 of 569 checks passed
@radical radical deleted the copilot/fix-heartbeat-windows-issue branch December 15, 2025 00:38
@dotnet-policy-service dotnet-policy-service bot added this to the 13.2 milestone Dec 15, 2025
Copy link
Contributor

Copilot AI left a 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 loadpercentage with Get-CimInstance Win32_Processor and average LoadPercentage across processors
  • Replace wmic OS get FreePhysicalMemory,TotalVisibleMemorySize with Get-CimInstance Win32_OperatingSystem
  • Replace wmic process with Get-Process -Name 'dcp*' using pipe-delimited output for robust parsing

Comment on lines +264 to +265
long.TryParse(parts[0].Trim(), out var freeKb) &&
long.TryParse(parts[1].Trim(), out var totalKb))
Copy link

Copilot AI Dec 15, 2025

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.

Suggested change
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))

Copilot uses AI. Check for mistakes.
Comment on lines +363 to +364
int.TryParse(parts[1], out var pid) &&
long.TryParse(parts[2], out var workingSet))
Copy link

Copilot AI Dec 15, 2025

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.

Suggested change
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))

Copilot uses AI. Check for mistakes.
var match = System.Text.RegularExpressions.Regex.Match(output, @"LoadPercentage=(\d+)");
if (match.Success)
var trimmed = output.Trim();
if (double.TryParse(trimmed, out var loadPercentage))
Copy link

Copilot AI Dec 15, 2025

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).

Suggested change
if (double.TryParse(trimmed, out var loadPercentage))
if (double.TryParse(trimmed, NumberStyles.Float, CultureInfo.InvariantCulture, out var loadPercentage))

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants