public void Can_use_uds_socket_reporter_with_options()
        {
            // Arrange
            var filter        = new MetricsFilter().WhereType(MetricType.Apdex);
            var flushInterval = TimeSpan.FromDays(1);
            var settings      = new SocketSettings();

            settings.Address = defaultUnixAddress;
            var options = new MetricsReportingSocketOptions();

            options.Filter                 = filter;
            options.FlushInterval          = flushInterval;
            options.MetricsOutputFormatter = new TestMetricsFormatter();
            options.SocketSettings         = settings;
            var builder = new MetricsBuilder().Report.OverUds(options);

            // Act
            var metrics = builder.Build();

            // Assert
            metrics.Reporters.Should().Contain(reportMetrics => reportMetrics is SocketMetricsReporter);
            metrics.Reporters.First().FlushInterval.Should().Be(flushInterval);
            metrics.Reporters.First().Filter.Should().BeSameAs(filter);
            metrics.Reporters.First().Formatter.Should().BeOfType <TestMetricsFormatter>();
        }
Ejemplo n.º 2
0
 public DefaultSocketClient(MetricsReportingSocketOptions options)
 {
     _options         = options;
     _socketClient    = CreateSocketClient(options.SocketSettings);
     _socketPolicy    = options.SocketPolicy;
     _failureAttempts = 0;
 }
        public void Socket_metrics_reporter_expect_output_formatter()
        {
            // Arrange
            Action action = () =>
            {
                var options = new MetricsReportingSocketOptions();

                // Act
                var reporter = new SocketMetricsReporter(options);
            };

            // Assert
            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Add the <see cref="SocketMetricsReporter" /> allowing metrics to be reported over TCP.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="options">The Socket reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder OverTcp(
            this IMetricsReportingBuilder reportingBuilder,
            MetricsReportingSocketOptions options)
        {
            if (reportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(reportingBuilder));
            }

            options.SocketSettings.ProtocolType = ProtocolType.Tcp;

            var provider = new SocketMetricsReporter(options);

            return(reportingBuilder.Using(provider));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Add the <see cref="SocketMetricsReporter" /> allowing metrics to be reported over TCP.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="setupAction">The Socket reporting options to use.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder OverTcp(
            this IMetricsReportingBuilder reportingBuilder,
            Action <MetricsReportingSocketOptions> setupAction)
        {
            if (reportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(reportingBuilder));
            }

            var options = new MetricsReportingSocketOptions();

            setupAction?.Invoke(options);

            options.SocketSettings.ProtocolType = ProtocolType.Tcp;

            var provider = new SocketMetricsReporter(options);

            return(reportingBuilder.Using(provider));
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Add the <see cref="SocketMetricsReporter" /> allowing metrics to be reported over Unix Domain Sockets.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="metricsOutputFormatter">
        ///     The <see cref="IMetricsOutputFormatter" /> used to configure metrics output formatter.
        /// </param>
        /// <param name="address">The Unix Domain Socket endpoint address where metrics are POSTed.</param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder OverUds(
            this IMetricsReportingBuilder reportingBuilder,
            IMetricsOutputFormatter metricsOutputFormatter,
            string address)
        {
            if (reportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(reportingBuilder));
            }

            var options = new MetricsReportingSocketOptions
            {
                SocketSettings         = new SocketSettings(ProtocolType.IP, address, 0),
                MetricsOutputFormatter = metricsOutputFormatter
            };
            var provider = new SocketMetricsReporter(options);

            return(reportingBuilder.Using(provider));
        }
        public async Task Can_flush_metrics_via_sockets_with_options()
        {
            // Arrange
            var filter    = new MetricsFilter().WhereType(MetricType.Apdex);
            var formatter = new TestMetricsFormatter();
            var interval  = TimeSpan.FromDays(1);
            var settings  = new SocketSettings(defaultProtocol, defaultAddress, defaultPort);
            var options   = new MetricsReportingSocketOptions
            {
                Filter                 = filter,
                FlushInterval          = interval,
                MetricsOutputFormatter = formatter,
                SocketSettings         = settings
            };
            var reporter = new SocketMetricsReporter(options);
            var snapshot = new MetricsDataValueSource(DateTime.Now, Enumerable.Empty <MetricsContextValueSource>());

            // Act
            var result = await reporter.FlushAsync(snapshot, CancellationToken.None);

            // Assert
            result.Should().BeTrue();
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     Add the <see cref="SocketMetricsReporter" /> allowing metrics to be reported over TCP.
        /// </summary>
        /// <param name="reportingBuilder">
        ///     The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
        /// </param>
        /// <param name="metricsOutputFormatter">
        ///     The <see cref="IMetricsOutputFormatter" /> used to configure metrics reporters.
        /// </param>
        /// <param name="address">The TCP endpoint address where metrics are POSTed.</param>
        /// <param name="port">The TCP endpoint port where metrics are POSTed.</param>
        /// <param name="flushInterval">
        ///     The <see cref="T:System.TimeSpan" /> interval used if intended to schedule metrics
        ///     reporting.
        /// </param>
        /// <returns>
        ///     An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
        /// </returns>
        public static IMetricsBuilder OverTcp(
            this IMetricsReportingBuilder reportingBuilder,
            IMetricsOutputFormatter metricsOutputFormatter,
            string address,
            int port,
            TimeSpan flushInterval)
        {
            if (reportingBuilder == null)
            {
                throw new ArgumentNullException(nameof(reportingBuilder));
            }

            var options = new MetricsReportingSocketOptions
            {
                SocketSettings         = new SocketSettings(ProtocolType.Tcp, address, port),
                MetricsOutputFormatter = metricsOutputFormatter,
                FlushInterval          = flushInterval
            };

            var provider = new SocketMetricsReporter(options);

            return(reportingBuilder.Using(provider));
        }