feat: add runtime profiling parity and close config runtime drift

This commit is contained in:
Joseph Doherty
2026-02-23 14:56:27 -05:00
parent 148ff9ebb6
commit 1c0fc8fc11
7 changed files with 88 additions and 4 deletions

View File

@@ -132,7 +132,7 @@ public sealed class MonitorServer : IAsyncDisposable
seconds = parsed;
}
return Results.File(_pprofHandler.CaptureCpuProfile(seconds), "application/octet-stream");
return Results.File(_pprofHandler.CaptureCpuProfile(seconds), "application/json");
});
}
}

View File

@@ -1,4 +1,5 @@
using System.Text;
using System.Diagnostics;
using System.Text.Json;
namespace NATS.Server.Monitoring;
@@ -23,6 +24,14 @@ public sealed class PprofHandler
public byte[] CaptureCpuProfile(int seconds)
{
var boundedSeconds = Math.Clamp(seconds, 1, 120);
return Encoding.UTF8.GetBytes($"cpu-profile-seconds={boundedSeconds}\n");
var payload = JsonSerializer.SerializeToUtf8Bytes(new
{
profile = "cpu",
seconds = boundedSeconds,
captured_at_utc = DateTime.UtcNow,
process_total_cpu_ms = Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds,
thread_count = Process.GetCurrentProcess().Threads.Count,
});
return payload;
}
}