示例#1
0
        public static void SendThrowsIfTransportIsNullMetrics()
        {
            // Arrange
            IStatsDTransport     transport = null;
            IEnumerable <string> metrics   = Array.Empty <string>();

            // Act and Assert
            Assert.Throws <ArgumentNullException>("transport", () => transport.Send(metrics));
        }
示例#2
0
        public static void SendThrowsIfTransportIsNullMetric()
        {
            // Arrange
            IStatsDTransport transport = null;
            string           metric    = "metric";

            // Act and Assert
            Assert.Throws <ArgumentNullException>("transport", () => transport.Send(metric));
        }
        internal BufferBasedStatsDPublisher(StatsDConfiguration configuration, IStatsDTransport transport)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _onError   = configuration.OnError;
            _transport = transport;
            _formatter = new StatsDUtf8Formatter(configuration.Prefix);
        }
        public static void Constructor_Throws_If_Transport_Is_Null()
        {
            // Arrange
            var configuration          = new StatsDConfiguration();
            IStatsDTransport transport = null;

            // Act and Assert
            Assert.Throws <ArgumentNullException>(
                "transport",
                () => new StatsDPublisher(configuration, transport));
        }
示例#5
0
        public StatsDPublisher(StatsDConfiguration configuration, IStatsDTransport transport)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _transport = transport ?? throw new ArgumentNullException(nameof(transport));

            _formatter = new StatsDMessageFormatter(configuration.Culture, configuration.Prefix);
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StatsDPublisher"/> class for the specified transport.
        /// </summary>
        /// <param name="configuration">The StatsD configuration to use.</param>
        /// <param name="transport">The transport implementation to use.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="configuration"/> or <paramref name="transport"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="configuration"/> is invalid, such as an invalid hostname or IP address.
        /// </exception>
        public StatsDPublisher(StatsDConfiguration configuration, IStatsDTransport transport)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

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

            _inner = new BufferBasedStatsDPublisher(configuration, transport);

            _transport        = transport;
            _disposeTransport = false;
        }
        /// <summary>
        /// Sends the specified metric to the StatsD server.
        /// </summary>
        /// <param name="transport">The <see cref="IStatsDTransport"/> to use.</param>
        /// <param name="metric">The metric to send.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="transport"/> or <paramref name="metric"/> is <see langword="null"/>.
        /// </exception>
        public static void Send(this IStatsDTransport transport, string metric)
        {
            if (transport == null)
            {
                throw new ArgumentNullException(nameof(transport));
            }

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

            var buffer  = Encoding.UTF8.GetBytes(metric);
            var segment = new ArraySegment <byte>(buffer);

            transport.Send(segment);
        }
        /// <summary>
        /// Sends the specified metrics to the StatsD server.
        /// </summary>
        /// <param name="transport">The <see cref="IStatsDTransport"/> to use.</param>
        /// <param name="metrics">The metric(s) to send.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="transport"/> or <paramref name="metrics"/> is <see langword="null"/>.
        /// </exception>
        public static void Send(this IStatsDTransport transport, IEnumerable <string> metrics)
        {
            if (transport == null)
            {
                throw new ArgumentNullException(nameof(transport));
            }

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

            foreach (string metric in metrics)
            {
                transport.Send(metric);
            }
        }
示例#9
0
        public StatsDPublisher(StatsDConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (string.IsNullOrWhiteSpace(configuration.Host))
            {
                throw new ArgumentNullException(nameof(configuration.Host));
            }

            _formatter = new StatsDMessageFormatter(configuration.Culture, configuration.Prefix);

            var endpointSource = EndpointParser.MakeEndPointSource(
                configuration.Host, configuration.Port, configuration.DnsLookupInterval);

            _transport = new UdpTransport(endpointSource);
        }
示例#10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StatsDPublisher"/> class using the default transport.
        /// </summary>
        /// <param name="configuration">The StatsD configuration to use.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="configuration"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="configuration"/> is invalid, such as an invalid hostname or IP address.
        /// </exception>
        public StatsDPublisher(StatsDConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (string.IsNullOrWhiteSpace(configuration.Host))
            {
                throw new ArgumentException("No hostname or IP address is set.", nameof(configuration));
            }

            var endpointSource = EndPointFactory.MakeEndPointSource(
                configuration.Host !, configuration.Port, configuration.DnsLookupInterval);

            var transport = new SocketTransport(endpointSource, configuration.SocketProtocol);

            _transport        = transport;
            _disposeTransport = true;

            _inner = new BufferBasedStatsDPublisher(configuration, transport);
        }
 public BufferBasedStatsDPublisher(StatsDConfiguration configuration, IStatsDTransport transport)
 {
     _onError   = configuration.OnError;
     _transport = transport;
     _formatter = new StatsDUtf8Formatter(configuration.Prefix);
 }