public Recorder( Statsd.StatsdPipe pipe, string productName, string applicationName) { this.c_pipe = pipe; this.c_keyPrefix = string.Format("{0}.{1}.", productName, applicationName); }
public void send_timer_with_lamba_still_records_on_error_and_still_bubbles_up_exception() { const string statName = "name"; var stopwatch = MockRepository.GenerateMock <IStopwatch>(); stopwatch.Stub(x => x.ElapsedMilliseconds()).Return(500); _stopwatch.Stub(x => x.Get()).Return(stopwatch); var s = new Statsd(new Statsd.Configuration() { Udp = _udp, RandomGenerator = _randomGenerator, StopwatchFactory = _stopwatch, Sender = _sender }); Assert.Throws <InvalidOperationException>(() => s.Send(() => { throw new InvalidOperationException(); }, statName)); IList <object[]> argsPerCall = _sender.GetArgumentsForCallsMadeOn(x => x.Send(Arg <Metric> .Is.Anything)); Assert.That(argsPerCall.Count, Is.EqualTo(1)); Assert.That(((Metric)argsPerCall[0][0]).Command, Is.EqualTo("name:500|ms")); }
public void set_return_value_with_send_timer_with_lambda() { const string statName = "name"; var stopwatch = MockRepository.GenerateMock <IStopwatch>(); stopwatch.Stub(x => x.ElapsedMilliseconds()).Return(500); _stopwatch.Stub(x => x.Get()).Return(stopwatch); var s = new Statsd(new Statsd.Configuration() { Udp = _udp, RandomGenerator = _randomGenerator, StopwatchFactory = _stopwatch, Sender = _sender }); var returnValue = 0; s.Send(() => returnValue = TestMethod(), statName); IList <object[]> argsPerCall = _sender.GetArgumentsForCallsMadeOn(x => x.Send(Arg <Metric> .Is.Anything)); Assert.That(argsPerCall.Count, Is.EqualTo(1)); Assert.That(((Metric)argsPerCall[0][0]).Command, Is.EqualTo("name:500|ms")); Assert.That(returnValue, Is.EqualTo(5)); }
public void send_timer_with_lambda_and_tags_passes() { const string statName = "name"; var stopwatch = MockRepository.GenerateMock <IStopwatch>(); stopwatch.Stub(x => x.ElapsedMilliseconds()).Return(500); _stopwatch.Stub(x => x.Get()).Return(stopwatch); _randomGenerator = MockRepository.GenerateMock <IRandomGenerator>(); _randomGenerator.Stub(x => x.ShouldSend(Arg <double> .Is.Anything)).Return(true); var s = new Statsd(new Statsd.Configuration() { Udp = _udp, RandomGenerator = _randomGenerator, StopwatchFactory = _stopwatch, Sender = _sender }); s.Send(() => TestMethod(), statName, 0.1, new { tag1 = 1, tag2 = "2" }); IList <object[]> argsPerCall = _sender.GetArgumentsForCallsMadeOn(x => x.Send(Arg <Metric> .Is.Anything)); Assert.That(argsPerCall.Count, Is.EqualTo(1)); Assert.That(((Metric)argsPerCall[0][0]).Command, Is.EqualTo("name,tag1=1,tag2=2:500|ms")); }
public void send_oversized_udp_packets_are_split_if_possible_with_multiple_messages_in_one_packet() { var msg = new String('f', MetricsConfig.DefaultStatsdMaxUDPPacketSize / 2); listenThread.Start(3); var sender = new BatchSender(); var statsd = new Statsd(new Statsd.Configuration() { Udp = udp, Sender = sender }); statsd.Send <Statsd.Counting>("counter", 1); statsd.Send <Statsd.Counting>(msg, 2); statsd.Send <Statsd.Counting>(msg, 3); sender.Flush(); // Make sure that a split packet can contain mulitple metrics AssertWasReceived(String.Format("counter:1|c\n{0}:2|c", msg), 0); AssertWasReceived(String.Format("{0}:3|c", msg), 1); AssertWasReceived(null, 2); }
public void send_oversized_udp_packets_are_split_if_possible() { var msg = new String('f', MetricsConfig.DefaultStatsdMaxUDPPacketSize - 15); listenThread.Start(3); // Listen for 3 messages var sender = new BatchSender(); var statsd = new Statsd(new Statsd.Configuration() { Udp = udp, Sender = sender }); statsd.Send <Statsd.Counting>(msg, 1); statsd.Send <Statsd.Timing>(msg, 2); sender.Flush(); // These two metrics should be split as their combined lengths exceed the maximum packet size AssertWasReceived(String.Format("{0}:1|c", msg), 0); AssertWasReceived(String.Format("{0}:2|ms", msg), 1); // No extra metric should be sent at the end AssertWasReceived(null, 2); }
public void set_max_udp_packet_size() { // Make sure that we can set the max UDP packet size udp = new StatsdUDP(serverName, serverPort, 10); var msg = new String('f', 5); listenThread.Start(2); var sender = new BatchSender(); var statsd = new Statsd(new Statsd.Configuration() { Udp = udp, Sender = sender }); statsd.Send <Statsd.Counting>(msg, 1); statsd.Send <Statsd.Timing>(msg, 2); sender.Flush(); // 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); }
public void single_send_is_thread_safe() { var counts = new CountingUDP(); var test = new Statsd(counts); // send some commands in parallel, `command' just being a number in sequence int sends = 1024, threads = 2; // appears sufficient to surface error most of the time but may vary by machine var sent = new ManualResetEvent[threads]; for (int i = 0; i < threads; i++) { var done = sent[i] = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(CreateSender(sends, threads, i, test, done)); } // allow threads to complete, cleanup WaitHandle.WaitAll(sent); foreach (IDisposable d in sent) { d.Dispose(); } counts.ExpectSequence(sends); }
public void ConfirmUdpSendNoBufferedTime() { var client = new Udp(); using (var statsd = new Statsd(new StatsdOptions() { BufferMetrics = false, OnExceptionGenerated = (exception) => { throw exception; } }, client)) { var stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < 100000; i++) { statsd.CountAsync("fun"); } while (client.worker.IsBusy) { } stopwatch.Stop(); //we shouldn't cost more than 1 milisecond a metric buffered or not Assert.InRange(stopwatch.ElapsedMilliseconds, 0, 100000); } }
public void can_concurrently_add_double_metrics() { var s = new Statsd(_udp, SampleEverything); Parallel.For(0, 1000000, x => Assert.DoesNotThrow(() => s.AddGauge("name", 5d))); }
public void add_service_check_with_pipe_in_name() { Statsd s = new Statsd(_udp, _randomGenerator, _stopwatch); Assert.Throws <ArgumentException>(() => s.Add("name|", 0)); }
public void Initialise() { _outputChannel = new Mock <IOutputChannel>(); _statsd = new Statsd("localhost", 12000, outputChannel: _outputChannel.Object); _testData = new TestData(); }
public void Before_each() { _stats = new Statsd(_udp, _randomGenerator, _stopwatch); }
public void CreateClient_WithInvalidCharactersInHostName_DoesNotError() { var statsd = new Statsd("@%)(F(FSDLKDEQ423t0-vbdfb", 12000); statsd.LogCount("test.foo"); }
public void CreateClient_WithIPAddress_DoesNotError() { var statsd = new Statsd("127.0.0.1", 12000); statsd.LogCount("test.stat"); }
public void CreateClient_WithInvalidHostName_DoesNotError() { var statsd = new Statsd("nowhere.here.or.anywhere", 12000); statsd.LogCount("test.stat"); }
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); } }
public void can_concurrently_add_double_metrics() { var s = new Statsd(_udp, _randomGenerator, _stopwatch); Parallel.For(0, 1000000, x => Assert.DoesNotThrow(() => s.Add <Statsd.Gauge>("name", 5d))); }