ShouldSend() public method

public ShouldSend ( double sampleRate ) : bool
sampleRate double
return bool
コード例 #1
0
 public void Send <TCommandType, T>(string name, T value, double sampleRate = 1.0, string[] tags = null) where TCommandType : Metric
 {
     if (RandomGenerator.ShouldSend(sampleRate))
     {
         Send(Metric.GetCommand <TCommandType, T>(_prefix, name, value, sampleRate, tags));
     }
 }
コード例 #2
0
 public void Add <TCommandType>(string name, int value, double sampleRate) where TCommandType : IAllowsInteger, IAllowsSampleRate
 {
     if (RandomGenerator.ShouldSend(sampleRate))
     {
         Commands.Add(GetCommand(name, value.ToString(CultureInfo.InvariantCulture), _commandToUnit[typeof(TCommandType)], sampleRate));
     }
 }
コード例 #3
0
 public void Add(string name, int value, double sampleRate)
 {
     if (RandomGenerator.ShouldSend(sampleRate))
     {
         _commands.Add(GetCommand(name, value, _commandToUnit[typeof(Counting)], sampleRate));
     }
 }
コード例 #4
0
 public void Send <TCommandType>(string name, int value, double sampleRate) where TCommandType : ICommandType
 {
     if (RandomGenerator.ShouldSend(sampleRate))
     {
         Send(GetCommand(name, value, _commandToUnit[typeof(TCommandType)], sampleRate));
     }
 }
コード例 #5
0
 public Task SendAsync <TCommandType, T>(string name, T value, double sampleRate = 1.0, string[] tags = null) where TCommandType : Metric
 {
     if (RandomGenerator.ShouldSend(sampleRate))
     {
         return(SendAsync(Metric.GetCommand <TCommandType, T>(_prefix, name, value, sampleRate, _constantTags, tags)));
     }
     return(Task.FromResult((object)null));
 }
コード例 #6
0
 public void If_sample_rate_is_1_then_always_true()
 {
     RandomGenerator randomGenerator = new RandomGenerator();
     for (int i = 0; i < NumberOfTestsRan; i++)
     {
         Assert.True(randomGenerator.ShouldSend(1));
     }
 }
コード例 #7
0
 public void Send <TCommandType>(string name, int value, double sampleRate, IDictionary <String, String> dimensions = null) where TCommandType : IAllowsInteger, IAllowsSampleRate
 {
     if (RandomGenerator.ShouldSend(sampleRate))
     {
         Commands = new List <string> {
             GetCommand(name, value.ToString(CultureInfo.InvariantCulture), _commandToUnit[typeof(TCommandType)], sampleRate, dimensions)
         };
         Send();
     }
 }
コード例 #8
0
ファイル: Statsd.cs プロジェクト: vinla/statsd-csharp-client
        public void Send <TCommandType>(string name, int value, double sampleRate) where TCommandType : IAllowsInteger, IAllowsSampleRate
        {
            if (!RandomGenerator.ShouldSend(sampleRate))
            {
                return;
            }

            var command = GetCommand(name, value.ToString(CultureInfo.InvariantCulture), _commandToUnit[typeof(TCommandType)], sampleRate);

            SendSingle(command);
        }
コード例 #9
0
        public void If_sample_rate_is_0_5_then_have_half_true()
        {
            int numberOfTrues = 0;
            RandomGenerator randomGenerator = new RandomGenerator();
            for (int i = 0; i < NumberOfTestsRan; i++)
            {
                if (randomGenerator.ShouldSend(0.5))
                {
                    numberOfTrues++;
                }
            }

            Assert.That( Math.Round(numberOfTrues/(double)NumberOfTestsRan,1),Is.EqualTo(0.5));
        }
コード例 #10
0
        public void If_sample_rate_is_one_tenth_of_pct_then_have_one_tenth_of_pct()
        {
            int numberOfTrues = 0;
            RandomGenerator randomGenerator = new RandomGenerator();
            const int sampleRate = 1/1000;
            for (int i = 0; i < NumberOfTestsRan; i++)
            {
                if (randomGenerator.ShouldSend(sampleRate))
                {
                    numberOfTrues++;
                }
            }

            Assert.That(Math.Round(numberOfTrues / (double)NumberOfTestsRan, 1), Is.EqualTo(sampleRate));
        }
コード例 #11
0
        public void If_sample_rate_is_one_quarter_then_have_one_quarter_true()
        {
            var numberOfTrues = 0;
            var randomGenerator = new RandomGenerator();
            const int sampleRate = 1/4;

            for (var i = 0; i < NumberOfTestsToRun; i++)
            {
                if (randomGenerator.ShouldSend(sampleRate))
                {
                    numberOfTrues++;
                }
            }

            Assert.That(Math.Round(numberOfTrues / (double)NumberOfTestsToRun, 1), Is.EqualTo(sampleRate));
        }
コード例 #12
0
        public void Send(Action actionToTime, string statName, double sampleRate = 1)
        {
            var stopwatch = StopwatchFactory.Get();

            try
            {
                stopwatch.Start();
                actionToTime();
            }
            finally
            {
                stopwatch.Stop();
                if (RandomGenerator.ShouldSend(sampleRate))
                {
                    Send <Timing>(statName, stopwatch.ElapsedMilliseconds());
                }
            }
        }
コード例 #13
0
        public void Add(Action actionToTime, string statName, double sampleRate = 1, IDictionary <String, String> dimensions = null)
        {
            var stopwatch = StopwatchFactory.Get();

            try
            {
                stopwatch.Start();
                actionToTime();
            }
            finally
            {
                stopwatch.Stop();
                if (RandomGenerator.ShouldSend(sampleRate))
                {
                    Add <Timing>(statName, stopwatch.ElapsedMilliseconds(), dimensions);
                }
            }
        }
コード例 #14
0
ファイル: Statsd.cs プロジェクト: vinla/statsd-csharp-client
        private void HandleTiming(Action actionToTime, string statName, double sampleRate, Action <string, int> actionToStore)
        {
            var stopwatch = StopwatchFactory.Get();

            try
            {
                stopwatch.Start();
                actionToTime();
            }
            finally
            {
                stopwatch.Stop();
                if (RandomGenerator.ShouldSend(sampleRate))
                {
                    actionToStore(statName, stopwatch.ElapsedMilliseconds);
                }
            }
        }