/// <summary> /// functional style for timing an delegate with no return value, is not async /// </summary> /// <param name="statsClient">the stats statsClient</param> /// <param name="bucket">the stat name</param> /// <param name="action">the delegate to time</param> public static void Time(this IStatsClient statsClient, string bucket, Action <IDisposableTimer> action) { using (var timer = StartTimer(statsClient, bucket)) { action(timer); } }
/// <summary> /// functional style for timing an delegate with no return value, is async /// </summary> /// <param name="statsClient">the stats statsClient</param> /// <param name="bucket">the stat name</param> /// <param name="action">the delegate to time</param> public static async Task Time(this IStatsClient statsClient, string bucket, Func <IDisposableTimer, Task> action) { using (var timer = StartTimer(statsClient, bucket)) { await action(timer); } }
/// <summary> /// functional style for timing a function with a return value, is not async /// </summary> /// <param name="statsClient">the stats statsClient</param> /// <param name="bucket">the stat name</param> /// <param name="func">the function to time</param> public static T Time <T>(this IStatsClient statsClient, string bucket, Func <IDisposableTimer, T> func) { using (var timer = StartTimer(statsClient, bucket)) { return(func(timer)); } }
public static void Timer(this IStatsClient stats, string name, Action action) { var time = Stopwatch.StartNew(); action(); stats.Timer(name, time.Elapsed); }
/// <summary> /// functional style for timing a function with a return value, is async /// </summary> /// <param name="statsClient">the stats statsClient</param> /// <param name="bucket">the stat name</param> /// <param name="func">the function to time</param> public static async Task <T> Time <T>(this IStatsClient statsClient, string bucket, Func <IDisposableTimer, Task <T> > func) { using (var timer = StartTimer(statsClient, bucket)) { return(await func(timer)); } }
public void SetUp() { this.dataClientFactory = MockRepository.GenerateMock<IDataClientFactory>(); this.sqlClient = MockRepository.GenerateMock<ISqlClient>(); this.graphiteClientFactory = MockRepository.GenerateMock<IGraphiteClientFactory>(); statsClient = MockRepository.GenerateMock<IStatsClient>(); log = MockRepository.GenerateMock<ILog>(); }
public DisposableTimer(IStatsClient statsClient, string statName) { if (string.IsNullOrEmpty(statName)) { throw new ArgumentNullException(nameof(statName)); } _statsClient = statsClient ?? throw new ArgumentNullException(nameof(statsClient)); StatName = statName; _stopwatch = Stopwatch.StartNew(); }
public static void GaugeAbsoluteValue(this IStatsClient stats, string name, int value) { if (value < 0) { stats.Send( new Metric(name, MetricValue.Gauge(0)), new Metric(name, MetricValue.Delta(value))); } else { stats.Send(new Metric(name, MetricValue.Gauge((uint)value))); } }
protected override void Invoke() { Func <DateTime> GetToday = () => { IDateTimePT dt = AutofacContainer.Container.Resolve <IDateTimePT>(); var today = dt.Now; return(today); }; DateTime startDate, endDate; if (base.Cmdlet.StartDate.HasValue) { startDate = base.Cmdlet.StartDate.Value; if (base.Cmdlet.EndDate.HasValue) { endDate = base.Cmdlet.EndDate.Value; } else { endDate = GetToday(); } } else { endDate = GetToday(); if (base.Cmdlet.LastDays.HasValue) { startDate = endDate.SubtrackDays(base.Cmdlet.LastDays.Value); } else { startDate = endDate.SubtrackDays(DefaultDays); } } IStatsClient client = Autofac.AutofacContainer.Container.Resolve <IStatsClient>(); List <CalculationDay> stats = client.GetStats(startDate, endDate); Func <int, string> f = s => s.ToString().FillWithZeros(3); foreach (var stat in stats.OrderBy(x => x.Date)) { string result = $"[{stat.Date}] m-added: {f(stat.MailCountAdd)}, m-sent: {f(stat.MailCountSent)}, m-processed: {f(stat.MailCountProcessed)}, t-added {f(stat.TaskCountAdded)}, t-finished {f(stat.TaskCountFinished)}, t-removed {f(stat.TaskCountRemoved)}"; WriteOutput(result); } }
public void Dispose() { if (!_disposed) { _disposed = true; _stopwatch.Stop(); if (string.IsNullOrEmpty(StatName)) { throw new InvalidOperationException("StatName must be set"); } _statsClient.Timing(StatName, _stopwatch.ElapsedMilliseconds); _stopwatch = null; _statsClient = null; } }
public static IStatsClient Scope(this IStatsClient self, string prefix) => new ScopedStatsClient(self, new StatsPrefix(prefix));
public static void Send(this IStatsClient stats, string name, MetricValue value) => stats.Send(new Metric(name, value));
public static void Send(this IStatsClient stats, params Metric[] metrics) => stats.Send(metrics);
/// <summary> /// Start a timer for use in a "using" statement /// </summary> /// <param name="statsClient">the stats statsClient</param> /// <param name="bucket">the stat name</param> /// <returns>the disposable timer</returns> public static IDisposableTimer StartTimer(this IStatsClient statsClient, string bucket) { return(new DisposableTimer(statsClient, bucket)); }
public ScopedStatsClient(IStatsClient inner, string prefix) { this.inner = inner; this.prefix = prefix.EndsWith(".") ? prefix : prefix + '.'; }
public ScopedStatsClient(IStatsClient inner, StatsPrefix prefix) { this.inner = inner; this.prefix = prefix; }
public static void Counter(this IStatsClient stats, string name) => stats.Send(new Metric(name, CountOfOne));
public static void GaugeDelta(this IStatsClient stats, string name, int value) => stats.Send(new Metric(name, MetricValue.Delta(value)));
public static void Counter(this IStatsClient stats, string name, int count) => stats.Send(new Metric(name, MetricValue.Counter(count)));
public static void Timer(this IStatsClient stats, string name, TimeSpan value) => stats.Timer(name, (ulong)value.TotalMilliseconds);
public static void Timer(this IStatsClient stats, string name, ulong value) => stats.Send(new Metric(name, MetricValue.Time(value)));