Skip to content

Instantly share code, notes, and snippets.

@PadreSVK
Created September 8, 2023 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PadreSVK/e502a6c811e1a3e07ffc9b85b7da66c6 to your computer and use it in GitHub Desktop.
Save PadreSVK/e502a6c811e1a3e07ffc9b85b7da66c6 to your computer and use it in GitHub Desktop.
using System;
using System.Management;
namespace Chyron.Maps.Render.Maint
{
public class MemoryMetrics
{
public double TotalGB { get; set; }
public double UsedGB { get; set; }
public double FreeGB { get; set; }
public static MemoryMetrics GetMemoryMetrics()
{
var winQuery = new ObjectQuery("SELECT * FROM CIM_OperatingSystem");
var searcher = new ManagementObjectSearcher(winQuery);
MemoryMetrics metrics = default;
foreach (var item in searcher.Get())
{
metrics = new MemoryMetrics
{
TotalGB = Math.Round(double.Parse(item["TotalVisibleMemorySize"].ToString()) / 1024 / 1024, 0),
FreeGB = Math.Round(double.Parse(item["FreePhysicalMemory"].ToString()) / 1024 / 1024, 0),
};
metrics.UsedGB = metrics.TotalGB - metrics.FreeGB;
}
return metrics;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment