/// <summary>
        ///     Add the <see cref="MetricsStatsDStringOutputFormatter" /> allowing metrics to be reported to StatsD over TCP.
        /// </summary>
        /// <param name="metricsReportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="setupAction">The StatsD reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToStatsDTcp(
            this IMetricsReportingBuilder metricsReportingBuilder,
            Action <MetricsReportingStatsDOptions> setupAction)
        {
            if (metricsReportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricsReportingBuilder));
            }

            var options = new MetricsReportingStatsDOptions();

            setupAction?.Invoke(options);

            var formatter = new MetricsStatsDStringOutputFormatter(options.StatsDOptions);

            return(metricsReportingBuilder.OverTcp(
                       opt =>
            {
                opt.MetricsOutputFormatter = formatter;
                opt.FlushInterval = options.FlushInterval;
                opt.SocketSettings = options.SocketSettings;
                opt.SocketPolicy = options.SocketPolicy;
                opt.Filter = options.Filter;
            }));
        }
Пример #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="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,
            MetricFields fields = null)
        {
            if (metricFormattingBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricFormattingBuilder));
            }

            var formatter = new MetricsStatsDStringOutputFormatter(fields);

            return(metricFormattingBuilder.Using(formatter, false));
        }
Пример #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.");
        }
Пример #4
0
        /// <summary>
        ///     Add the <see cref="MetricsStatsDStringOutputFormatter" /> allowing metrics to be reported to StatsD over UDP.
        /// </summary>
        /// <param name="metricsReportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="options">The StatsD reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder ToStatsDUdp(
            this IMetricsReportingBuilder metricsReportingBuilder,
            MetricsReportingStatsDOptions options)
        {
            if (metricsReportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricsReportingBuilder));
            }

            var formatter = new MetricsStatsDStringOutputFormatter(options.StatsDOptions);

            return(metricsReportingBuilder.OverUdp(
                       opt =>
            {
                opt.MetricsOutputFormatter = formatter;
                opt.FlushInterval = TimeSpan.Zero;
                opt.SocketSettings = options.SocketSettings;
                opt.SocketPolicy = options.SocketPolicy;
                opt.Filter = options.Filter;
            }));
        }
Пример #5
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 StatsD formatting
        ///     options.
        /// </param>
        /// <param name="setupAction">The StatsD 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,
            Action <MetricsStatsDOptions> setupAction,
            MetricFields fields = null)
        {
            if (metricFormattingBuilder == null)
            {
                throw new ArgumentNullException(nameof(metricFormattingBuilder));
            }

            if (setupAction == null)
            {
                throw new ArgumentNullException(nameof(setupAction));
            }

            var options = new MetricsStatsDOptions();

            setupAction(options);

            var formatter = new MetricsStatsDStringOutputFormatter(options, fields);

            return(metricFormattingBuilder.Using(formatter, false));
        }