public void LogUdpStatsBuffered() { var options = new StatsdOptions { BufferMetrics = true, HostOrIp = "localhost", Port = 8125, OnExceptionGenerated = Options_OnExceptionGenerated, OnLogEventGenerated = Options_OnLogEventGenerated }; var statsd = Statsd.New <Udp>(options); var whenToStop = DateTime.Now.AddMinutes(20); var random = new Random(); while (whenToStop > DateTime.Now) { var amount = random.Next(1, 6); for (int i = 0; i < amount; i++) { statsd.CountAsync("autotest.counteryo").Wait(); statsd.GaugeAsync("autotest.gaugeyo", random.Next(50, 400)).Wait(); statsd.SetAsync("autotest.setyo", random.Next(100, 1000)).Wait(); statsd.TimingAsync("autotest.timeryo", random.Next(100, 1000)).Wait(); } Thread.Sleep(75); } }
public void EscapeDots() { var options = new StatsdOptions() { Prefix = "awesome." }; Assert.Equal("awesome", options.Prefix); }
public StastdTests() { var opt = new StatsdOptions { OnExceptionGenerated = (exception) => { throw exception; } }; options = opt; }
public void ConfirmUdpSendBuffTime() { var client = new Udp(); var options = new StatsdOptions() { BufferMetrics = true, OnExceptionGenerated = (exception) => { throw exception; } }; using (var statsd = new Statsd(options, 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); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); // Bind appsettings to StatsdOptions class var statsDOptions = new StatsdOptions(); Configuration.Bind("StatsD", statsDOptions); services.AddSingleton(statsDOptions); // Set up StatsD service services.AddStatsD(provider => { var options = provider.GetRequiredService <StatsdOptions>(); return(new StatsDConfiguration() { Host = options.HostName, Port = options.Port, Prefix = options.Prefix // , // OnError = ex => LogError(ex) }); }); }