Esempio n. 1
0
        private void InitializePool([NotNull] DnsEndPoint graphiteEndPoint, GraphiteProtocol graphiteProtocol, [CanBeNull] string globalPathPrefix)
        {
            hostnameResolver = new HostnameResolverWithCache(TimeSpan.FromHours(1), new SimpleDnsResolver());
            switch (graphiteProtocol)
            {
            case GraphiteProtocol.Tcp:
                tcpPool = new Pool <GraphiteTcpClient>(x => new GraphiteTcpClient(hostnameResolver.Resolve(graphiteEndPoint.Host), graphiteEndPoint.Port, globalPathPrefix));
                break;

            case GraphiteProtocol.Udp:
                udpPool = new Pool <GraphiteUdpClient>(x => new GraphiteUdpClient(hostnameResolver.Resolve(graphiteEndPoint.Host), graphiteEndPoint.Port, globalPathPrefix));
                break;

            default:
                throw new ArgumentException($"Unknown graphite protocol: {graphiteProtocol}");
            }
        }
Esempio n. 2
0
        public void TestGraphiteConnection(string hostname, GraphiteProtocol graphiteProtocol)
        {
            var topology = new TestGraphiteClientSettings
            {
                Enabled          = true,
                StatsDEndPoint   = new DnsEndPoint(hostname, 8125),
                GraphiteEndPoint = new DnsEndPoint(hostname, 2003),
                GraphiteProtocol = graphiteProtocol
            };
            var sut       = new PooledGraphiteClient(topology);
            var stopwatch = Stopwatch.StartNew();

            sut.Send("Test", 10, DateTime.UtcNow);
            var attempt1 = stopwatch.ElapsedMilliseconds;

            stopwatch.Restart();
            sut.Send("Test", 10, DateTime.UtcNow);
            var attempt2 = stopwatch.ElapsedMilliseconds;

            Console.WriteLine($"Host: {hostname}\nt1: {attempt1}\nt2: {attempt2}");
        }