private static IEndPointSource ResolveEndPointSource(IServiceProvider provider) { var config = provider.GetRequiredService <StatsDConfiguration>(); return(EndpointParser.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval)); }
public void AMetricCanBeSentWithoutAnExceptionBeingThrown() { // Arrange var endPointSource = EndpointParser.MakeEndPointSource( UdpListeners.EndpointA, null); using (var target = new SocketTransport(endPointSource, SocketProtocol.Udp)) { // Act and Assert target.Send("mycustommetric"); } }
public void Setup() { var config = new StatsDConfiguration { Host = "127.0.0.1", }; var endpointSource = EndpointParser.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval); _pooledTransport = new PooledUdpTransport(endpointSource); _unpooledTransport = new UdpTransport(endpointSource); }
public void MultipleMetricsCanBeSentWithoutAnExceptionBeingThrownParallel() { // Arrange var endPointSource = EndpointParser.MakeEndPointSource( UdpListeners.EndpointA, null); using (var target = new SocketTransport(endPointSource, SocketProtocol.Udp)) { Parallel.For(0, 10_000, _ => { // Act and Assert target.Send("mycustommetric:1|c"); }); } }
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); }
private static void Main(string[] args) { var iterations = Enumerable.Range(1, 500000); var endpoint = EndpointParser.MakeEndPointSource("localhost", 3128, null); var client = new UdpTransport(endpoint); var formatter = new StatsDMessageFormatter(CultureInfo.InvariantCulture); var watch = new Stopwatch(); Console.WriteLine("To start - hit ENTER."); Console.ReadLine(); Console.WriteLine("start"); watch.Start(); Parallel.ForEach(iterations, x => client.Send(formatter.Gauge(x, "bucket_sample" + "number-of-messages-to-be-sent"))); watch.Stop(); Console.WriteLine("end - " + watch.ElapsedMilliseconds); Console.ReadLine(); }
public static void EndpointSwitchShouldNotCauseExceptionsParallel() { // Arrange var endPointSource1 = EndpointParser.MakeEndPointSource( UdpListeners.EndpointA, null); var endPointSource2 = EndpointParser.MakeEndPointSource( UdpListeners.EndpointB, null); using (var target = new SocketTransport(new MillisecondSwitcher(endPointSource2, endPointSource1), SocketProtocol.Udp)) { Parallel.For(0, 10_000, _ => { // Act and Assert target.Send("mycustommetric"); }); } }
public static void EndpointSwitchShouldNotCauseExceptionsSequential() { // Arrange var endPointSource1 = EndpointParser.MakeEndPointSource( UdpListeners.EndpointA, null); var endPointSource2 = EndpointParser.MakeEndPointSource( UdpListeners.EndpointB, null); using (var target = new SocketTransport(new MillisecondSwitcher(endPointSource2, endPointSource1), SocketProtocol.Udp)) { for (int i = 0; i < 10_000; i++) { // Act and Assert target.Send("mycustommetric:1|c"); } } }
public void Setup() { var config = new StatsDConfiguration { // if you want verify that stats are recevied, // you will need the IP of suitable local test stats server Host = "127.0.0.1", Prefix = "testmetric" }; var endpointSource = EndpointParser.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval); var udpTransport = new UdpTransport(endpointSource); var ipTransport = new IpTransport(endpointSource); _udpSender = new StatsDPublisher(config, udpTransport); _udpSender.Increment("startup.ud"); _ipSender = new StatsDPublisher(config, ipTransport); _udpSender.Increment("startup.ip"); }
/// <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 = EndpointParser.MakeEndPointSource( configuration.Host, configuration.Port, configuration.DnsLookupInterval); var transport = new SocketTransport(endpointSource, configuration.SocketProtocol); _transport = transport; _disposeTransport = true; _inner = new BufferBasedStatsDPublisher(configuration, transport); }
public void Setup() { var config = new StatsDConfiguration { Host = "127.0.0.1", }; var endpointSource1 = EndpointParser.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval); var endpointSource2 = EndpointParser.MakeEndPointSource( config.Host, config.Port + 1, config.DnsLookupInterval); var switcher = new MillisecondSwitcher(endpointSource1, endpointSource2); _transport = new SocketTransport(endpointSource1, SocketProtocol.Udp); _transportSwitched = new SocketTransport(switcher, SocketProtocol.Udp); }
public void Setup() { var config = new StatsDConfiguration { // if you want to verify that stats are received, // you will need the IP of suitable local test stats server Host = "127.0.0.1", Prefix = "testmetric" }; var endpointSource = EndpointParser.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval); _transport = new SocketTransport(endpointSource, SocketProtocol.Udp); _adaptedStatsDPublisher = new StatsDPublisher(config); _adaptedStatsDPublisher.Increment("startup.ud"); _udpSender = new BufferBasedStatsDPublisher(config, _transport); _udpSender.Increment("startup.ud"); }