public void Setup()
 {
     _udp             = MockRepository.GenerateMock <IStatsdClient>();
     _randomGenerator = MockRepository.GenerateMock <IRandomGenerator>();
     _randomGenerator.Stub(x => x.ShouldSend(Arg <double> .Is.Anything)).Return(true);
     _stopwatch = MockRepository.GenerateMock <IStopWatchFactory>();
 }
 public void Setup()
 {
     _udp             = Substitute.For <IStatsdClient>();
     _stopwatch       = Substitute.For <IStopWatchFactory>();
     _randomGenerator = Substitute.For <IRandomGenerator>();
     _randomGenerator.ShouldSend(0).ReturnsForAnyArgs(true);
 }
Esempio n. 3
0
 public Statsd(IStatsdClient statsdClient, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory, ReadOnlyMemory <char> prefix)
 {
     StopwatchFactory = stopwatchFactory;
     StatsdClient     = statsdClient;
     RandomGenerator  = randomGenerator;
     _prefix          = prefix;
 }
 public void Setup()
 {
     _udp = MockRepository.GenerateMock<IStatsdClient>();
     _randomGenerator = MockRepository.GenerateMock<IRandomGenerator>();
     _randomGenerator.Stub(x => x.ShouldSend(Arg<double>.Is.Anything)).Return(true);
     _stopwatch = MockRepository.GenerateMock<IStopWatchFactory>();
 }
Esempio n. 5
0
 public Statsd(IStatsdClient statsdClient, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory, string prefix)
 {
     Commands         = new List <string>();
     StopwatchFactory = stopwatchFactory;
     StatsdClient     = statsdClient;
     RandomGenerator  = randomGenerator;
     _prefix          = prefix;
 }
        public static Task SendAsync(this IStatsdClient client, ReadOnlySpan <char> command)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            return(client.SendAsync(command.ToString()));
        }
        public static void Send(this IStatsdClient client, ReadOnlySpan <char> command)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            client.SendAsync(command.ToString()).GetAwaiter().GetResult();
        }
Esempio n. 8
0
 static void ShowExample(IStatsdClient statsd)
 {
     statsd.Gauge(bucketPrefix + "gauge", 500);
     statsd.Timing(bucketPrefix + "timer", 500);
     statsd.Increment(bucketPrefix + "counter");
     statsd.Decrement(bucketPrefix + "counter");
     statsd.UpdateCount(2, bucketPrefix + "counter");
     statsd.UpdateCount(4, 0, bucketPrefix + "counter", bucketPrefix + "counter2");
     statsd.UpdateCount(8, 2, bucketPrefix + "counter", bucketPrefix + "counter2");
 }
Esempio n. 9
0
 static void ShowExample(IStatsdClient statsd)
 {
     statsd.Gauge(bucketPrefix + "gauge", 500);
     statsd.Timing(bucketPrefix + "timer", 500);
     statsd.Increment(bucketPrefix + "counter");
     statsd.Decrement(bucketPrefix + "counter");
     statsd.UpdateCount(2, bucketPrefix + "counter");
     statsd.UpdateCount(4, 0, bucketPrefix + "counter", bucketPrefix + "counter2");
     statsd.UpdateCount(8, 2, bucketPrefix + "counter", bucketPrefix + "counter2");
 }
Esempio n. 10
0
        /// <summary>
        /// Disposes current instance of <see cref="Client"/> and replaces it with stub implementation
        /// </summary>
        public static void Dispose()
        {
#if NET40
            var client = _statsdClient;
            Thread.MemoryBarrier();
#else
            var client = Volatile.Read(ref _statsdClient);
#endif
            _statsdClient = new StubClient();
            (client as IDisposable)?.Dispose();
        }
Esempio n. 11
0
        private static void CreateStatsD(MetricsConfig config)
        {
            _statsdClient?.Dispose();

            _statsdClient = null;

            if (!string.IsNullOrEmpty(config.StatsdServerName))
            {
                _statsdClient = new StatsdUDPClient(config.Encoding, config.StatsdServerName, config.StatsdServerPort, config.StatsdMaxUDPPacketSize);
                _statsD       = new Statsd(_statsdClient);
            }
        }
Esempio n. 12
0
        private static void CreateStatsD(MetricsConfig config)
        {
            if (_statsdClient != null)
            {
                _statsdClient.Dispose();
            }

            _statsdClient = null;

            if (!string.IsNullOrEmpty(config.StatsdServerName))
            {
                if (config.UseTcpProtocol)
                {
                    _statsdClient = new StatsdTCPClient(config.StatsdServerName, config.StatsdServerPort);
                }
                else
                {
                    _statsdClient = new StatsdUDPClient(config.StatsdServerName, config.StatsdServerPort, config.StatsdMaxUDPPacketSize);
                }
                _statsD = new Statsd(_statsdClient);
            }
        }
Esempio n. 13
0
 public Statsd(IStatsdClient statsdClient)
     : this(statsdClient, "")
 {
 }
Esempio n. 14
0
 public ThreadPoolStatsd(ManualResetEvent doneEvent, string bucketPrefix, IStatsdClient statsd)
 {
     this.doneEvent = doneEvent;
     this.bucketPrefix = bucketPrefix;
     this.statsd = statsd;
 }
 /// <summary>
 /// Sends gauge metric into a <see cref="IStatsdClient"/>
 /// </summary>
 /// <param name="self">An instance of the <see cref="IStatsdClient"/></param>
 /// <param name="name">Name of a metric</param>
 /// <param name="value">Time interval in milliseconds</param>
 public static IStatsdClient LogTiming(this IStatsdClient self, string name, int value)
 {
     self.LogTiming(new Timing(name, value));
     return(self);
 }
Esempio n. 16
0
 /// <summary>
 /// Configures the property <see cref="Client"/> with appropriate implementation of <see cref="IStatsdClient"/>
 /// <remarks>Do not use synchronous <see cref="IStatsdClient"/> to avoid threading issues.</remarks>
 /// <remarks>Default values for parameters: prefix=null, background=true, ignore_exceptions=true</remarks>
 /// <code>
 /// // the following strings are equivalent
 /// var uri = "udp://host:port?prefix=my_prefix&amp;background&amp;ignore_exceptions"
 /// var uri = "udp://host:port?prefix=my_prefix&amp;background=true&amp;ignore_exceptions=true"
 /// </code>
 /// /// </summary>
 /// <param name="uri">Parameter of the statsd client </param>
 /// <param name="exceptionHandler">Action to perform on an unhandled exception. Most commoly it's used for logging</param>
 public static void Configure(Uri uri, Action <Exception> exceptionHandler = null)
 {
     _statsdClient = BuildStatsd.From(uri, exceptionHandler);
 }
Esempio n. 17
0
 public Statsd(IStatsdClient statsdClient)
     : this(statsdClient, new RandomGenerator(), new StopWatchFactory(), ReadOnlyMemory <char> .Empty)
 {
 }
Esempio n. 18
0
 public Statsd(IStatsdClient statsdClient, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory)
     : this(statsdClient, randomGenerator, stopwatchFactory, ReadOnlyMemory <char> .Empty)
 {
 }
 /// <summary>
 /// Sends gauge metric into a <see cref="IStatsdClient"/>
 /// </summary>
 /// <param name="self">An instance of the <see cref="IStatsdClient"/></param>
 /// <param name="name">Name of a metric</param>
 /// <param name="stopwatch">An instance of <see cref="LeanStopwatch"/> which will be used to determine time interval</param>
 public static IStatsdClient LogTiming(this IStatsdClient self, string name, LeanStopwatch stopwatch)
 {
     self.LogTiming(stopwatch.Elapsed(name));
     return(self);
 }
Esempio n. 20
0
 public Statsd(IStatsdClient statsdClient)
     : this(statsdClient, new RandomGenerator(), new StopWatchFactory(), string.Empty)
 {
 }
Esempio n. 21
0
 public ThreadPoolStatsd(ManualResetEvent doneEvent, string bucketPrefix, IStatsdClient statsd)
 {
     this.doneEvent    = doneEvent;
     this.bucketPrefix = bucketPrefix;
     this.statsd       = statsd;
 }
Esempio n. 22
0
 public Statsd(IStatsdClient statsdClient, string prefix)
     : this(statsdClient, new RandomGenerator(), new StopWatchFactory(), prefix)
 {
 }
Esempio n. 23
0
 public Statsd(IStatsdClient statsdClient, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory)
     : this(statsdClient, randomGenerator, stopwatchFactory, string.Empty)
 {
 }