public async Task Async_set_max_udp_packet_size()
        {
            // Make sure that we can set the max UDP packet size
            _udp = new StatsdUDP(_serverName, _serverPort, 10);
            var oldStatsd = _statsd;

            try
            {
                _statsd = new Statsd(_udp);
                var msg = new string('f', 5);
                _listenThread.Start(2);
                _statsd.Add <Statsd.Counting, int>(msg, 1);
                _statsd.Add <Statsd.Gauge, int>(msg, 2);
                await _statsd.SendAsync();

                // Since our packet size limit is now 10, this (short) message should still be split
                AssertWasReceived(string.Format("{0}:1|c", msg), 0);
                AssertWasReceived(string.Format("{0}:2|g", msg), 1);
            }
            finally
            {
                // reset statsd, so we don't get stuck with max size of 10 for other tests
                _statsd = oldStatsd;
            }
        }
示例#2
0
        public void add_counter_sets_prefix_on_name()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch, "another.prefix.");

            s.Add <Statsd.Counting, int>("counter", 1, sampleRate: 0.1);
            s.Add <Statsd.Timing, int>("timer", 1);
            s.Send();

            Mock.Get(_udp).Verify(x => x.Send("another.prefix.counter:1|c|@0.1\nanother.prefix.timer:1|ms"));
        }
示例#3
0
        public void add_one_counter_and_one_gauge_sends_in_one_go()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Counting, int>("counter", 1, 0.1);
            s.Add <Statsd.Timing, int>("timer", 1);
            s.Send();

            Mock.Get(_udp).Verify(x => x.Send("counter:1|c|@0.1\ntimer:1|ms"));
        }
示例#4
0
        public void add_one_counter_and_one_gauge_sends_in_one_go()
        {
            Statsd s = new Statsd(udp, _randomGenerator, _stopwatch);

            s.Add("counter", 1, 0.1);
            s.Add <Statsd.Timing>("timer", 1);
            s.Send();

            udp.AssertWasCalled(x => x.Send("counter:1|c|@0.1\ntimer:1|ms"));
        }
示例#5
0
        public void add_one_counter_and_one_gauge_sends_and_removes_commands()
        {
            Statsd s = new Statsd(udp, _randomGenerator, _stopwatch);

            s.Add("counter", 1, 0.1);
            s.Add <Statsd.Timing>("timer", 1);
            s.Send();

            Assert.That(s.Commands.Count, Is.EqualTo(0));
        }
示例#6
0
            public void add_counter_sets_prefix_on_name()
            {
                var s = new Statsd(_udp, _randomGenerator, _stopwatch, "another.prefix.");

                s.Add <Statsd.Counting>("counter", 1, 0.1);
                s.Add <Statsd.Timing>("timer", 1);
                s.Send();

                _udp.Received().Send("another.prefix.counter:1|c|@0.1\nanother.prefix.timer:1|ms");
            }
示例#7
0
            public void add_one_counter_and_one_timer_sends_in_one_go()
            {
                var s = new Statsd(_udp, _randomGenerator, _stopwatch);

                s.Add <Statsd.Counting>("counter", 1, 0.1);
                s.Add <Statsd.Timing>("timer", 1);
                s.Send();

                _udp.Received().Send("counter:1|c|@0.1\ntimer:1|ms");
            }
示例#8
0
        public void add_counter_sets_prefix_on_name()
        {
            Statsd s = new Statsd(udp, _randomGenerator, _stopwatch, "another.prefix.");

            s.Add("counter", 1, 0.1);
            s.Add <Statsd.Timing>("timer", 1);
            s.Send();

            udp.AssertWasCalled(x => x.Send("another.prefix.counter:1|c|@0.1\nanother.prefix.timer:1|ms"));
        }
示例#9
0
        public void add_one_counter_and_one_gauge_with_no_sample_rate_shows_in_commands()
        {
            Statsd s = new Statsd(udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Counting>("counter", 1);
            s.Add <Statsd.Timing>("timer", 1);

            Assert.That(s.Commands.Count, Is.EqualTo(2));
            Assert.That(s.Commands[0], Is.EqualTo("counter:1|c"));
            Assert.That(s.Commands[1], Is.EqualTo("timer:1|ms"));
        }
示例#10
0
        public void add_one_counter_and_one_gauge_using_long_values_with_no_sample_rate_shows_in_commands()
        {
            Statsd s = new Statsd(udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Counting>("counter", 784353464464323);
            s.Add <Statsd.Timing>("timer", 653244346423);

            Assert.That(s.Commands.Count, Is.EqualTo(2));
            Assert.That(s.Commands[0], Is.EqualTo("counter:784353464464323|c"));
            Assert.That(s.Commands[1], Is.EqualTo("timer:653244346423|ms"));
        }
示例#11
0
        public void Add_one_counter_and_one_gauge_shows_in_commands()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Counting, int>("counter", 1, 0.1);
            s.Add <Statsd.Timing, int>("timer", 1);

            Assert.That(s.Commands.Count, Is.EqualTo(2));
            Assert.That(s.Commands[0], Is.EqualTo("counter:1|c|@0.1"));
            Assert.That(s.Commands[1], Is.EqualTo("timer:1|ms"));
        }
 private static void AddObservationStats <T>(string experimentName, IObservation <T> observation, Statsd statsd)
 {
     experimentName = ReplaceWhitespace(experimentName);
     statsd.Add <Statsd.Timing>(string.Format("{0}.{1}.Results.Microseconds", experimentName, observation.Name),
                                (int)(observation.ElapsedTime.TotalMilliseconds * 1000)); // use microseconds because required to sent int
     if (observation.IsMismatched)
     {
         // Gauge, Meter, or Count -- use Count for now, gives us # of mismatches / second
         statsd.Add <Statsd.Counting>(string.Format("{0}.{1}.Results.Mismatches", experimentName,
                                                    observation.Name), 1);
     }
 }
示例#13
0
 public void set_max_udp_packet_size()
 {
     // Make sure that we can set the max UDP packet size
     udp = new StatsdUDP(serverName, serverPort, 10);
     statsd = new Statsd(udp);
     var msg = new String('f', 5);
     listenThread.Start(2);
     statsd.Add<Statsd.Counting>(msg, 1);
     statsd.Add<Statsd.Timing>(msg, 2);
     statsd.Send();
     // Since our packet size limit is now 10, this (short) message should still be split
     AssertWasReceived(String.Format("{0}:1|c", msg), 0);
     AssertWasReceived(String.Format("{0}:2|ms", msg), 1);
 }
示例#14
0
        public void SendSplitMetrics()
        {
            using (var statdUds = new StatsdUnixDomainSocket(StatsdUnixDomainSocket.UnixDomainSocketPrefix + _temporaryPath.Path, 25))
            {
                using (var socket = CreateSocketServer(_temporaryPath))
                {
                    var statd        = new Statsd(statdUds);
                    var messageCount = 7;

                    for (int i = 0; i < messageCount; ++i)
                    {
                        statd.Add("title" + i, "text");
                    }
                    Assert.AreEqual(messageCount, statd.Commands.Count);

                    statd.Send();

                    var response = ReadFromServer(socket);
                    for (int i = 0; i < messageCount; ++i)
                    {
                        Assert.True(response.Contains("title" + i));
                    }
                }
            }
        }
            public void time_add()
            {
                var statsd = new Statsd(new StatsdUDPClient(_localhostAddress, _randomUnusedLocalPort));

                statsd.Add(() => Thread.Sleep(MultiSecondSleepDelay), "time");
                statsd.Send();
                Assert.That(LastPacketMessageReceived(), Does.Match(_expectedMultiSecondTimeRegEx));
            }
示例#16
0
        public void add_one_counter_and_send_one_gauge_sends_only_sends_the_last()
        {
            Statsd s = new Statsd(udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Counting>("counter", 1);
            s.Send <Statsd.Timing>("timer", 1);

            udp.AssertWasCalled(x => x.Send("timer:1|ms"));
        }
示例#17
0
        public void add_histogram_double()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Histogram, double>("histogram", 5.3);

            Assert.That(s.Commands.Count, Is.EqualTo(1));
            Assert.That(s.Commands[0], Is.EqualTo("histogram:5.3|h"));
        }
示例#18
0
        public void add_gauge_with_sample_rate()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Gauge, int>("gauge", 5, sampleRate: 0.5);

            Assert.That(s.Commands.Count, Is.EqualTo(1));
            Assert.That(s.Commands[0], Is.EqualTo("gauge:5|g|@0.5"));
        }
示例#19
0
        public void add_gauge_double()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Gauge, double>("gauge", 5.3);

            Assert.That(s.Commands.Count, Is.EqualTo(1));
            Assert.That(s.Commands[0], Is.EqualTo("gauge:5.3|g"));
        }
示例#20
0
        public void add_one_counter_and_send_one_gauge_sends_only_sends_the_last_two_doubles()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Counting, double>("counter", 1.1);
            s.Send <Statsd.Timing, double>("timer", 1.1);

            Mock.Get(_udp).Verify(x => x.Send("timer:1.1|ms"));
        }
示例#21
0
        public void add_gauge_with_sample_rate_and_tags_double()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Gauge, int>("gauge", 5, sampleRate: 0.5, tags: new[] { "tag1:true", "tag2" });

            Assert.That(s.Commands.Count, Is.EqualTo(1));
            Assert.That(s.Commands[0], Is.EqualTo("gauge:5|g|@0.5|#tag1:true,tag2"));
        }
示例#22
0
        public void add_set_with_sample_rate()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Set, int>("set", 5, sampleRate: 0.5);

            Assert.That(s.Commands.Count, Is.EqualTo(1));
            Assert.That(s.Commands[0], Is.EqualTo("set:5|s|@0.5"));
        }
示例#23
0
        public void add_set_string_with_sample_rate_and_tags()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Set, string>("set", "string", sampleRate: 0.5, tags: new[] { "tag1:true", "tag2" });

            Assert.That(s.Commands.Count, Is.EqualTo(1));
            Assert.That(s.Commands[0], Is.EqualTo("set:string|s|@0.5|#tag1:true,tag2"));
        }
示例#24
0
        public void add_set_string()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Set, string>("set", "string");

            Assert.That(s.Commands.Count, Is.EqualTo(1));
            Assert.That(s.Commands[0], Is.EqualTo("set:string|s"));
        }
示例#25
0
        public void add_set_with_tags()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Set, int>("set", 5, tags: new[] { "tag1:true", "tag2" });

            Assert.That(s.Commands.Count, Is.EqualTo(1));
            Assert.That(s.Commands[0], Is.EqualTo("set:5|s|#tag1:true,tag2"));
        }
示例#26
0
        public void add_increase_counter_by_x_with_tags()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Counting, int>("counter", 5, tags: new[] { "tag1:true", "tag2" });

            Assert.That(s.Commands.Count, Is.EqualTo(1));
            Assert.That(s.Commands[0], Is.EqualTo("counter:5|c|#tag1:true,tag2"));
        }
示例#27
0
        public void add_set()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Set, int>("set", 5);

            Assert.That(s.Commands.Count, Is.EqualTo(1));
            Assert.That(s.Commands[0], Is.EqualTo("set:5|s"));
        }
示例#28
0
        public void add_histogram_with_sample_rate_and_tags()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Histogram, int>("histogram", 5, sampleRate: 0.5, tags: new[] { "tag1:true", "tag2" });

            Assert.That(s.Commands.Count, Is.EqualTo(1));
            Assert.That(s.Commands[0], Is.EqualTo("histogram:5|h|@0.5|#tag1:true,tag2"));
        }
示例#29
0
        public void add_histogram_with_sample_rate()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Histogram, int>("histogram", 5, 0.5);

            Assert.That(s.Commands.Count, Is.EqualTo(1));
            Assert.That(s.Commands[0], Is.EqualTo("histogram:5|h|@0.5"));
        }
示例#30
0
        public void add_increase_counter_by_x()
        {
            Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch);

            s.Add <Statsd.Counting, int>("counter", 5);

            Assert.That(s.Commands.Count, Is.EqualTo(1));
            Assert.That(s.Commands[0], Is.EqualTo("counter:5|c"));
        }