Updated the GetVirtualMachineInternal to return the correct HDD and RAM usage using the WSP VMconfig service
This commit is contained in:
parent
14b28939bb
commit
9a9ee5ecca
2 changed files with 39 additions and 1 deletions
|
@ -20,5 +20,8 @@ namespace WebsitePanel.Providers.Virtualization
|
|||
|
||||
public const Int64 Size1G = 0x40000000;
|
||||
public const Int64 Size1M = 0x100000;
|
||||
|
||||
public const string KVP_RAM_SUMMARY_KEY = "VM-RAM-Summary";
|
||||
public const string KVP_HDD_SUMMARY_KEY = "VM-HDD-Summary";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,7 +152,10 @@ namespace WebsitePanel.Providers.Virtualization
|
|||
vm.Name = result[0].GetProperty("Name").ToString();
|
||||
vm.State = result[0].GetEnum<VirtualMachineState>("State");
|
||||
vm.CpuUsage = ConvertNullableToInt32(result[0].GetProperty("CpuUsage"));
|
||||
vm.RamUsage = Convert.ToInt32(ConvertNullableToInt64(result[0].GetProperty("MemoryAssigned")) / Constants.Size1M);
|
||||
// This does not truly give the RAM usage, only the memory assigned to the VPS
|
||||
// Lets handle detection of total memory and usage else where
|
||||
//vm.RamUsage = Convert.ToInt32(ConvertNullableToInt64(result[0].GetProperty("MemoryAssigned")) / Constants.Size1M);
|
||||
vm.RamSize = Convert.ToInt32(ConvertNullableToInt64(result[0].GetProperty("MemoryStartup")) / Constants.Size1M);
|
||||
vm.Uptime = Convert.ToInt64(result[0].GetProperty<TimeSpan>("UpTime").TotalMilliseconds);
|
||||
vm.Status = result[0].GetProperty("Status").ToString();
|
||||
vm.ReplicationState = result[0].GetProperty("ReplicationState").ToString();
|
||||
|
@ -192,6 +195,38 @@ namespace WebsitePanel.Providers.Virtualization
|
|||
// network adapters
|
||||
vm.Adapters = NetworkAdapterHelper.Get(PowerShell, vm.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the WebsitePanel VMConfig Windows service to get the RAM usage as well as the HDD usage / sizes
|
||||
List<KvpExchangeDataItem> vmKvps = GetKVPItems(vmId);
|
||||
foreach (KvpExchangeDataItem vmKvp in vmKvps)
|
||||
{
|
||||
// RAM
|
||||
if (vmKvp.Name == Constants.KVP_RAM_SUMMARY_KEY)
|
||||
{
|
||||
string[] ram = vmKvp.Data.Split(':');
|
||||
int freeRam = Int32.Parse(ram[0]);
|
||||
int availRam = Int32.Parse(ram[1]);
|
||||
|
||||
vm.RamUsage = availRam - freeRam;
|
||||
}
|
||||
|
||||
// HDD
|
||||
if (vmKvp.Name == Constants.KVP_HDD_SUMMARY_KEY)
|
||||
{
|
||||
string[] disksArray = vmKvp.Data.Split(';');
|
||||
vm.HddLogicalDisks = new LogicalDisk[disksArray.Length];
|
||||
for (int i = 0; i < disksArray.Length; i++)
|
||||
{
|
||||
string[] disk = disksArray[i].Split(':');
|
||||
vm.HddLogicalDisks[i] = new LogicalDisk();
|
||||
vm.HddLogicalDisks[i].DriveLetter = disk[0];
|
||||
vm.HddLogicalDisks[i].FreeSpace = Int32.Parse(disk[1]);
|
||||
vm.HddLogicalDisks[i].Size = Int32.Parse(disk[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue