Example #1
0
        public void GetSummaryInfo(Dictionary<string, VmStatsEntry> vmProcessorInfo, List<System.Management.ManagementPath> vmsToInspect)
        {
            // Process info available from WMI,
            // See http://msdn.microsoft.com/en-us/library/hh850062(v=vs.85).aspx
            uint[] requestedInfo = new uint[] {  // TODO: correct?
                    0, // Name
                    1, // ElementName
                    4, // Number of processes
                    101 // ProcessorLoad
                };

            System.Management.ManagementBaseObject[] sysSummary;
            var vmsvc = GetVirtualisationSystemManagementService();
            System.Management.ManagementPath[] vmPaths = vmsToInspect.ToArray();
            vmsvc.GetSummaryInformation(requestedInfo, vmPaths, out sysSummary);

            foreach (var summary in sysSummary)
            {

                var summaryInfo = new SummaryInformation(summary);

                logger.Debug("VM " + summaryInfo.Name + "(elementName " + summaryInfo.ElementName + ") has " +
                                summaryInfo.NumberOfProcessors + " CPUs, and load of " + summaryInfo.ProcessorLoad);
                var vmInfo = new VmStatsEntry
                {
                    cpuUtilization = summaryInfo.ProcessorLoad,
                    numCPUs = summaryInfo.NumberOfProcessors,
                    networkReadKBs = 1,
                    networkWriteKBs = 1,
                    entityType = "vm"
                };
                vmProcessorInfo.Add(summaryInfo.ElementName, vmInfo);
            }
        }
        public JContainer GetVmStatsCommand([FromBody]dynamic cmd)
        {
            bool result = false;
            string details = null;
            JArray vmNamesJson = cmd.vmNames;
            string[] vmNames = vmNamesJson.ToObject<string[]>();
            Dictionary<string, VmStatsEntry> vmProcessorInfo = new Dictionary<string,VmStatsEntry>(vmNames.Length);

            var vmsToInspect = new List<System.Management.ManagementPath>();
            foreach (var vmName in vmNames)
            {
                var sys = WmiCalls.GetComputerSystem(vmName);
                if (sys == null)
                {
                    logger.InfoFormat("GetVmStatsCommand requested unknown VM {0}", vmNames);
                    continue;
                }
                var sysInfo = WmiCalls.GetVmSettings(sys);
                vmsToInspect.Add(sysInfo.Path);
            }

            // Process info available from WMI,
            // See http://msdn.microsoft.com/en-us/library/cc160706%28v=vs.85%29.aspx
            uint[] requestedInfo = new uint[] {
                    0, // Name
                    1, // ElementName
                    4, // Number of processes
                    101 // ProcessorLoad
                };

            System.Management.ManagementBaseObject[] sysSummary;
            var vmsvc = WmiCalls.GetVirtualisationSystemManagementService();
            System.Management.ManagementPath[] vmPaths =  vmsToInspect.ToArray();
            vmsvc.GetSummaryInformation(requestedInfo, vmPaths, out sysSummary);

            foreach (var summary in sysSummary)
            {
                var summaryInfo = new CloudStack.Plugin.AgentShell.ROOT.VIRTUALIZATION.SummaryInformation(summary);

                logger.Debug("VM " + summaryInfo.Name + "(elementName " + summaryInfo.ElementName + ") has " +
                                summaryInfo.NumberOfProcessors + " CPUs, and load of " + summaryInfo.ProcessorLoad);
                var vmInfo = new VmStatsEntry
                {
                    cpuUtilization = summaryInfo.ProcessorLoad,
                    numCPUs = summaryInfo.NumberOfProcessors,
                    networkReadKBs = 1,
                    networkWriteKBs = 1,
                    entityType = "vm"
                };
                vmProcessorInfo.Add(summaryInfo.ElementName, vmInfo);
            }

            // TODO: Network usage comes from Performance Counter API; however it is only available in kb/s, and not in total terms.
            // Curious about these?  Use perfmon to inspect them, e.g. http://msdn.microsoft.com/en-us/library/xhcx5a20%28v=vs.100%29.aspx
            // Recent post on these counter at http://blogs.technet.com/b/cedward/archive/2011/07/19/hyper-v-networking-optimizations-part-6-of-6-monitoring-hyper-v-network-consumption.aspx
            result = true;

            object ansContent = new
            {
                vmInfos = vmProcessorInfo,
                result = result,
                details = details,
            };
            return ReturnCloudStackTypedJArray(ansContent, CloudStackTypes.GetVmStatsAnswer);
        }