コード例 #1
0
 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>();
 }
コード例 #2
0
 public void Setup()
 {
     _udp             = Substitute.For <IStatsdClient>();
     _stopwatch       = Substitute.For <IStopWatchFactory>();
     _randomGenerator = Substitute.For <IRandomGenerator>();
     _randomGenerator.ShouldSend(0).ReturnsForAnyArgs(true);
 }
コード例 #3
0
 public Statsd(IStatsdClient statsdClient, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory, ReadOnlyMemory <char> prefix)
 {
     StopwatchFactory = stopwatchFactory;
     StatsdClient     = statsdClient;
     RandomGenerator  = randomGenerator;
     _prefix          = prefix;
 }
コード例 #4
0
 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>();
 }
コード例 #5
0
 public Statsd(IStatsdClient statsdClient, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory, string prefix)
 {
     Commands         = new List <string>();
     StopwatchFactory = stopwatchFactory;
     StatsdClient     = statsdClient;
     RandomGenerator  = randomGenerator;
     _prefix          = prefix;
 }
コード例 #6
0
        public static Task SendAsync(this IStatsdClient client, ReadOnlySpan <char> command)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

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

            client.SendAsync(command.ToString()).GetAwaiter().GetResult();
        }
コード例 #8
0
ファイル: ClientTest.cs プロジェクト: appfirst/statsd_clients
 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");
 }
コード例 #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");
 }
コード例 #10
0
ファイル: GlobalStatsd.cs プロジェクト: Codestellation/statsd
        /// <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();
        }
コード例 #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);
            }
        }
コード例 #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);
            }
        }
コード例 #13
0
 public Statsd(IStatsdClient statsdClient)
     : this(statsdClient, "")
 {
 }
コード例 #14
0
ファイル: ClientTest.cs プロジェクト: appfirst/statsd_clients
 public ThreadPoolStatsd(ManualResetEvent doneEvent, string bucketPrefix, IStatsdClient statsd)
 {
     this.doneEvent = doneEvent;
     this.bucketPrefix = bucketPrefix;
     this.statsd = statsd;
 }
コード例 #15
0
 /// <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);
 }
コード例 #16
0
ファイル: GlobalStatsd.cs プロジェクト: Codestellation/statsd
 /// <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);
 }
コード例 #17
0
 public Statsd(IStatsdClient statsdClient)
     : this(statsdClient, new RandomGenerator(), new StopWatchFactory(), ReadOnlyMemory <char> .Empty)
 {
 }
コード例 #18
0
 public Statsd(IStatsdClient statsdClient, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory)
     : this(statsdClient, randomGenerator, stopwatchFactory, ReadOnlyMemory <char> .Empty)
 {
 }
コード例 #19
0
 /// <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);
 }
コード例 #20
0
ファイル: Statsd.cs プロジェクト: vinla/statsd-csharp-client
 public Statsd(IStatsdClient statsdClient)
     : this(statsdClient, new RandomGenerator(), new StopWatchFactory(), string.Empty)
 {
 }
コード例 #21
0
 public ThreadPoolStatsd(ManualResetEvent doneEvent, string bucketPrefix, IStatsdClient statsd)
 {
     this.doneEvent    = doneEvent;
     this.bucketPrefix = bucketPrefix;
     this.statsd       = statsd;
 }
コード例 #22
0
 public Statsd(IStatsdClient statsdClient, string prefix)
     : this(statsdClient, new RandomGenerator(), new StopWatchFactory(), prefix)
 {
 }
コード例 #23
0
 public Statsd(IStatsdClient statsdClient, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory)
     : this(statsdClient, randomGenerator, stopwatchFactory, string.Empty)
 {
 }