예제 #1
0
 public AppStatsTimer(string name, IStatsd client)
 {
     _name      = name;
     _stopWatch = new Stopwatch();
     _client    = client;
     _stopWatch.Start();
 }
예제 #2
0
        internal AgentWriter(IApi api, IStatsd statsd, bool automaticFlush)
        {
            _api    = api;
            _statsd = statsd;

            _flushTask = automaticFlush ? Task.Run(FlushTracesTaskLoopAsync) : Task.FromResult(true);
        }
 public void SetUp()
 {
     FlipperActor = MockActor("User:5");
     StatsdClient = MockRepository.GenerateStub<IStatsd>();
     Instrumenter = new StatsdInstrumenter(StatsdClient);
     Flipper = new Flipper(new MemoryAdapter(), Instrumenter);
 }
예제 #4
0
 public void Shutdown()
 {
     lock (Padlock)
     {
         _statsD?.Dispose();
         _statsD = null;
     }
 }
예제 #5
0
 internal VeStatsDClient(IStatsd statsd, string datacenter, Dictionary <string, string> customTags = null)
 {
     _statsd     = statsd;
     _systemTags = $"host={Environment.MachineName.ToLower()},datacenter={datacenter}";
     if (customTags != null)
     {
         _systemTags = $"{_systemTags},{string.Join(",", customTags.Select(x => x.Key + '=' + x.Value))}";
     }
 }
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     _stopwatch = Stopwatch.StartNew();
     if (!filterContext.Controller.TempData.ContainsKey("statsdclient"))
     {
         throw new ArgumentNullException("statsdclient", "Could not find the statsdclient reference in the controller's TempData.");
     }
     _statsd = filterContext.Controller.TempData["statsdclient"] as IStatsd;
 }
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
   _stopwatch = Stopwatch.StartNew();
   if (!filterContext.Controller.TempData.ContainsKey("statsdclient"))
   {
     throw new ArgumentNullException("statsdclient", "Could not find the statsdclient reference in the controller's TempData.");
   }
   _statsd = filterContext.Controller.TempData["statsdclient"] as IStatsd;
 }
 static WaitCallback CreateSender(int sends, int threads, int which, IStatsd statsd, ManualResetEvent done)
 {
     return x => {
         for (int i = 0; i < sends; i++)
             if (which == (i % threads))
                 statsd.Send(i.ToString());
         done.Set();
     };
 }
예제 #9
0
        public AppStatsClient(string serverName = "127.0.0.1", int port = 12000)
        {
            string prefix = "ex";

            if (Settings.Current.WebsiteMode != WebsiteMode.Production)
            {
                prefix += "." + Settings.Current.WebsiteMode.ToString().ToLower();
            }

            _client = new Statsd(serverName, port, prefix: prefix, connectionType: ConnectionType.Udp);
        }
예제 #10
0
        public PerfCounterService(Func<IEnumerable<CounterDefinition>> getDefinitions, string statsDHost, int statsDPort = 8125)
        {
            defaultTickTimeSpan = TimeSpan.FromSeconds(10);
            initialDelay = TimeSpan.FromSeconds(10);

            var statsPrefix = string.Format("monitor.{0}", Environment.MachineName);

            statsD = new Statsd(statsDHost, statsDPort, statsPrefix);

            counters = new Lazy<Dictionary<string, PerformanceCounter>>(() => CreateCounters(getDefinitions()));
        }
예제 #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
 static WaitCallback CreateSender(int sends, int threads, int which, IStatsd statsd, ManualResetEvent done)
 {
     return(x => {
         for (int i = 0; i < sends; i++)
         {
             if (which == (i % threads))
             {
                 statsd.Send(i.ToString());
             }
         }
         done.Set();
     });
 }
 public AgentWriter(IApi api, IStatsd statsd, bool synchronousSend)
 {
     _api             = api;
     _statsd          = statsd;
     _synchronousSend = synchronousSend;
     if (synchronousSend)
     {
         _flushTask = Task.FromResult(false); // NET45 doesn't have completed task.
     }
     else
     {
         _flushTask = Task.Run(FlushTracesTaskLoopAsync);
     }
 }
예제 #14
0
        private static void CreateStatsD(MetricsConfig config)
        {
            if (_statsdUdp != null)
            {
                _statsdUdp.Dispose();
            }

            _statsdUdp = null;

            if (!string.IsNullOrEmpty(config.StatsdServerName))
            {
                _statsdUdp = new StatsdUDP(config.StatsdServerName, config.StatsdServerPort, config.StatsdMaxUDPPacketSize);
                _statsD    = new Statsd(_statsdUdp);
            }
        }
예제 #15
0
        public void Configure(StatsdConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (string.IsNullOrEmpty(config.StatsdServerName))
            {
                throw new ArgumentNullException("config.StatsdServername");
            }

            _prefix = config.Prefix;
            _statsD = new Statsd(new StatsdUDP(config.StatsdServerName, config.StatsdPort, config.StatsdMaxUDPPacketSize));
        }
        public static void AppendWarning(this IStatsd statsd, string source, string message, string[] tags = null)
        {
            if (statsd != null)
            {
                string[] warningTags =
                {
                    $"source:{source}",
                    $"message:{message}"
                };

                string[] allTags = warningTags.Concat(tags ?? Enumerable.Empty <string>()).ToArray();

                statsd.Add <Statsd.Counting, int>(TracerMetricNames.Health.Warnings, value: 1, sampleRate: 1, allTags);
            }
        }
        public static void AppendException(this IStatsd statsd, Exception exception, string source, string message, string[] tags = null)
        {
            if (statsd != null)
            {
                string[] exceptionTags =
                {
                    $"source:{source}",
                    $"message:{message}",
                    $"exception-type:{exception.GetType().FullName}",
                    $"exception-message:{exception.Message}",
                };

                string[] allTags = exceptionTags.Concat(tags ?? Enumerable.Empty <string>()).ToArray();

                statsd.Add <Statsd.Counting, int>(TracerMetricNames.Health.Exceptions, value: 1, sampleRate: 1, allTags);
            }
        }
예제 #18
0
        private static void CreateStatsD(MetricsConfig config)
        {
            if (_statsdUdp != null)
            {
                _statsdUdp.Dispose();
            }

            _statsdUdp = null;

            if (!string.IsNullOrEmpty(config.StatsdServerName))
            {
                _statsdUdp = new StatsdUDP(config.StatsdServerName, config.StatsdServerPort, config.StatsdMaxUDPPacketSize);
                _statsD    = new Statsd(new Statsd.Configuration()
                {
                    Udp = _statsdUdp, Sender = config.Sender, Prefix = _prefix, GlobalTags = config.GlobalTags, TagScopes = _tagScopes
                });
            }
        }
예제 #19
0
            private static void DoubleHandler(IStatsd client, string metricType, string name, object arg)
            {
                var value = Convert.ToDouble(arg);

                switch (metricType)
                {
                case MetricType.COUNT:
                    throw new NotSupportedException();

                case MetricType.GAUGE:
                    client.LogGauge(name, value);
                    break;

                case MetricType.TIMING:
                    throw new NotSupportedException();

                case MetricType.SET:
                    throw new NotSupportedException();
                }
            }
예제 #20
0
        public Api(Uri baseEndpoint, DelegatingHandler delegatingHandler, IStatsd statsd)
        {
            _tracesEndpoint = new Uri(baseEndpoint, TracesPath);
            _statsd         = statsd;

            _client = delegatingHandler == null
                          ? new HttpClient()
                          : new HttpClient(delegatingHandler);

            _client.DefaultRequestHeaders.Add(AgentHttpHeaderNames.Language, ".NET");

            // report runtime details
            try
            {
                var frameworkDescription = FrameworkDescription.Create();

                if (frameworkDescription != null)
                {
                    _client.DefaultRequestHeaders.Add(AgentHttpHeaderNames.LanguageInterpreter, frameworkDescription.Name);
                    _client.DefaultRequestHeaders.Add(AgentHttpHeaderNames.LanguageVersion, frameworkDescription.ProductVersion);
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "Error getting framework description");
            }

            // report Tracer version
            _client.DefaultRequestHeaders.Add(AgentHttpHeaderNames.TracerVersion, TracerConstants.AssemblyVersion);

            // report container id (only Linux containers supported for now)
            var containerId = ContainerInfo.GetContainerId();

            if (containerId != null)
            {
                _client.DefaultRequestHeaders.Add(AgentHttpHeaderNames.ContainerId, containerId);
            }

            // don't add automatic instrumentation to requests from this HttpClient
            _client.DefaultRequestHeaders.Add(HttpHeaderNames.TracingEnabled, "false");
        }
예제 #21
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);
            }
        }
예제 #22
0
            private static void IntHandler(IStatsd client, string metricType, string name, object arg)
            {
                var value = Convert.ToInt32(arg);

                switch (metricType)
                {
                case MetricType.COUNT:
                    client.LogCount(name, value);
                    break;

                case MetricType.GAUGE:
                    client.LogGauge(name, value);
                    break;

                case MetricType.TIMING:
                    client.LogTiming(name, value);
                    break;

                case MetricType.SET:
                    client.LogSet(name, value);
                    break;
                }
            }
예제 #23
0
        public Api(Uri baseEndpoint, IApiRequestFactory apiRequestFactory, IStatsd statsd)
        {
            Log.Debug("Creating new Api");

            _tracesEndpoint    = new Uri(baseEndpoint, TracesPath);
            _statsd            = statsd;
            _containerId       = ContainerMetadata.GetContainerId();
            _apiRequestFactory = apiRequestFactory ?? new ApiWebRequestFactory();

            // report runtime details
            try
            {
                _frameworkDescription = FrameworkDescription.Create();

                if (_frameworkDescription != null)
                {
                    Log.Information(_frameworkDescription.ToString());
                }
            }
            catch (Exception e)
            {
                Log.SafeLogError(e, "Error getting framework description");
            }
        }
예제 #24
0
 public static Task SendAsync(this IStatsd statsd, Func <Task> actionToTime, string statName, double sampleRate = 1) =>
 statsd.SendAsync(actionToTime, statName.AsMemory(), sampleRate);
예제 #25
0
 public static void Send(this IStatsd statsd, Action actionToTime, string statName, double sampleRate = 1) =>
 statsd.Send(actionToTime, statName.AsSpan(), sampleRate);
예제 #26
0
 public static Task SendAsync <TCommandType>(this IStatsd statsd, string name, string value) where TCommandType : IAllowsString =>
 statsd.SendAsync <TCommandType>(name.AsSpan(), value.AsSpan());
예제 #27
0
 public StatsdInstrumenter(IStatsd statsdClient)
     : this(statsdClient, new SystemClock())
 {
 }
예제 #28
0
 public StatsdInstrumenter(IStatsd statsdClient, IClock clock)
 {
     _statsdClient = statsdClient;
     _clock = clock;
 }
예제 #29
0
파일: Statsd.cs 프로젝트: Elders/StatsD
 internal TimingToken(IStatsd client, string name)
 {
     stopwatch = Stopwatch.StartNew();
     this.client = client;
     this.name = name;
 }
예제 #30
0
 public static Task SendAsync <TCommandType>(this IStatsd statsd, string name, int value) where TCommandType : IAllowsInteger =>
 statsd.SendAsync <TCommandType>(name.AsSpan(), value);
예제 #31
0
 internal StatsDHelper(IPrefixProvider prefixProvider, IStatsd statsdClient)
 {
     _prefixProvider = prefixProvider;
     _statsdClient = statsdClient;
 }
예제 #32
0
 public StatsdPublisher(IStatsd statsdClient)
 {
     _statsdClient = statsdClient;
 }
 internal TimingToken(IStatsd client, string name)
 {
   _stopwatch = Stopwatch.StartNew();
   _client = client;
   _name = name;
 }
 public StatsBuilderInternal(IStatsd statsd, string metricType)
 {
   _statsd = statsd;
   _parts = new List<string>();
   _metricType = metricType;
 }
 /// <summary>
 /// Log a timing metric
 /// </summary>
 /// <param name="client">The statsd client instance.</param>
 /// <param name="name">The namespace of the timing metric.</param>
 /// <param name="duration">The duration to log (will be converted into milliseconds)</param>
 public static void LogTiming(this IStatsd client, string name, TimeSpan duration)
 {
     client.LogTiming(name, (int)duration.TotalMilliseconds);
 }
 /// <summary>
 /// Starts a timing metric that will be logged when the TimingToken is disposed.
 /// </summary>
 /// <param name="client">The statsd clien instance.</param>
 /// <param name="name">The namespace of the timing metric.</param>
 /// <returns>A timing token that has been initialised with a start datetime.</returns>
 /// <remarks>Wrap the code you want to measure in a using() {} block. The
 /// TimingToken instance will log the duration when it is disposed.</remarks>
 public static TimingToken LogTiming(this IStatsd client, string name)
 {
     return(new TimingToken(client, name));
 }
예제 #37
0
 public static void Send <TCommandType>(this IStatsd statsd, string name, double value) where TCommandType : IAllowsDouble =>
 statsd.Send <TCommandType>(name.AsSpan(), value);
예제 #38
0
 public AgentWriter(IApi api, IStatsd statsd)
     : this(api, statsd, automaticFlush : true)
 {
 }
예제 #39
0
 public static Task SendAsync <TCommandType>(this IStatsd statsd, string name, double value, bool isDeltaValue) where TCommandType : IAllowsDouble, IAllowsDelta =>
 statsd.SendAsync <TCommandType>(name.AsSpan(), value, isDeltaValue);
예제 #40
0
 public AgentWriter(IApi api, IStatsd statsd)
 {
     _api       = api;
     _statsd    = statsd;
     _flushTask = Task.Run(FlushTracesTaskLoopAsync);
 }
예제 #41
0
 public static Task SendAsync <TCommandType>(this IStatsd statsd, string name, int value, double sampleRate) where TCommandType : IAllowsInteger, IAllowsSampleRate =>
 statsd.SendAsync <TCommandType>(name.AsSpan(), value, sampleRate);