コード例 #1
0
ファイル: StastdTests.cs プロジェクト: sanjaiganesh/StatsN
        public void BadMetricValuePassed()
        {
            var statsd = Statsd.New <NullChannel>(a => { a.HostOrIp = "localhost"; a.OnExceptionGenerated = (b) => { throw b; }; });
            var output = statsd.BuildMetric("yodawg", "", "c", "myPrefix");

            Assert.True(string.IsNullOrEmpty(output));
        }
コード例 #2
0
ファイル: StastdTests.cs プロジェクト: sanjaiganesh/StatsN
        public void CorrectMetricTypesPassed()
        {
            var statsd = Statsd.New <NullChannel>(a => { a.HostOrIp = "localhost"; a.OnExceptionGenerated = (b) => { throw b; }; });
            var output = statsd.BuildMetric("awesomeMetric.yo", "1", "c", "myPrefix");

            Assert.Equal("myPrefix.awesomeMetric.yo:1|c", output);
        }
コード例 #3
0
ファイル: StastdTests.cs プロジェクト: sanjaiganesh/StatsN
        public void TestManyMetrics(string metric, string value, string type, string assertionValue, string prefix = "")
        {
            var statsd = Statsd.New <NullChannel>(options);
            var output = statsd.BuildMetric(metric, value, type, prefix);

            Assert.Equal(assertionValue, output);
        }
コード例 #4
0
ファイル: StastdTests.cs プロジェクト: sanjaiganesh/StatsN
        public void BuildMetricNoPrefixTest()
        {
            var statsd = Statsd.New <NullChannel>(options);
            var output = statsd.BuildMetric("awesomeMetric.yo", "1", "c");

            Assert.Equal("awesomeMetric.yo:1|c", output);
        }
コード例 #5
0
ファイル: UdpTests.cs プロジェクト: sanjaiganesh/StatsN
        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);
            }
        }
コード例 #6
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc();
     services.AddSingleton <IStatsd>(Statsd.New <Udp>(new StatsdOptions()
     {
         HostOrIp = "grafana_graphite", Port = 8125, Prefix = "dotnet.metrics.webapi"
     }));
 }
コード例 #7
0
        public void NoConnectionShouldNotCauseExceptions()
        {
            var statsd = Statsd.New <Tcp>(new StatsdOptions()
            {
                HostOrIp = "127.0.0.1",
                Port     = 8888
            });

            statsd.CountAsync("awesomemetric.yo");
            statsd.CountAsync("awesomemetric.yo");
            statsd.CountAsync("awesomemetric.yo");
            statsd.CountAsync("awesomemetric.yo");
        }
コード例 #8
0
ファイル: StastdTests.cs プロジェクト: sanjaiganesh/StatsN
        public void BuildMetricTiming()
        {
            var statsd    = Statsd.New <NullChannel>(a => { a.HostOrIp = "localhost"; a.OnExceptionGenerated = (b) => { throw b; }; });
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            for (int i = 0; i < 100000; i++)
            {
                statsd.BuildMetric("awesomeMetric.yo", "1", "c", "myPrefix");
            }
            stopwatch.Stop();
            //we should be able to compile metrics FAST
            Assert.InRange(stopwatch.ElapsedMilliseconds, 0, 3000);
        }