コード例 #1
0
        static void Main(string[] args)
        {
            var pathToFolderWithMetrics = args[0];
            var pathToTestedRepository  = args[1];

            var volumeMetricsProvider = new VolumeMetricsProvider(pathToFolderWithMetrics);
            var allFilesData          = volumeMetricsProvider.ProvideVolumeMetrics();

            var gitConnector             = new GitProvider(pathToTestedRepository);
            var volumeMetricsWithCommits = gitConnector.AddCommitsMetrics(allFilesData);

            var basicMetricsProvider = new BasicMetricsProvider(pathToFolderWithMetrics);
            var basicMetrics         = basicMetricsProvider.ProvideBasicMetrics();

            var metricsAggregator = new MetricsAggregator();
            var aggregatedMetrics = metricsAggregator.AggregateMetrics(basicMetrics, volumeMetricsWithCommits);

            var additionalInformationCreator = new AdditionalInformationCreator();

            additionalInformationCreator.SaveToFileLimitValues(aggregatedMetrics);
            additionalInformationCreator.SaveToFileAsJson(aggregatedMetrics);

            var treeStructureConverter   = new TreeStructureConverter();
            var treeStructureMetrics     = treeStructureConverter.GenerateTreeStructureFromPaths(aggregatedMetrics);
            var jsonTreeStructureMetrics = JsonConvert.SerializeObject(treeStructureMetrics);

            File.WriteAllText(Directory.GetCurrentDirectory() + "\\OutputsFiles\\FinalStatisticsOutput.json", jsonTreeStructureMetrics);
        }
コード例 #2
0
        public void AddsProcessCpuUsageUsesMEtric()
        {
            var eventListenerMock = new Mock <ISimpleEventListener>();
            ConcurrentDictionary <string, MetricsData> metrics = new ConcurrentDictionary <string, MetricsData>();
            const double cpuValue = 1.1;
            MetricsData  cpuUsage = new MetricsData()
            {
                Name         = "cpu-usage",
                Measurements = new List <Measurement>()
                {
                    new Measurement()
                    {
                        Value = cpuValue
                    }
                },
            };

            metrics.TryAdd("cpu-usage", cpuUsage);
            eventListenerMock.Setup(x => x.Metrics).Returns(metrics);

            var systemStatisticsProviderMock = new Mock <ISystemStatisticsProvider>();

            var basicMetricsProvider = new BasicMetricsProvider(loggerMock, eventListenerMock.Object, systemStatisticsProviderMock.Object);

            basicMetricsProvider.GetMetricNames().Should().Contain("process.cpu.usage");
            var metric = basicMetricsProvider.GetMetricByName("process.cpu.usage");

            metric.Measurements.First().Value.Should().Be(cpuValue);
        }
コード例 #3
0
        public void AddsJvmThreadsDaemon()
        {
            var eventListenerMock = new Mock <ISimpleEventListener>();
            ConcurrentDictionary <string, MetricsData> metrics = new ConcurrentDictionary <string, MetricsData>();

            eventListenerMock.Setup(x => x.Metrics).Returns(metrics);

            var systemStatisticsProviderMock = new Mock <ISystemStatisticsProvider>();
            var basicMetricsProvider         = new BasicMetricsProvider(loggerMock, eventListenerMock.Object, systemStatisticsProviderMock.Object);

            basicMetricsProvider.GetMetricNames().Should().Contain("jvm.threads.daemon");
            var metric = basicMetricsProvider.GetMetricByName("jvm.threads.daemon");

            metric.Measurements.First().Value.Should().Be(0);
        }
コード例 #4
0
        public void AddsSystemCpuCount()
        {
            var eventListenerMock = new Mock <ISimpleEventListener>();
            ConcurrentDictionary <string, MetricsData> metrics = new ConcurrentDictionary <string, MetricsData>();

            eventListenerMock.Setup(x => x.Metrics).Returns(metrics);

            var systemStatisticsProviderMock = new Mock <ISystemStatisticsProvider>();
            var basicMetricsProvider         = new BasicMetricsProvider(loggerMock, eventListenerMock.Object, systemStatisticsProviderMock.Object);

            basicMetricsProvider.GetMetricNames().Should().Contain("system.cpu.count");
            var metric = basicMetricsProvider.GetMetricByName("system.cpu.count");

            metric.Measurements.First().Value.Should().Be(System.Environment.ProcessorCount);
        }
コード例 #5
0
        public void AddsProcessCpuUsageEvenIfNoMetric()
        {
            var eventListenerMock = new Mock <ISimpleEventListener>();
            ConcurrentDictionary <string, MetricsData> metrics = new ConcurrentDictionary <string, MetricsData>();

            eventListenerMock.Setup(x => x.Metrics).Returns(metrics);

            var systemStatisticsProviderMock = new Mock <ISystemStatisticsProvider>();

            var basicMetricsProvider = new BasicMetricsProvider(loggerMock, eventListenerMock.Object, systemStatisticsProviderMock.Object);

            basicMetricsProvider.GetMetricNames().Should().Contain("process.cpu.usage");
            var metric = basicMetricsProvider.GetMetricByName("process.cpu.usage");

            metric.Measurements.First().Value.Should().BeGreaterOrEqualTo(0.0001);
        }
コード例 #6
0
        public void UsesMetricsBySimpleEventListener()
        {
            var eventListenerMock = new Mock <ISimpleEventListener>();
            ConcurrentDictionary <string, MetricsData> metrics = new ConcurrentDictionary <string, MetricsData>();
            MetricsData metric = new MetricsData();

            metrics.TryAdd("test", metric);
            eventListenerMock.Setup(x => x.Metrics).Returns(metrics);

            var systemStatisticsProviderMock = new Mock <ISystemStatisticsProvider>();

            var basicMetricsProvider = new BasicMetricsProvider(loggerMock, eventListenerMock.Object, systemStatisticsProviderMock.Object);

            basicMetricsProvider.GetMetricNames().Should().Contain("test");
            basicMetricsProvider.GetMetricByName("test").Should().Be(metric);
        }
コード例 #7
0
        public void AddsJvmThreadsPeak()
        {
            var eventListenerMock = new Mock <ISimpleEventListener>();
            ConcurrentDictionary <string, MetricsData> metrics = new ConcurrentDictionary <string, MetricsData>();

            eventListenerMock.Setup(x => x.Metrics).Returns(metrics);

            var systemStatisticsProviderMock = new Mock <ISystemStatisticsProvider>();
            var basicMetricsProvider         = new BasicMetricsProvider(loggerMock, eventListenerMock.Object, systemStatisticsProviderMock.Object);

            basicMetricsProvider.GetMetricNames().Should().Contain("jvm.threads.peak");
            var metric      = basicMetricsProvider.GetMetricByName("jvm.threads.peak");
            int threadCount = Process.GetCurrentProcess().Threads.Count;

            metric.Measurements.First().Value.Should().Be(threadCount);

            // todo move this logic to get the threadcoun to systemstatsprovider, for easier and better test
        }
コード例 #8
0
        public void AddsSystemCpuUsage()
        {
            var eventListenerMock = new Mock <ISimpleEventListener>();
            ConcurrentDictionary <string, MetricsData> metrics = new ConcurrentDictionary <string, MetricsData>();

            eventListenerMock.Setup(x => x.Metrics).Returns(metrics);

            var          systemStatisticsProviderMock = new Mock <ISystemStatisticsProvider>();
            const double systemCpuUsage = 2.2;

            systemStatisticsProviderMock.Setup(x => x.Metric).Returns(systemCpuUsage);

            var basicMetricsProvider = new BasicMetricsProvider(loggerMock, eventListenerMock.Object, systemStatisticsProviderMock.Object);

            basicMetricsProvider.GetMetricNames().Should().Contain("system.cpu.usage");
            var metric = basicMetricsProvider.GetMetricByName("system.cpu.usage");

            metric.Measurements.First().Value.Should().Be(systemCpuUsage);
        }
コード例 #9
0
        public void AddsProcessUptime()
        {
            var eventListenerMock = new Mock <ISimpleEventListener>();
            ConcurrentDictionary <string, MetricsData> metrics = new ConcurrentDictionary <string, MetricsData>();

            eventListenerMock.Setup(x => x.Metrics).Returns(metrics);

            var systemStatisticsProviderMock = new Mock <ISystemStatisticsProvider>();

            TimeSpan uptime = new TimeSpan(0, 1, 0);

            systemStatisticsProviderMock.Setup(x => x.GetProcessUptime()).Returns(uptime);

            var basicMetricsProvider = new BasicMetricsProvider(loggerMock, eventListenerMock.Object, systemStatisticsProviderMock.Object);

            basicMetricsProvider.GetMetricNames().Should().Contain("process.uptime");
            var metric = basicMetricsProvider.GetMetricByName("process.uptime");

            metric.Measurements.First().Value.Should().Be(uptime.TotalSeconds);
        }
コード例 #10
0
        public void AddsJvmGcPause()
        {
            var eventListenerMock = new Mock <ISimpleEventListener>();
            ConcurrentDictionary <string, MetricsData> metrics = new ConcurrentDictionary <string, MetricsData>();

            eventListenerMock.Setup(x => x.Metrics).Returns(metrics);

            var firstEvent = new MetricsData()
            {
                Name         = "% Time in GC since last GC",
                Measurements = new List <Measurement>()
                {
                    new Measurement()
                    {
                        Statistic = "VALUE", Value = 50
                    }
                },
                AvailableTags = new List <AvailableTag>()
                {
                    new AvailableTag()
                    {
                        Tag = "StandardDeviation", Values = new Dictionary <string, double> {
                            { "StandardDeviation", 0.0 }
                        },
                    },
                    new AvailableTag()
                    {
                        Tag = "Count", Values = new Dictionary <string, double> {
                            { "Count", 1.0 }
                        },
                    },
                    new AvailableTag()
                    {
                        Tag = "Min", Values = new Dictionary <string, double> {
                            { "Min", 0.0 }
                        },
                    },
                    new AvailableTag()
                    {
                        Tag = "Max", Values = new Dictionary <string, double> {
                            { "Max", 0.0 }
                        },
                    },
                    new AvailableTag()
                    {
                        Tag = "IntervalSec", Values = new Dictionary <string, double> {
                            { "IntervalSec", 1.0 }
                        },
                    },
                    new AvailableTag()
                    {
                        Tag = "Series", Values = new Dictionary <string, double> {
                            { "Series", 1000.0 }
                        },
                    },
                },
            };

            var secondEvent = new MetricsData()
            {
                Name         = "% Time in GC since last GC",
                Measurements = new List <Measurement>()
                {
                    new Measurement()
                    {
                        Statistic = "VALUE", Value = 25
                    }
                },
                AvailableTags = new List <AvailableTag>()
                {
                    new AvailableTag()
                    {
                        Tag = "StandardDeviation", Values = new Dictionary <string, double> {
                            { "StandardDeviation", 0.0 }
                        },
                    },
                    new AvailableTag()
                    {
                        Tag = "Count", Values = new Dictionary <string, double> {
                            { "Count", 1.0 }
                        },
                    },
                    new AvailableTag()
                    {
                        Tag = "Min", Values = new Dictionary <string, double> {
                            { "Min", 0.0 }
                        },
                    },
                    new AvailableTag()
                    {
                        Tag = "Max", Values = new Dictionary <string, double> {
                            { "Max", 0.0 }
                        },
                    },
                    new AvailableTag()
                    {
                        Tag = "IntervalSec", Values = new Dictionary <string, double> {
                            { "IntervalSec", 1.0 }
                        },
                    },
                    new AvailableTag()
                    {
                        Tag = "Series", Values = new Dictionary <string, double> {
                            { "Series", 1000.0 }
                        },
                    },
                },
            };

            var systemStatisticsProviderMock = new Mock <ISystemStatisticsProvider>();

            systemStatisticsProviderMock.Setup(x => x.GetGCCount()).Returns(2);
            var basicMetricsProvider = new BasicMetricsProvider(loggerMock, eventListenerMock.Object, systemStatisticsProviderMock.Object);

            eventListenerMock.Raise(x => x.GCCollectionEvent += null, new GcTotalTimeEventArgs(firstEvent));
            eventListenerMock.Raise(x => x.GCCollectionEvent += null, new GcTotalTimeEventArgs(secondEvent));

            basicMetricsProvider.GetMetricNames().Should().Contain("jvm.gc.pause");
            var metric = basicMetricsProvider.GetMetricByName("jvm.gc.pause");

            metric.Measurements.Should().HaveCount(3);

            metric.Measurements.First(x => x.Statistic == "COUNT").Value.Should().Be(2);
            metric.Measurements.First(x => x.Statistic == "TOTAL_TIME").Value.Should().Be(0.75);
            metric.Measurements.First(x => x.Statistic == "MAX").Value.Should().Be(0.5);
        }