Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

WMI performance query doesn't return correct data

$
0
0
		private void GetAspNetInfo(Dictionary<string, Dictionary<string, object>> res)
		{
			if (_counter == null)
				_counter = new PerformanceCounter("ASP.NET Apps v4.0.30319", "Requests Total", "__Total__");
			Console.WriteLine(">>>>>>>> {0}\t{1}", _counter.CategoryName + " " + _counter.CounterName, _counter.NextValue());

			if (_searcher2 == null)
				_searcher2 = new ManagementObjectSearcher("SELECT * FROM Win32_PerfFormattedData_ASPNET4030319_ASPNETAppsv4030319");
			Report(_searcher2);
		}

		private static void Report(ManagementObjectSearcher searcher)
		{
			DataLog.Info(string.Format("\r\n--------------------- {0} ---------------------\r\n", searcher.Query));
			foreach (var obj in searcher.Get())
			{
				var message = FormatMessage(obj);
				Console.WriteLine("\r\n{0}\r\n{1}\r\n", obj["Name"], message);
			}
		}

		private static string FormatMessage(ManagementBaseObject obj)
		{
			var properties =
				obj.Properties.Cast<PropertyData>().Where(val => val.Value != null && val.Value.Equals(0)).
				Select(val => string.Format("{0}={1}", val.Name, val.Value)).ToList();
			var message = string.Join(" ", properties);
			return message;
		}

The code above prints the correct result for data retrieved via PerformanceCounter, but the WMI query returns all zero values.

Any ideas why this can be happening?


Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>