Выполнение 3 лабораторной работы

This commit is contained in:
2026-11-06 20:26:11 +03:00
parent 0ab3a341aa
commit 87f2a65448
105 changed files with 8359 additions and 25 deletions
+45
View File
@@ -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;
}
}
}
}