Example #1
0
        public void ReturnLogEventsOfSize(SizeBucket sizeBucket, int want)
        {
            // Arrange
            // Below512B
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(1, 1 * ByteSize.B));
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(1, 512 * ByteSize.B - 1));

            // Between512BAnd1KB
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(2, 512 * ByteSize.B));
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(2, 1 * ByteSize.KB - 1));

            // Between1And5KB
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(3, 1 * ByteSize.KB));
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(3, 5 * ByteSize.KB - 1));

            // Between5And10KB
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(4, 5 * ByteSize.KB));
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(4, 10 * ByteSize.KB - 1));

            // Between10And50KB
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(5, 10 * ByteSize.KB));
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(5, 50 * ByteSize.KB - 1));

            // Between50And100KB
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(6, 50 * ByteSize.KB));
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(6, 100 * ByteSize.KB - 1));

            // Between100And512KB
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(7, 100 * ByteSize.KB));
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(7, 512 * ByteSize.KB - 1));

            // Between512KBAnd1MB
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(8, 512 * ByteSize.KB));
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(8, 1 * ByteSize.MB - 1));

            // Between1And5MB
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(9, 1 * ByteSize.MB));
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(9, 5 * ByteSize.MB - 1));

            // EqualToAndAbove5MB
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(10, 5 * ByteSize.MB));
            _statistics.ReportReceivedBatch("", "", 1, 1, Repeat(10, 10 * ByteSize.MB));

            // Act
            var got = _statistics.LogEventsOfSize(sizeBucket);

            // Assert
            got.ShouldBe(want);
        }
Example #2
0
        private void OnTick(object?state)
        {
            if (state != null && ((CancellationToken)state).IsCancellationRequested)
            {
                return;
            }

            if (_statistics.Start == null)
            {
                _logger.LogInformation("Waiting for log events...");
                return;
            }

            var now = _clock.Now;

            var messageBuilder = new StringBuilder();

            messageBuilder.AppendFormatted("start                                  {0:O}", _statistics.Start);
            messageBuilder.AppendFormatted("duration                               {0}", now.Subtract(_statistics.Start ?? now));
            messageBuilder.AppendNewLine();
            messageBuilder.AppendLine("batches");
            messageBuilder.AppendTabbedFormatted("content-type                       {0}", _statistics.ContentType);
            messageBuilder.AppendTabbedFormatted("content-encoding                   {0}", _statistics.ContentEncoding);
            messageBuilder.AppendTabbedFormatted("count                              {0}", _statistics.ContentLength.Count);
            messageBuilder.AppendTabbedFormatted("per second                         {0:N2}", _statistics.RequestsPerSecond);
            messageBuilder.AppendTabbedFormatted("size uncompressed (min/avg/max)    {0} / {1} / {2}",
                                                 ByteSize.FriendlyValue(_statistics.BatchSize.Min),
                                                 ByteSize.FriendlyValue(_statistics.BatchSize.Average),
                                                 ByteSize.FriendlyValue(_statistics.BatchSize.Max));

            if (!string.IsNullOrEmpty(_statistics.ContentEncoding))
            {
                messageBuilder.AppendTabbedFormatted("size compressed (min/avg/max)      {0} / {1} / {2}",
                                                     ByteSize.FriendlyValue(_statistics.ContentLength.Min),
                                                     ByteSize.FriendlyValue(_statistics.ContentLength.Average),
                                                     ByteSize.FriendlyValue(_statistics.ContentLength.Max));
                messageBuilder.AppendTabbedFormatted("compression ratio                  {0:N2}", _statistics.CompressionRatio);
            }

            var rows = new[]
            {
                new DistributionRow("                                             size < 512 B  {0,9} |{1}", _statistics.BatchesOfSize(SizeBucket.Below512B)),
                new DistributionRow("                                   512 B  <= size < 1 KB   {0,9} |{1}", _statistics.BatchesOfSize(SizeBucket.Between512BAnd1KB)),
                new DistributionRow("                                   1K B   <= size < 5 KB   {0,9} |{1}", _statistics.BatchesOfSize(SizeBucket.Between1And5KB)),
                new DistributionRow("                                   5K B   <= size < 10 KB  {0,9} |{1}", _statistics.BatchesOfSize(SizeBucket.Between5And10KB)),
                new DistributionRow("                                   10K B  <= size < 50 KB  {0,9} |{1}", _statistics.BatchesOfSize(SizeBucket.Between10And50KB)),
                new DistributionRow("                                   50K B  <= size < 100 KB {0,9} |{1}", _statistics.BatchesOfSize(SizeBucket.Between50And100KB)),
                new DistributionRow("                                   100 KB <= size < 512 KB {0,9} |{1}", _statistics.BatchesOfSize(SizeBucket.Between100And512KB)),
                new DistributionRow("                                   512 KB <= size < 1 MB   {0,9} |{1}", _statistics.BatchesOfSize(SizeBucket.Between512KBAnd1MB)),
                new DistributionRow("                                   1 MB   <= size < 5 MB   {0,9} |{1}", _statistics.BatchesOfSize(SizeBucket.Between1And5MB)),
                new DistributionRow("                                   5 MB   <= size          {0,9} |{1}", _statistics.BatchesOfSize(SizeBucket.EqualToAndAbove5MB)),
            };

            messageBuilder.AppendTabbedFormatted("distribution");
            foreach (var(template, nbrOfBatches) in rows)
            {
                messageBuilder.AppendTabbedFormatted(template, nbrOfBatches, new string('#', (int)Math.Round(20.0 * nbrOfBatches / _statistics.BatchSize.Count)));
            }

            _logger.LogInformation(messageBuilder.ToString());

            messageBuilder.AppendNewLine();
            messageBuilder.AppendLine("log events");
            messageBuilder.AppendTabbedFormatted("count                              {0}", _statistics.LogEventSize.Count);
            messageBuilder.AppendTabbedFormatted("per second                         {0:N2}", _statistics.LogEventsPerSecond);
            messageBuilder.AppendTabbedFormatted("size (min/avg/max)                 {0} / {1} / {2}",
                                                 ByteSize.FriendlyValue(_statistics.LogEventSize.Min),
                                                 ByteSize.FriendlyValue(_statistics.LogEventSize.Average),
                                                 ByteSize.FriendlyValue(_statistics.LogEventSize.Max));
            messageBuilder.AppendTabbedFormatted("per batch (min/avg/max)            {0} / {1:N2} / {2}",
                                                 _statistics.LogEventsPerBatch.Min,
                                                 _statistics.LogEventsPerBatch.Average,
                                                 _statistics.LogEventsPerBatch.Max);

            rows = new[]
            {
                new DistributionRow("                                             size < 512 B  {0,9} |{1}", _statistics.LogEventsOfSize(SizeBucket.Below512B)),
                new DistributionRow("                                   512 B  <= size < 1 KB   {0,9} |{1}", _statistics.LogEventsOfSize(SizeBucket.Between512BAnd1KB)),
                new DistributionRow("                                   1K B   <= size < 5 KB   {0,9} |{1}", _statistics.LogEventsOfSize(SizeBucket.Between1And5KB)),
                new DistributionRow("                                   5K B   <= size < 10 KB  {0,9} |{1}", _statistics.LogEventsOfSize(SizeBucket.Between5And10KB)),
                new DistributionRow("                                   10K B  <= size < 50 KB  {0,9} |{1}", _statistics.LogEventsOfSize(SizeBucket.Between10And50KB)),
                new DistributionRow("                                   50K B  <= size < 100 KB {0,9} |{1}", _statistics.LogEventsOfSize(SizeBucket.Between50And100KB)),
                new DistributionRow("                                   100 KB <= size < 512 KB {0,9} |{1}", _statistics.LogEventsOfSize(SizeBucket.Between100And512KB)),
                new DistributionRow("                                   512 KB <= size < 1 MB   {0,9} |{1}", _statistics.LogEventsOfSize(SizeBucket.Between512KBAnd1MB)),
                new DistributionRow("                                   1 MB   <= size < 5 MB   {0,9} |{1}", _statistics.LogEventsOfSize(SizeBucket.Between1And5MB)),
                new DistributionRow("                                   5 MB   <= size          {0,9} |{1}", _statistics.LogEventsOfSize(SizeBucket.EqualToAndAbove5MB)),
            };

            messageBuilder.AppendTabbedFormatted("distribution");

            foreach (var(template, nbrOfLogEvents) in rows)
            {
                messageBuilder.AppendTabbedFormatted(template, nbrOfLogEvents, new string('#', (int)Math.Round(40.0 * nbrOfLogEvents / _statistics.LogEventSize.Count)));
            }

            _logger.LogInformation(messageBuilder.ToString());
        }