static void Main(string[] args) { var options = new Options(); if (CommandLine.Parser.Default.ParseArgumentsStrict(args, options)) { var client = new Statsd(options.Host, options.Port, prefix: options.Namespace, connectionType: options.UseTCP ? ConnectionType.Tcp : ConnectionType.Udp); var tokenSource = new System.Threading.CancellationTokenSource(); var stopwatch = Stopwatch.StartNew(); var totalMetricsSent = 0; var letters = new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; var tasks = new List <Task>(); int numThreads = options.Threads == 0 ? 1 : options.Threads; for (int count = 0; count < numThreads; count++) { int myTaskNumber = count; var task = Task.Factory.StartNew(() => { var rnd = new Random(); int taskNumber = myTaskNumber; if (taskNumber == 0) { Console.WriteLine("Feeding stats to {0}:{1}, ctrl+c to exit.", options.Host, options.Port); } while (true) { client.LogCount("test.count.one." + rnd.Next(5)); client.LogCount("test.count.bigValue", rnd.Next(50)); client.LogTiming("test.timing." + rnd.Next(5), rnd.Next(100, 2000)); client.LogGauge("test.gauge." + rnd.Next(5), rnd.Next(100)); client.LogCalendargram("test.calendargram.users", letters.Next(), "m"); Thread.Sleep(options.Delay); Interlocked.Add(ref totalMetricsSent, 4); if (taskNumber == 0 && stopwatch.ElapsedMilliseconds >= 5000) { Console.WriteLine("Total sent: {0}", totalMetricsSent); stopwatch.Restart(); } } }, tokenSource.Token); tasks.Add(task); } Console.CancelKeyPress += (sender, e) => { tokenSource.Cancel(); }; Task.WaitAll(tasks.ToArray()); } }
public void CreateClient_WithInvalidCharactersInHostName_DoesNotError() { Initialise(); var statsd = new Statsd("@%)(F(FSDLKDEQ423t0-vbdfb", 12000); statsd.LogCount("test.foo"); }
public void CreateClient_WithIPAddress_DoesNotError() { Initialise(); var statsd = new Statsd("127.0.0.1", 12000); statsd.LogCount("test.stat"); }
/* * Usage: statsd -c foo.bar.baz.zom */ static void Main(string[] args) { var options = new Options(); if (Parser.Default.ParseArgumentsStrict(args, options)) { var client = new Statsd(options.Host, options.Port, rethrowOnError: true); if ((options.Count || options.Gauge || options.Timing) && String.IsNullOrEmpty(options.RawData)) { Console.WriteLine("Cannot send raw data and specify a metric type in the same command. See statsdcmd --help."); } if (!String.IsNullOrEmpty(options.RawData)) { UDPClient.SendRaw(options.Host, options.Port, options.RawData); return; } if (options.Count) { client.LogCount(options.Name, options.Value); } else if (options.Timing) { client.LogTiming(options.Name, options.Value); } else if (options.Gauge) { client.LogGauge(options.Name, options.Value); } else { Console.WriteLine("No metric type specified."); } } }
public void LogCount_EmptyStringPrefix_DoesNotStartNameWithPeriod() { var statsd = new Statsd("localhost", 12000, prefix: "", outputChannel: _outputChannel.Object); var inputStat = "some.stat:1|c"; _outputChannel.Setup(p => p.SendAsync(It.Is <string>(q => q == inputStat))).Returns(Task.FromResult(false)).Verifiable(); statsd.LogCount("some.stat"); _outputChannel.VerifyAll(); }
public void LogCount_NullPrefix_DoesNotStartNameWithPeriod() { var statsd = new Statsd("localhost", 12000, prefix: null, outputChannel: _outputChannel.Object); var inputStat = "some.stat:1|c"; _outputChannel.Setup(p => p.Send(It.Is <string>(q => q == inputStat))) .Verifiable(); statsd.LogCount("some.stat"); _outputChannel.VerifyAll(); }
public void Constructor_PrefixEndsInPeriod_RemovePeriod() { var statsd = new Statsd("localhost", 12000, "foo.", outputChannel: _outputChannel.Object); var stat = _testData.NextStatName; var count = _testData.NextInteger; _outputChannel.Setup(p => p.SendAsync("foo." + stat + ":" + count.ToString() + "|c")).Returns(Task.FromResult(false)).Verifiable(); statsd.LogCount(stat, count); _outputChannel.VerifyAll(); }
public void LogCount_ValidInput_Success() { Initialise(); var stat = _testData.NextStatName; var count = _testData.NextInteger; _outputChannel.Setup(p => p.SendAsync(stat + ":" + count.ToString() + "|c")).Verifiable(); _statsd.LogCount(stat, count); _outputChannel.VerifyAll(); }
public void LogCount_NameIsNull_ExpectArgumentNullException() { _statsd.LogCount(null); }
public void CreateClient_WithInvalidHostName_DoesNotError() { var statsd = new Statsd("nowhere.here.or.anywhere", 12000); statsd.LogCount("test.stat"); }
private void ReportFatal() { _statsd.LogCount(MetricNameLogEventsFatal); }