Abnormal dotnet-counters output UI with alpine container
Description

Configuration
- dotnet-counters (5.0.236902+5366510b270d0f0ebffc9e36e9496688b20b96c2)
- Alpine docker container
dotnet --info output:

@mikelle-rogers @josalem
Based on the output, it looks like the console line rewriting failed, so it continuously printed on the same line.
What shell and terminal/console were you using?
Do you have a specific base container you were using or was it just a generic Alpine image?
@mikelle-rogers can you see if you can repro this behavior?
Just a generic docker alpine image, I use the docker image with tag mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine, used with the original shell with sh command
used with the original shell
Was this the console on Windows, Linux, or Mac? And specifically, was it a special console like iTerm2 on macOS or the new Windows Terminal on Windows?
I used ubuntu terminal on wsl2 and powershell 7 both on windows terminal. And also on our rancher temp container terminal(not sure what it is)
I tried to repro this behavior on a Windows computer, using an ubuntu terminal on wsl2, but line rewriting worked great. What version of ubuntu were you using?
I'm using Ubuntu 20.04

Out of curiosity, is the container running locally on your machine or are you connecting to a container on a remote machine?
The container is running on remote machine, it's running in a kubernetes cluster on aws
Does running dotnet-trace, in the same environment as dotnet-counters was running in, exhibit similar behavior?
@mikelle-rogers sorry for my late response, no, dotnet-trace collect works as expected, and dotnet-counters collect also works,
dotnet-counters monitor is the only thing I meet that does not work.
And besides, I can reproduce it on my Windows 10 with PowerShell Core 7.1.4 and Powershell 5.
I'm having the same problem, with that same image, when i connect to the container using Portainer. Other tools like top or htop work just fine.
After some investigation, it seems in alpine Console.SetCursorPosition and Console.Clear are not working properly but ANSI escape codes are.
I did some quick and dirty changes to dotnet-counters/Exporters/ConsoleWriter.cs
I added this two methods and replace all references to Console.SetCursorPosition and Console.Clear and re-tested on alpine and it seems to be working fine.
private void SetCursorPosition(int col, int row)
{
Console.Write($"\u001B[{row + 1};{col + 1}H");
}
private static void Clear()
{
Console.WriteLine($"\u001b[H\u001B[J");
}
That was my hunch of what was wrong. dotnet-trace uses this code to handle this kind of issue:
https://github.com/dotnet/diagnostics/blob/e7976ae7bbcf55242d5b1b174c44f1e6991161ed/src/Tools/Common/Commands/Utils.cs#L130-L163
The fix is to have dotnet-counters attempt to use ANSI escape codes if the following attempt to enable vterm passes: https://github.com/dotnet/diagnostics/blob/e7976ae7bbcf55242d5b1b174c44f1e6991161ed/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs#L217