public AppStatsTimer(string name, IStatsd client) { _name = name; _stopWatch = new Stopwatch(); _client = client; _stopWatch.Start(); }
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); }
public void Shutdown() { lock (Padlock) { _statsD?.Dispose(); _statsD = null; } }
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; }
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 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); }
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())); }
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); } }
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); } }
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); } }
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); } }
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 }); } }
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(); } }
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"); }
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); } }
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; } }
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"); } }
public static Task SendAsync(this IStatsd statsd, Func <Task> actionToTime, string statName, double sampleRate = 1) => statsd.SendAsync(actionToTime, statName.AsMemory(), sampleRate);
public static void Send(this IStatsd statsd, Action actionToTime, string statName, double sampleRate = 1) => statsd.Send(actionToTime, statName.AsSpan(), sampleRate);
public static Task SendAsync <TCommandType>(this IStatsd statsd, string name, string value) where TCommandType : IAllowsString => statsd.SendAsync <TCommandType>(name.AsSpan(), value.AsSpan());
public StatsdInstrumenter(IStatsd statsdClient) : this(statsdClient, new SystemClock()) { }
public StatsdInstrumenter(IStatsd statsdClient, IClock clock) { _statsdClient = statsdClient; _clock = clock; }
internal TimingToken(IStatsd client, string name) { stopwatch = Stopwatch.StartNew(); this.client = client; this.name = name; }
public static Task SendAsync <TCommandType>(this IStatsd statsd, string name, int value) where TCommandType : IAllowsInteger => statsd.SendAsync <TCommandType>(name.AsSpan(), value);
internal StatsDHelper(IPrefixProvider prefixProvider, IStatsd statsdClient) { _prefixProvider = prefixProvider; _statsdClient = statsdClient; }
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)); }
public static void Send <TCommandType>(this IStatsd statsd, string name, double value) where TCommandType : IAllowsDouble => statsd.Send <TCommandType>(name.AsSpan(), value);
public AgentWriter(IApi api, IStatsd statsd) : this(api, statsd, automaticFlush : true) { }
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);
public AgentWriter(IApi api, IStatsd statsd) { _api = api; _statsd = statsd; _flushTask = Task.Run(FlushTracesTaskLoopAsync); }
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);