Created
September 8, 2023 10:44
-
-
Save PadreSVK/e502a6c811e1a3e07ffc9b85b7da66c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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