feat: add runtime profiling parity and close config runtime drift
This commit is contained in:
@@ -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");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user