Example #1
0
        private async Task <string> Serialize(
            IEnumerable <MetricsDataValueSource> dataValueSource,
            double sampleRate = 1.0)
        {
            var settings = new MetricsStatsDOptions
            {
                DefaultSampleRate   = sampleRate,
                MetricNameFormatter = new DefaultDogStatsDMetricStringSerializer()
            };
            var serializer = new MetricSnapshotSerializer();
            var fields     = new MetricFields();

            await using (var ms = new MemoryStream())
            {
                await using (var packer =
                                 new MetricSnapshotStatsDStringWriter(
                                     ms,
                                     new StatsDPointSampler(settings),
                                     settings))
                {
                    foreach (var source in dataValueSource)
                    {
                        serializer.Serialize(packer, source, fields);
                    }
                }
                return(Encoding.UTF8.GetString(ms.ToArray()));
            }
        }
Example #2
0
        /// <summary>
        ///     Add the <see cref="MetricsStatsDStringOutputFormatter" /> allowing metrics to optionally be reported to Datadog
        /// </summary>
        /// <param name="metricFormattingBuilder">
        ///     The <see cref="IMetricsOutputFormattingBuilder" /> used to configure Datadog formatting
        ///     options.
        /// </param>
        /// <param name="options">The Datadog formatting options to use.</param>
        /// <param name="fields">The metric fields to report as well as their names.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder AsStatsDString(
            this IMetricsOutputFormattingBuilder metricFormattingBuilder,
            MetricsStatsDOptions options,
            MetricFields fields = null)
        {
            if (metricFormattingBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricFormattingBuilder));
            }

            var formatter = new MetricsStatsDStringOutputFormatter(options, fields);

            return(metricFormattingBuilder.Using(formatter, false));
        }
Example #3
0
        public async Task Can_format_CHUNKED_DogStatsD_payload_with_multiple_fields_correctly()
        {
            // Arrange
            var timestamp   = new DateTime(2017, 1, 1, 1, 1, 1, DateTimeKind.Utc);
            var metricsData = CreateSource(timestamp, 4);

            var options = new MetricsStatsDOptions
            {
                MetricNameFormatter = new DefaultDogStatsDMetricStringSerializer()
            };
            var formatter = new MetricsStatsDStringOutputFormatter(options);

            // Act
            var chunks = await formatter.WriteAsync(metricsData, 30, CancellationToken.None);

            // Assert
            chunks.Count.Should().Be(4);
            chunks.All(x => !x.EndsWith("\n")).Should()
            .BeTrue("All metrics in this sample should be transmitted in their own packet.");
        }
 public MetricsReportingStatsDOptions()
 {
     SocketSettings = new SocketSettings();
     SocketPolicy   = new SocketPolicy();
     StatsDOptions  = new MetricsStatsDOptions();
 }
Example #5
0
 public string Write(MetricsStatsDOptions options)
 => _metricStringSerializer.Serialize(this, options);
Example #6
0
 public StatsDPointSampler(MetricsStatsDOptions options)
 {
     _options = options;
 }