Ejemplo n.º 1
0
        public override void Sample()
        {
            if (_listener == null)
            {
                return;
            }

            try
            {
                _threadPoolProxy.GetMaxThreads(out int countWorkerThreadsMax, out int countCompletionThreadsMax);
                _threadPoolProxy.GetAvailableThreads(out int countWorkerThreadsAvail, out int countCompletionThreadsAvail);

                var stats = new ThreadpoolUsageStatsSample(countWorkerThreadsMax, countWorkerThreadsAvail, countCompletionThreadsMax, countCompletionThreadsAvail);

                _transformer.Transform(stats);

                var sample = _listener.Sample();
                _transformer.Transform(sample);
            }
            catch (Exception ex)
            {
                Log.Error($"Unable to get Threadpool stats sample.  No .Net Threadpool metrics will be reported.  Error : {ex}");

                Stop();
            }
        }
Ejemplo n.º 2
0
        public void TransformSample_ThreadpoolUsageStats_CreatesCorrectMetricValues()
        {
            const int countWorkerThreadsRemaining     = 83;
            const int countWorkerThreadsInUse         = 17;
            const int countCompletionThreadsRemaining = 180;
            const int countCompletionThreadsInUse     = 20;

            var generatedMetrics = new Dictionary <string, MetricDataWireModel>();

            Mock.Arrange(() => _metricAggregator
                         .Collect(Arg.IsAny <MetricWireModel>()))
            .DoInstead <MetricWireModel>(m => generatedMetrics.Add(m.MetricName.Name, m.Data));

            var sample = new ThreadpoolUsageStatsSample(countWorkerThreadsRemaining + countWorkerThreadsInUse, countWorkerThreadsRemaining, countCompletionThreadsRemaining + countCompletionThreadsInUse, countCompletionThreadsRemaining);

            _threadStatsTransformer.Transform(sample);

            NrAssert.Multiple(
                () => Assert.AreEqual(4, generatedMetrics.Count),
                () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.GetThreadpoolUsageStatsName(ThreadType.Worker, ThreadStatus.InUse), countWorkerThreadsInUse),
                () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.GetThreadpoolUsageStatsName(ThreadType.Worker, ThreadStatus.Available), countWorkerThreadsRemaining),
                () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.GetThreadpoolUsageStatsName(ThreadType.Completion, ThreadStatus.InUse), countCompletionThreadsInUse),
                () => MetricTestHelpers.CompareMetric(generatedMetrics, MetricNames.GetThreadpoolUsageStatsName(ThreadType.Completion, ThreadStatus.Available), countCompletionThreadsRemaining)
                );
        }
Ejemplo n.º 3
0
        public void threadpool_usage_sample_generated_on_sample()
        {
            // Arrange
            var threadpoolUsageStatsSample = null as ThreadpoolUsageStatsSample;

            Mock.Arrange(() => _threadStatsSampleTransformer.Transform(Arg.IsAny <ThreadpoolUsageStatsSample>()))
            .DoInstead <ThreadpoolUsageStatsSample>(sample => threadpoolUsageStatsSample = sample);

            // Act
            _sampleAction();

            // Assert
            Assert.NotNull(threadpoolUsageStatsSample);
        }