c# - Reading RAM and Disk utilization for VM's in Hyper-V using WMI Classes -


i new wmi classes, want read cpu, ram , disk utilization different virtual machines on hyper-v using wmi classes in c# code.

cpu utilization: able using properties processorload , processorloadhistory

     managementbaseobject outparams = virtualsystemservice.invokemethod("getsummaryinformation", inparams, null);       managementbaseobject[] summaryinformationarray = (managementbaseobject[])outparams["summaryinformation"]; 

ram utilization: not able exact value of current ram utilization dynamic , static allocation. virtualquantity , reservation proprty of 'msvm_memorysettingdata' class gives startup ram value in case of dynamic ram , minimum value of ram allocated in case of static ram.

harddisk utilization: not able harddisk utilization of each virtual machine.

my code is:

public static managementobject gettargetcomputer(string vmelementname, managementscope scope)     {         string query = string.format("select * msvm_computersystem elementname = '{0}'", vmelementname);          managementobjectsearcher searcher = new managementobjectsearcher(scope, new objectquery(query));          managementobjectcollection computers = searcher.get();          managementobject computer = null;          foreach (managementobject instance in computers)         {             computer = instance;             break;         }         return computer;     }  void getsummaryinformation(managementobject virtualsystemsettings, uint32[] requestedinformation, managementobject virtualsystemservice)     {         managementbaseobject inparams = virtualsystemservice.getmethodparameters("getsummaryinformation");         string[] settingpaths = new string[1];         settingpaths[0] = virtualsystemsettings.path.path;         inparams["settingdata"] = settingpaths;         inparams["requestedinformation"] = requestedinformation;         managementbaseobject outparams = virtualsystemservice.invokemethod("getsummaryinformation", inparams, null);          uint32 v = (uint32)outparams["returnvalue"];          if ((uint32)outparams["returnvalue"] == 0)         {             managementbaseobject[] summaryinformationarray = (managementbaseobject[])outparams["summaryinformation"];              foreach (managementbaseobject summaryinformation in summaryinformationarray)             {                  foreach (uint32 requested in requestedinformation)                 {                     string name = summaryinformation["name"].tostring();                     switch (requested)//103, 106, 109, 104, 3, 4, 101, 105                     {                          case 103:                             string memoryusage = summaryinformation["memoryusage"].tostring();                             break;                         case 112:                             int32 memoryavailable = (int32)summaryinformation["memoryavailable"];                             break;                         case 113:                             int32 availablememorybuffer = (int32)summaryinformation["availablememorybuffer"];                             break;                     }                 }             }         }         else         {             console.writeline("failed retrieve virtual system summary information");         }          inparams.dispose();         outparams.dispose();     }   managementobject virtualsystem = gettargetcomputer(vm["elementname"].tostring(), scope);              managementobjectcollection virtualsystemsettings = virtualsystem.getrelated            (                "msvm_virtualsystemsettingdata",                "msvm_settingsdefinestate",                null,                null,                "settingdata",                "managedelement",                false,                null            );             managementobject virtualsystemsetting = null;                            foreach (managementobject instance in virtualsystemsettings)             {                 virtualsystemsetting = instance;                  foreach (managementobject memorysettingdata in virtualsystemsetting.getrelated("msvm_memorysettingdata"))                 {                     string heartbeat = (string)memorysettingdata["heartbeat"];                     string memoryusage = (string)memorysettingdata["memoryusage"];                     string virtualquantity = (string)memorysettingdata["virtualquantity"];                     string limit = (string)memorysettingdata["limit"];                 }               }             uint32[] requestedinfo = { 103, 112, 113 };             getsummaryinformation(virtualsystemsetting, requestedinfo, virtualsystemservice); 

is possible current ram utilization , harddisk utilization of each individual virtual machine in hyper-v using wmi classes ?

to find out ram utilization, may want check out following 'hyper-v dynamic memory' example:

https://code.msdn.microsoft.com/windowsdesktop/hyper-v-dynamic-memory-9b0b1d05

it may provide insight on how obtain other information looking for.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -