Выполнение работы на 4.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace LoadTest
|
||||
{
|
||||
internal static class Rss
|
||||
{
|
||||
/// <summary>
|
||||
/// RSS процесса приложения в МБ: читает VmRSS из /proc/1/status внутри контейнера
|
||||
/// (PID 1 — dotnet, ENTRYPOINT в exec-форме). Возвращает null, если контейнер не задан или недоступен.
|
||||
/// </summary>
|
||||
public static double? ReadMegabytes(string? container)
|
||||
{
|
||||
if (string.IsNullOrEmpty(container))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var info = new ProcessStartInfo("docker", ["exec", container, "cat", "/proc/1/status"])
|
||||
{
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
};
|
||||
using var process = Process.Start(info)!;
|
||||
var output = process.StandardOutput.ReadToEnd();
|
||||
process.WaitForExit();
|
||||
|
||||
var line = output.Split('\n').FirstOrDefault(l => l.StartsWith("VmRSS:"));
|
||||
if (line is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var kb = double.Parse(line.Split(' ', StringSplitOptions.RemoveEmptyEntries)[1],
|
||||
System.Globalization.CultureInfo.InvariantCulture);
|
||||
return Math.Round(kb / 1024, 1);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user