コード例 #1
0
        public static void HyperVPerfCounter()
        {
            HyperVPerfCounter hyperVPerfCounter = new HyperVPerfCounter();

            while (true)
            {
                Thread.Sleep(1000);
                VMHvPerfCounterInfo NetVM2HvPerfCounterInfo = hyperVPerfCounter.GetVMHyperVPerfInfo("NetVM2");
                Console.WriteLine("当前内存压力为:" + Convert.ToString(NetVM2HvPerfCounterInfo.currentPressure));
            }
        }
コード例 #2
0
        public VMHvPerfCounterInfo GetVMHyperVPerfInfo(string VMName)
        {
            bool ret = SetPerCounter(VMName);

            if (ret)
            {
                VMHvPerfCounterInfo vmHvPerfCounterInfo = new VMHvPerfCounterInfo();
                vmHvPerfCounterInfo.VMName              = VMName;
                vmHvPerfCounterInfo.averagePressure     = memoryAveragePressure.NextValue();
                vmHvPerfCounterInfo.currentPressure     = memoryCurrentPressure.NextValue();
                vmHvPerfCounterInfo.availableMemory     = currentAvailableMemory.NextValue();
                vmHvPerfCounterInfo.guestMemory         = guestPhycicalMemory.NextValue();
                vmHvPerfCounterInfo.availablePercentage = vmHvPerfCounterInfo.availableMemory / vmHvPerfCounterInfo.guestMemory;
                return(vmHvPerfCounterInfo);
            }
            else
            {
                return(null);
            }
        }