예제 #1
0
        public override async Task <CollectResult> Collect()
        {
            var coll = WmiHelper.WmiQuery(Device, String.Format("SELECT * FROM Win32_LogicalDisk WHERE Name = '{0}:'", DriveLetter));

            // Count usage of each OS instance (should really be only one!)
            decimal total = 0;
            decimal free  = 0;
            int     count = 0;

            foreach (ManagementObject queryObj in coll)
            {
                object o = queryObj["FreeSpace"];
                count++;
                free += (decimal)Convert.ChangeType(o, typeof(decimal));
                o     = queryObj["Size"];
                count++;
                total += (decimal)Convert.ChangeType(o, typeof(decimal));
            }

            // Average them out
            if (count > 0)
            {
                switch (Measurement)
                {
                case DiskMeasurement.BytesFree:
                    return(new CollectResult(free));

                case DiskMeasurement.BytesUsed:
                    return(new CollectResult(total - free));

                case DiskMeasurement.MegabytesFree:
                    return(new CollectResult(free / 1024 / 1024));

                case DiskMeasurement.MegabytesUsed:
                    return(new CollectResult((total - free) / 1024 / 1024));

                case DiskMeasurement.PercentFree:
                    return(new CollectResult((free / total) * 100));

                case DiskMeasurement.PercentUsed:
                    return(new CollectResult(1 - (free / total) * 100));
                }
            }

            // Failed!
            throw new Exception("No disk query found!");
        }
예제 #2
0
        public override async Task <CollectResult> Collect()
        {
            var coll = WmiHelper.WmiQuery(Device, "SELECT * FROM Win32_PerfFormattedData_PerfOS_System");

            // Count usage of each OS instance (should really be only one!)
            decimal total = 0;
            int     count = 0;

            foreach (ManagementObject queryObj in coll)
            {
                object o = queryObj["FileDataOperationsPersec"];
                count++;
                total += (decimal)Convert.ChangeType(o, typeof(decimal));
            }

            // Average them out
            if (count > 0)
            {
                return(new CollectResult(total / count));
            }

            // Failed!
            throw new Exception("No disk query found!");
        }