public override bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result)
            {
                if (binder.Operation == ExpressionType.AddAssign)
                {
                    var quantity = (int)arg;
                    var name     = String.Join(".", _parts);
                    switch (_metricType)
                    {
                    case MetricType.COUNT:
                        _statsd.LogCount(name, quantity);
                        break;

                    case MetricType.GAUGE:
                        _statsd.LogGauge(name, quantity);
                        break;

                    case MetricType.TIMING:
                        _statsd.LogTiming(name, quantity);
                        break;

                    case MetricType.SET:
                        _statsd.LogSet(name, quantity);
                        break;
                    }
                    result = null;
                    return(true);
                }
                result = null;
                return(false);
            }
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;
            _stopWatch.Stop();
            _client.LogTiming(_name, _stopWatch.ElapsedMilliseconds);
        }
Exemple #3
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;
                }
            }
 /// <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);
 }
 public void Timer(string statName, int milliseconds)
 {
     _client.LogTiming(statName, milliseconds);
 }
Exemple #6
0
 public void LogTiming(string name, long milliseconds, Dictionary <string, string> tags = null)
 {
     RunSafe(() =>
             _statsd.LogTiming(BuildName(name, tags), milliseconds));
 }
 /// <summary>
 /// Stops the internal timer and logs a latency metric.
 /// </summary>
 public void Dispose()
 {
     _stopwatch.Stop();
     _client.LogTiming(_name, (int)_stopwatch.ElapsedMilliseconds);
 }
 public override void OnActionExecuted(ActionExecutedContext filterContext)
 {
     _stopwatch.Stop();
     _statsd.LogTiming(_name, (int)_stopwatch.ElapsedMilliseconds);
 }
 public void LogTiming(string name, long milliseconds)
 {
     _statsdClient.LogTiming(string.Format("{0}.{1}", GetStandardPrefix, name), milliseconds);
 }