|
|
|
@ -17,22 +17,25 @@ namespace hass_workstation_service.Domain.Sensors
|
|
|
|
|
}
|
|
|
|
|
public override string GetState()
|
|
|
|
|
{
|
|
|
|
|
ManagementObjectCollection collection = _searcher.Get();
|
|
|
|
|
UInt64? totalMemory = null;
|
|
|
|
|
UInt64? freeMemory = null;
|
|
|
|
|
foreach (ManagementObject mo in collection)
|
|
|
|
|
using (ManagementObjectCollection collection = _searcher.Get())
|
|
|
|
|
{
|
|
|
|
|
totalMemory = (UInt64)mo.Properties["TotalVisibleMemorySize"]?.Value;
|
|
|
|
|
freeMemory = (UInt64)mo.Properties["FreePhysicalMemory"]?.Value;
|
|
|
|
|
UInt64? totalMemory = null;
|
|
|
|
|
UInt64? freeMemory = null;
|
|
|
|
|
foreach (ManagementObject mo in collection)
|
|
|
|
|
{
|
|
|
|
|
totalMemory = (UInt64)mo.Properties["TotalVisibleMemorySize"]?.Value;
|
|
|
|
|
freeMemory = (UInt64)mo.Properties["FreePhysicalMemory"]?.Value;
|
|
|
|
|
}
|
|
|
|
|
if (totalMemory != null && freeMemory != null)
|
|
|
|
|
{
|
|
|
|
|
decimal totalMemoryDec = totalMemory.Value;
|
|
|
|
|
decimal freeMemoryDec = freeMemory.Value;
|
|
|
|
|
decimal precentageUsed = 100 - (freeMemoryDec / totalMemoryDec) * 100;
|
|
|
|
|
return precentageUsed.ToString("#.##", CultureInfo.InvariantCulture);
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
if (totalMemory != null && freeMemory != null)
|
|
|
|
|
{
|
|
|
|
|
decimal totalMemoryDec = totalMemory.Value;
|
|
|
|
|
decimal freeMemoryDec = freeMemory.Value;
|
|
|
|
|
decimal precentageUsed = 100 - (freeMemoryDec / totalMemoryDec) * 100;
|
|
|
|
|
return precentageUsed.ToString("#.##", CultureInfo.InvariantCulture);
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public override SensorDiscoveryConfigModel GetAutoDiscoveryConfig()
|
|
|
|
|
{
|
|
|
|
|