/// <summary> /// Starts a new MetricsPipe instance. /// </summary> /// <returns></returns> public MetricsPipe Start() { var result = new MetricsPipe(GraphiteConfigurationProvider.Get(), this, StopwatchWrapper.StartNew); Current = result; return result; }
/// <summary> /// Times a step with specified key. /// </summary> /// <param name="profiler">The profiler.</param> /// <param name="key">The key.</param> /// <param name="reporter">Action to report result.</param> /// <returns></returns> public static IDisposable Step(this MetricsPipe profiler, string key, Action <MetricsPipe, string, long> reporter) { if (profiler == null) { return(null); } if (reporter == null) { throw new ArgumentNullException("reporter"); } var timing = profiler.StartTiming(); return(new Reporter(() => { timing.Dispose(); int?elapsed = timing.ComputeElapsedMilliseconds(); if (elapsed.HasValue) { reporter(profiler, key, elapsed.Value); } })); }
/// <summary> /// Starts a new MetricsPipe instance. /// </summary> /// <returns></returns> public MetricsPipe Start() { var result = new MetricsPipe(GraphiteConfigurationProvider.Get(), this, StopwatchWrapper.StartNew); Current = result; return(result); }
/// <summary> /// Reports a raw value directly to graphite. /// </summary> /// <param name="profiler">The profiler.</param> /// <param name="key">The metric key.</param> /// <param name="value">The value.</param> public static void Raw(this MetricsPipe profiler, string key, long value) { if (profiler == null) { return; } profiler.ReportRaw(key, value); }
/// <summary> /// Increases a counter for specified key. /// </summary> /// <param name="profiler">The profiler.</param> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <param name="sampling">Sample by provided value.</param> public static void Count(this MetricsPipe profiler, string key, long value = 1, float sampling = 1) { if (profiler == null) { return; } profiler.ReportCounter(key, value, sampling); }
/// <summary> /// Times a step with specified key. /// </summary> /// <param name="profiler">The profiler.</param> /// <param name="key">The key.</param> /// <returns></returns> public static IDisposable Step(this MetricsPipe profiler, string key) { if (profiler == null) { return(null); } return(Step(profiler, key, Timing)); }
/// <summary> /// Stops the current MetricsPipe instance. /// </summary> /// <returns></returns> public MetricsPipe Stop() { MetricsPipe current = Current; if (current != null) { current.Stop(); current.Dispose(); } return(current); }
/// <summary> /// Starts a new MetricsPipe instance. /// </summary> /// <param name="configurationContainer">Configuration container for graphite and statsd parameters.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException" /> public MetricsPipe Start(IConfigurationContainer configurationContainer) { if (configurationContainer == null) { throw new ArgumentNullException("configurationContainer"); } var result = new MetricsPipe(configurationContainer, this, StopwatchWrapper.StartNew); Current = result; return(result); }
/// <summary> /// Times a step with specified key. /// </summary> /// <param name="profiler">The profiler.</param> /// <param name="key">The key.</param> /// <returns></returns> public static IDisposable Step(this MetricsPipe profiler, string key) { if (profiler == null) { return(null); } var timing = profiler.StartTiming(); return(new Reporter(() => { timing.Dispose(); int?elapsed = timing.ComputeElapsedMilliseconds(); if (elapsed.HasValue) { profiler.ReportTiming(key, elapsed.Value); } })); }