Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
internal class StartupHook
{
public static void Initialize()
{
new Thread(PollGCMetrics)
{
IsBackground = true,
Name = "GCMetricsPoller"
}.Start();
}
private static void PollGCMetrics()
{
var dogstatsdConfig = new StatsdConfig
{
StatsdServerName = "127.0.0.1",
StatsdPort = 8125,
};
using var dogStatsdService = new DogStatsdService();
dogStatsdService.Configure(dogstatsdConfig);
while (true)
{
var gen0 = GC.CollectionCount(0);
var gen1 = GC.CollectionCount(1);
var gen2 = GC.CollectionCount(2);
dogStatsdService.Gauge("GC.Gen0", gen0);
dogStatsdService.Gauge("GC.Gen1", gen1);
dogStatsdService.Gauge("GC.Gen2", gen2);
Thread.Sleep(1000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment