public void TestPerformanceCounterSourceForTransientInstance()
        {
            var config = TestUtility.GetConfig("Sources", "PerformanceCounter");
            var performanceCounterSource = new PerformanceCounterSource(new PluginContext(config, NullLogger.Instance, null));

            performanceCounterSource.Start();
            var results = performanceCounterSource.Query(null);
            var metrics = results.Data as ICollection <KeyValuePair <MetricKey, MetricValue> >;

            Assert.True(metrics.Count > 0);
            Assert.Contains(metrics, m => m.Value.Value > 0);

            Process p = Process.Start("notepad.exe"); // Start a new process by running the notepad.exe

            // Query the process again
            var newResults = performanceCounterSource.Query(null);
            var newMetrics = newResults.Data as ICollection <KeyValuePair <MetricKey, MetricValue> >;

            // Find the different processes between the old process list and new process list
            var diff = newMetrics.Where(n => !metrics.Any(m => m.Key.Id == n.Key.Id)).ToList();

            // If the difference contains the new process, return true
            Assert.True(diff.Where(m => m.Key.Category.Equals("Process") && m.Key.Id.Contains("notepad")).ToList().Count > 0);

            // Kill the process
            p.Kill();

            performanceCounterSource.Stop();
        }
        public void TestUnitInference()
        {
            Assert.Equal(MetricUnit.Percent, PerformanceCounterSource.InferUnit(null, "% Total Run Time"));
            Assert.Equal(MetricUnit.Percent, PerformanceCounterSource.InferUnit(null, "Data Map Hits %"));
            Assert.Equal(MetricUnit.Percent, PerformanceCounterSource.InferUnit(null, "Slow Tier Destaged Container Fill Ratio (%)"));

            Assert.Equal(MetricUnit.CountSecond, PerformanceCounterSource.InferUnit(null, "Page Table Evictions/sec"));
            Assert.Equal(MetricUnit.CountSecond, PerformanceCounterSource.InferUnit(null, "Requests / Sec"));
            Assert.Equal(MetricUnit.BytesSecond, PerformanceCounterSource.InferUnit(null, "Bytes Received/sec"));
            Assert.Equal(MetricUnit.BytesSecond, PerformanceCounterSource.InferUnit(null, "IL Bytes Jitted / sec"));

            Assert.Equal(MetricUnit.Bytes, PerformanceCounterSource.InferUnit(null, "Bytes Received By Disconnected Clients"));
            Assert.Equal(MetricUnit.Bytes, PerformanceCounterSource.InferUnit(null, "In - Total bytes received"));
            Assert.Equal(MetricUnit.Megabytes, PerformanceCounterSource.InferUnit(null, "Total MBytes"));
            Assert.Equal(MetricUnit.Kilobytes, PerformanceCounterSource.InferUnit(null, " Available KBytes"));

            Assert.Equal(MetricUnit.Seconds, PerformanceCounterSource.InferUnit(null, "Duration - Duration of the session (Seconds)"));
            Assert.Equal(MetricUnit.Seconds, PerformanceCounterSource.InferUnit(null, "Avg. sec/Request"));
            Assert.Equal(MetricUnit.Milliseconds, PerformanceCounterSource.InferUnit(null, "File lock acquire average milliseconds"));
            Assert.Equal(MetricUnit.Milliseconds, PerformanceCounterSource.InferUnit(null, "I/O Database Reads (Attached) Average Latency"));
            Assert.Equal(MetricUnit.HundredNanoseconds, PerformanceCounterSource.InferUnit(null, "Slow tier destage read latency (100 ns)"));
            //This should be count per second
            Assert.Equal(MetricUnit.CountSecond, PerformanceCounterSource.InferUnit(null, "I/O Database Reads (Recovery) Abnormal Latency/sec"));

            Assert.Equal(MetricUnit.Count, PerformanceCounterSource.InferUnit(null, "Monitored Notifications"));
        }
示例#3
0
        public void TestCombinedCounters_DuplicateCounters()
        {
            var config = TestUtility.GetConfig("Sources", "SystemAndProcessorCounter");
            var performanceCounterSource = new PerformanceCounterSource(new PluginContext(config, NullLogger.Instance, null));

            performanceCounterSource.Start();
            var results = performanceCounterSource.Query(null);
            var metrics = results.Data;

            Assert.Equal(3 * (Environment.ProcessorCount + 1) + 2, metrics.Count);
            performanceCounterSource.Stop();
        }
示例#4
0
        public void TestLoadNonExistingCategory()
        {
            var config = TestUtility.GetConfig("Sources", "NonExistingCategory");
            var performanceCounterSource = new PerformanceCounterSource(new PluginContext(config, NullLogger.Instance, null));

            performanceCounterSource.Start();
            var results = performanceCounterSource.Query(null);
            var metrics = results.Data;

            Assert.Equal(1, metrics.Count);
            performanceCounterSource.Stop();
        }
示例#5
0
        public void TestSingleInstanceCounters_RepeatedCategory()
        {
            var config = TestUtility.GetConfig("Sources", "SystemCounter");
            var performanceCounterSource = new PerformanceCounterSource(new PluginContext(config, NullLogger.Instance, null));

            performanceCounterSource.Start();
            var results = performanceCounterSource.Query(null);
            var metrics = results.Data;

            Assert.Equal(3, metrics.Count);
            performanceCounterSource.Stop();
        }
示例#6
0
        public void TestLoadNonExistingCounters()
        {
            var config = TestUtility.GetConfig("Sources", "NonExistingCounter");
            var performanceCounterSource = new PerformanceCounterSource(new PluginContext(config, NullLogger.Instance, null));

            performanceCounterSource.Start();
            var results = performanceCounterSource.Query(null);

            // Assert that instance '0' has only 1 counter
            Assert.Equal(1, results.Data.Count);
            performanceCounterSource.Stop();
        }
        public void TestPerformanceCounterSource()
        {
            var config = TestUtility.GetConfig("Sources", "PerformanceCounter");
            var performanceCounterSource = new PerformanceCounterSource(new PluginContext(config, NullLogger.Instance, null));

            performanceCounterSource.Start();
            var results = performanceCounterSource.Query(null);
            var metrics = results.Data as ICollection <KeyValuePair <MetricKey, MetricValue> >;

            Assert.True(metrics.Count > 0);
            Assert.Contains(metrics, m => m.Value.Value > 0);
            performanceCounterSource.Stop();
        }
示例#8
0
        public void TestPerformanceCounterSource()
        {
            var config = TestUtility.GetConfig("Sources", "PerformanceCounter");
            var performanceCounterSource = new PerformanceCounterSource(new PluginContext(config, NullLogger.Instance, null, _bookmarkManager));

            performanceCounterSource.Start();
            var results = performanceCounterSource.Query(null);
            var metrics = results.Data;

            Assert.True(metrics.Count > 0);
            Assert.Contains(metrics, m => m.Value.Value > 0);
            performanceCounterSource.Stop();
        }
示例#9
0
        public void TestMultiInstanceCounters_RepeatedCategory()
        {
            var config = TestUtility.GetConfig("Sources", "ProcessorCounter");
            var performanceCounterSource = new PerformanceCounterSource(new PluginContext(config, NullLogger.Instance, null));

            performanceCounterSource.Start();
            var results = performanceCounterSource.Query(null);
            var metrics = results.Data;

            // 'ProcessorCounter' source has 5 counters for each processor
            // the number of instances is #processor + 1 to account for the "_Total" instance
            Assert.Equal(5 * (Environment.ProcessorCount + 1), metrics.Count);
            performanceCounterSource.Stop();
        }
示例#10
0
        public void when_querying_for_a_metric_in_a_particular_instances_then_the_instances_do_not_need_to_be_read()
        {
            var mockPerformanceCounter = new Mock <IPerformanceCounter>();
            var mockPerformanceCounterCategoryRepository = new Mock <IPerformanceCounterCategoryRepository>();

            mockPerformanceCounterCategoryRepository.Setup(m => m.GetInstances(It.IsAny <string>())).Returns(new[] { "foo" });

            var source = new PerformanceCounterSource(new PerformanceCounterRegistryTestHarness(_registryDictionary, (a, b, c) => mockPerformanceCounter.Object), mockPerformanceCounterCategoryRepository.Object);

            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            source.QueryValue("\\category(instance)\\counter").ToList();

            mockPerformanceCounterCategoryRepository.Verify(m => m.GetInstances(It.IsAny <string>()), Times.Never);
        }
示例#11
0
        public void TestPerformanceCounterSourceWithInstanceRegex()
        {
            var config = TestUtility.GetConfig("Sources", "PerformanceCounterWithInstanceRegex");
            var performanceCounterSource = new PerformanceCounterSource(new PluginContext(config, NullLogger.Instance, null));

            performanceCounterSource.Start();
            var results = performanceCounterSource.Query(null);
            var metrics = results.Data as ICollection <KeyValuePair <MetricKey, MetricValue> >;

            Assert.True(metrics.Count > 0);
            Regex instanceRegex = new Regex("^Local Area Connection\\* \\d$");

            Assert.All(metrics, m => Assert.Matches(instanceRegex, m.Key.Id));
            performanceCounterSource.Stop();
        }
示例#12
0
        public void TestAdditionalCounters_SameInstance()
        {
            var config = TestUtility.GetConfig("Sources", "FirstAndAllProcessorCounter");
            var performanceCounterSource = new PerformanceCounterSource(new PluginContext(config, NullLogger.Instance, null));

            performanceCounterSource.Start();
            var results = performanceCounterSource.Query(null);

            // Assert that instance '0' has 2 counters
            Assert.Equal(2, results.Data.Count(m => m.Key.Id == "0"));

            // Assert that instance '_Total' has 1 counter
            Assert.Equal(1, results.Data.Count(m => m.Key.Id == "_Total"));
            performanceCounterSource.Stop();
        }
示例#13
0
        public void TestDuplicatedInstanceInRegex(string sourceName)
        {
            var config = TestUtility.GetConfig("Sources", sourceName);
            var performanceCounterSource = new PerformanceCounterSource(new PluginContext(config, NullLogger.Instance, null));

            performanceCounterSource.Start();
            var results = performanceCounterSource.Query(null);

            // Assert the number of data points = #processor
            Assert.Equal(Environment.ProcessorCount, results.Data.Count);

            // Assert single counter for processor '0'
            Assert.Equal(1, results.Data.Count(m => m.Key.Id == "0"));

            performanceCounterSource.Stop();
        }
示例#14
0
        public void if_a_metric_is_being_queried_for_the_first_time_it_returns_no_value()
        {
            var mockPerformanceCounter = new Mock <IPerformanceCounter>();

            mockPerformanceCounter.Setup(m => m.NextValue()).Returns(5.0f);

            var mockPerformanceCounterCategoryRepository = new Mock <IPerformanceCounterCategoryRepository>();

            mockPerformanceCounterCategoryRepository.Setup(m => m.GetInstances(It.IsAny <string>())).Returns(new[] { "foo" });

            var source = new PerformanceCounterSource(new PerformanceCounterRegistryTestHarness(_registryDictionary, (a, b, c) => mockPerformanceCounter.Object), mockPerformanceCounterCategoryRepository.Object);

            var samples = source.QueryValue("\\category(*)\\counter").ToList();

            Assert.That(samples.Count, Is.EqualTo(0));
        }
示例#15
0
        public void TestLoadNonExistingInstances()
        {
            var config = TestUtility.GetConfig("Sources", "NonExistingInstance");
            var performanceCounterSource = new PerformanceCounterSource(new PluginContext(config, NullLogger.Instance, null));

            performanceCounterSource.Start();
            var results = performanceCounterSource.Query(null);

            Assert.Equal(2, results.Data.Count);

            // Assert that instance 'a' has no counters
            Assert.Equal(0, results.Data.Count(m => m.Key.Id == "a"));

            // Assert that instance '0' has 2 counters
            Assert.Equal(2, results.Data.Count(m => m.Key.Id == "0"));
            performanceCounterSource.Stop();
        }
示例#16
0
        public void if_a_metric_is_being_queried_for_the_second_time_it_returns_a_measured_value()
        {
            var mockPerformanceCounter = new Mock <IPerformanceCounter>();

            mockPerformanceCounter.Setup(m => m.NextValue()).Returns(5.0f);

            var mockPerformanceCounterCategoryRepository = new Mock <IPerformanceCounterCategoryRepository>();

            mockPerformanceCounterCategoryRepository.Setup(m => m.GetInstances(It.IsAny <string>())).Returns(new[] { "foo" });

            var source = new PerformanceCounterSource(new PerformanceCounterRegistryTestHarness(_registryDictionary, (a, b, c) => mockPerformanceCounter.Object), mockPerformanceCounterCategoryRepository.Object);

            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            source.QueryValue("\\category(*)\\counter").ToList();
            var samples = source.QueryValue("\\category(*)\\counter").ToList();

            Assert.That(samples.Count, Is.EqualTo(1));
            Assert.That(samples.First().Value, Is.EqualTo(5.0f));
        }