using EonaCat.LogStack.Core;
using System;
using System.Diagnostics;

namespace EonaCat.LogStack.Boosters;

/// <summary>
/// Adds a health snapshot: CPU, memory pressure and thread information.
/// </summary>
public sealed class HealthSnapshotBooster : BoosterBase
{
    public HealthSnapshotBooster() : base("HealthSnapshot") { }

    public override bool Boost(ref LogEventBuilder builder)
    {
        try
        {
            using var process = Process.GetCurrentProcess();
            builder.WithProperty("health_memory_mb", process.WorkingSet64 / 1024 / 1024);
            builder.WithProperty("health_threads", process.Threads.Count);
            builder.WithProperty("health_gc_memory_mb", GC.GetTotalMemory(false) / 1024 / 1024);
            builder.WithProperty("health_processor_count", Environment.ProcessorCount);
        }
        catch { }

        return true;
    }
}
