public void StatsExceptionOnEventFires() { int errorCount = 0; var target = new StatsdPipe("TBD", x => Interlocked.Increment(ref errorCount)); Assert.AreEqual(false, target.Active); Assert.AreEqual(1, errorCount); }
static void TestUnderPressure() { Console.WriteLine("TestUnderPressure"); StatsdPipe statsd = new StatsdPipe(); statsd.Transport = new TransportMock(); statsd.Strategy = new BufferedStrategy(500); statsd.Increment(bucketPrefix + "pressure.multiple1"); try { statsd.Gauge(bucketPrefix + "pressure.multiple1", 1); } catch (BucketTypeMismatchException btme) { Console.WriteLine(btme.Message); } for (int i = 0; i < 1000000; i++) { DateTime start = DateTime.Now; statsd.Increment(bucketPrefix + "pressure.multiple1"); int elapsedTimeMillis = Convert.ToInt32((DateTime.Now - start).TotalMilliseconds); statsd.Timing(bucketPrefix + "pressure.incr_time", elapsedTimeMillis); if (i % 3 == 0) { statsd.Increment(bucketPrefix + "pressure.multiple3"); } } }
public void StatsdPipeConstructsFromDefaultTest() { var target = new StatsdPipe(); Assert.IsNotNull(target.Server); Assert.IsTrue(target.Server.Port == 8125); Assert.IsTrue(target.Server.Address.Host == "localhost"); Assert.IsTrue(target.ApplicationName == string.Concat("UnitTests", ".", Environment.MachineName)); }
public Logger(string statsdHost, string statsdPort, string errorLogDB, string logFile) { this.errorLogDB = errorLogDB; try { this.statsd = new StatsdPipe(statsdHost, int.Parse(statsdPort)); Log(String.Format("Building statsdpipe: {0}:{1}", statsdHost, statsdPort), LogLevel.Trace); } catch { Log("Invalid or empty config values for statsdHost and statsdPipe; not logging to StatsD this run", LogLevel.Warn); } }
static void TestBasic() { Console.WriteLine("SendingWithoutGeyserStrategy"); StatsdPipe statsd = new StatsdPipe(); while (true) { Thread.Sleep(1000); ShowExample(statsd); } }
static void SendingWithGeyserStrategy() { Console.WriteLine("SendingWithGeyserStrategy"); StatsdPipe statsd = new StatsdPipe(); statsd.Strategy = new BufferedStrategy(5000); while (true) { Thread.Sleep(1); statsd.Increment(bucketPrefix + "mailslot"); } }
public void GaugeTest() { StatsdPipe target = new StatsdPipe(); // TODO: Initialize to an appropriate value string key = string.Empty; // TODO: Initialize to an appropriate value int value = 0; // TODO: Initialize to an appropriate value bool expected = false; // TODO: Initialize to an appropriate value bool actual; actual = target.Gauge(key, value); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void DecrementTest() { StatsdPipe target = new StatsdPipe(); // TODO: Initialize to an appropriate value string[] keys = null; // TODO: Initialize to an appropriate value bool expected = false; // TODO: Initialize to an appropriate value bool actual; actual = target.Decrement(keys); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void UpdateCountTest2() { StatsdPipe target = new StatsdPipe(); // TODO: Initialize to an appropriate value int magnitude = 0; // TODO: Initialize to an appropriate value double sampleRate = 0F; // TODO: Initialize to an appropriate value string[] keys = null; // TODO: Initialize to an appropriate value bool expected = false; // TODO: Initialize to an appropriate value bool actual; actual = target.UpdateCount(magnitude, sampleRate, keys); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
static void ShowExample() { StatsdPipe statsd = new StatsdPipe(); statsd.Gauge(bucketPrefix + "gauge", 500); statsd.Gauge("Gauge(string message, string key, int value)", bucketPrefix + "gauge", 500); statsd.Timing(bucketPrefix + "timer", 500); statsd.Timing("Timer(string message, string key, int value)", bucketPrefix + "timer", 500); statsd.Increment(bucketPrefix + "counter"); statsd.Decrement(bucketPrefix + "counter"); statsd.UpdateCount(2, bucketPrefix + "counter"); statsd.UpdateCount(3, 0, bucketPrefix + "counter", bucketPrefix + "counter2"); statsd.UpdateCount(4, 2, bucketPrefix + "counter", bucketPrefix + "counter2"); statsd.UpdateCount("UpdateCount(string message, string key, int value)", 5, bucketPrefix + "counter", bucketPrefix + "counter2"); statsd.UpdateCount("UpdateCount(string message, string key, int value)", 6, 1, bucketPrefix + "counter"); }
static void TestMailSlotStreaming() { GeyserStrategy strategy = new GeyserStrategy(); strategy.Interval = 2000; StatsdPipe statsd = new StatsdPipe(); statsd.Strategy = strategy; for (int i = 0; i < 1000; i++) { Thread.Sleep(r.Next(5)); statsd.Increment(bucketPrefix + "mailslot"); } }
static void SendMany() { Console.WriteLine("SendMany"); DateTime start = DateTime.Now; StatsdPipe statsd = new StatsdPipe(); statsd.Strategy = new BufferedStrategy(5000); for (int i = 0; i < 100000000; i++) { //Thread.Sleep(1); statsd.Increment(bucketPrefix + "mailslot"); } int elapsedTimeMillis = Convert.ToInt32((DateTime.Now - start).TotalMilliseconds); Console.WriteLine("Test took: " + elapsedTimeMillis + " msec"); }
static void TestMultiThreading() { Console.WriteLine("TestMultiThreading"); ManualResetEvent[] doneEvents = new ManualResetEvent[10]; for (int i = 0; i < doneEvents.Length; i++) { StatsdPipe statsd = new StatsdPipe(); statsd.Transport = new TransportMock(); statsd.Strategy = new BufferedStrategy(500); doneEvents[i] = new ManualResetEvent(false); ThreadPoolStatsd tps = new ThreadPoolStatsd(doneEvents[i], bucketPrefix, statsd); ThreadPool.QueueUserWorkItem(tps.SendMessages, i); } WaitHandle.WaitAll(doneEvents); }
public void EnsureMachineNameInConnectionStringIsHandled() { var target = new StatsdPipe("http://localhost:1234?application=UnitTests"); Assert.IsTrue(target.UseMachineNameFolder); target = new StatsdPipe("http://localhost:1234?application=UnitTests&usemachinenamefolder=gibberish"); Assert.IsTrue(target.UseMachineNameFolder); target = new StatsdPipe("http://localhost:1234?application=UnitTests&usemachinenamefolder=false"); Assert.IsFalse(target.UseMachineNameFolder); target = new StatsdPipe("http://localhost:1234?application=UnitTests&usemachinenamefolder=true"); Assert.IsTrue(target.UseMachineNameFolder); target = new StatsdPipe("http://localhost:1234?application=UnitTests&UseMachineNameFolder=false"); Assert.IsFalse(target.UseMachineNameFolder); }
static void SendingWithoutGeyserStrategy() { Console.WriteLine("SendingWithoutGeyserStrategy"); StatsdPipe statsd = new StatsdPipe(); int i = 0; StringBuilder sb = new StringBuilder(); sb.Append("a"); for (i = 0; i < 10; i++) { sb.Append(sb.ToString()); } Console.WriteLine(sb.Length); statsd.UpdateCount(1, 'a'); statsd.Strategy = new BufferedStrategy(5000); while (true) { Thread.Sleep(1); statsd.Increment(bucketPrefix + "mailslot"); } }
public void ThreadPoolCallback(Object threadContext) { StatsdPipe statsd = new StatsdPipe(); statsd.Send = new TransportMock().Send; GeyserStrategy stra = new GeyserStrategy(); stra.Interval = 0.5; statsd.Strategy = stra; int threadIndex = (int)threadContext; for (int i = 0; i < 100; i++) { //Thread.Sleep(r.Next(5)); DateTime start = DateTime.Now; statsd.Increment(bucketPrefix + "threadpool.thread" + threadIndex); int elapsedTimeMillis = Convert.ToInt32((DateTime.Now - start).TotalMilliseconds); statsd.Timing(bucketPrefix + "threadpool.incr_time", elapsedTimeMillis); } doneEvent.Set(); }
static void TestUnderPressure() { StatsdPipe statsd = new StatsdPipe(); statsd.Send = new TransportMock().Send; GeyserStrategy stra = new GeyserStrategy(); stra.Interval = 0.5; statsd.Strategy = stra; for (int i = 0; i < 10000; i++) { DateTime start = DateTime.Now; statsd.Increment(bucketPrefix + "pressure.multiple1"); int elapsedTimeMillis = Convert.ToInt32((DateTime.Now - start).TotalMilliseconds); statsd.Timing(bucketPrefix + "pressure.incr_time", elapsedTimeMillis); if (i % 3 == 0) { statsd.Increment(bucketPrefix + "pressure.multiple3"); } } }
static void TestMultiThreading2() { Console.WriteLine("TestMultiThreading (CB)"); DateTime start = DateTime.Now; ManualResetEvent[] doneEvents = new ManualResetEvent[10]; StatsdPipe statsd = new StatsdPipe(); //statsd.Transport = new TransportMock(); statsd.Strategy = new BufferedStrategy(2000); for (int i = 0; i < doneEvents.Length; i++) { doneEvents[i] = new ManualResetEvent(false); ThreadPoolStatsd tps = new ThreadPoolStatsd(doneEvents[i], bucketPrefix, statsd); ThreadPool.QueueUserWorkItem(tps.SendMessages, i); } WaitHandle.WaitAll(doneEvents); int elapsedTimeMillis = Convert.ToInt32((DateTime.Now - start).TotalMilliseconds); Console.WriteLine("Test took: " + elapsedTimeMillis + " msec"); }
public void SendMessageStats(Glmps.Message.ITimelineMessage message, ITabSetupContext context = null) { if (message is StatsdNetMessage) { return; } var timer = InitializeTimer(message); var selfTimer = Stopwatch.StartNew(); string statKey = GenerateStatKey(message); StatsdPipe.Timing(statKey, (long)message.Duration.TotalMilliseconds); IncrementStoredCount(statKey, context); selfTimer.Stop(); timer.Duration = selfTimer.Elapsed; PublishTimingMessage(timer, message, context); IncrementStoredCount("StatsdNet.TimingSum", context, timer.Duration.TotalMilliseconds); StatsdPipe.Timing("GlimpseStatsdNetTiming", (long)timer.Duration.TotalMilliseconds); }
public void StatsPipeShouldReportNotActiveWhenNoConnectionExists() { var target = new StatsdPipe(null, null); Assert.IsTrue(target.Active == false); }
public void StatsPipeShouldAddEnvironmentIfExists() { var s1 = new StatsdPipe("http://localhost:1234?application=UnitTests&environment=qa"); var s2 = new StatsdPipe("http://localhost:1234?application=UnitTests"); Assert.IsTrue(s1.ApplicationName.Contains(".qa"), "Should have .qa in the application name."); Assert.IsFalse(s2.ApplicationName.Contains(".qa"), "Should not have .qa in the application name. Was " + s2.ApplicationName); Assert.IsTrue(s1.Active && s2.Active); }
public void StatsNotActiveOnBadUrl() { var target = new StatsdPipe("TBD"); Assert.IsTrue(target.Active == false); }
public void StatsdUnitTestRunRecordInStatsdServer() { var target = new StatsdPipe(); target.Increment("StatsPipeTest"); }
public void StatsPipeShouldSendEvenWhenServerIsFake() { var target = new StatsdPipe("http://localhost:1234?application=UnitTests"); target.Increment("fake"); }