public MetricsPipeInstance(MetricsPipe profiler)
        {
            if (profiler == null)
            {
                throw new ArgumentNullException("profiler");
            }

            this.profiler = profiler;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Stops the current MetricsPipe instance.
        /// </summary>
        /// <returns></returns>
        public MetricsPipe Stop()
        {
            MetricsPipe current = Current;

            if (current != null)
            {
                current.Stop();
            }

            return(current);
        }
        /// <summary>
        /// Starts a new MetricsPipe instance.
        /// </summary>
        /// <returns></returns>
        public MetricsPipe Start()
        {
            var context = OperationContext.Current;

            if (context == null)
                return null;

            var result = new MetricsPipe(GraphiteConfiguration.Instance, this, StopwatchWrapper.StartNew);
            Current = result;

            return result;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Removes the registered instance of the <see cref="MetricsPipeInstance"/> class from the current operation context after the operation has returned but before the reply message is sent.
        /// </summary>
        /// <param name="reply">The reply message. This value is null if the operation is one way.</param>
        /// <param name="correlationState">The correlation object returned from the AfterReceiveRequest method.</param>
        public void BeforeSendReply(ref Message reply, object correlationState)
        {
            MetricsPipe profiler = WcfMetricsPipeProvider.Instance.Stop();

            try
            {
                if (profiler != null)
                {
                    if (this.reportRequestTime != null && this.reportRequestTime.Enable)
                    {
                        if (!string.IsNullOrEmpty(this.reportRequestTime.FixedKey))
                        {
                            profiler.ReportTiming(
                                this.reportRequestTime.FixedKey.ToLowerInvariant(),
                                profiler.ElapsedMilliseconds);
                        }
                        else if (OperationContext.Current != null && OperationContext.Current.IncomingMessageHeaders != null)
                        {
                            profiler.ReportTiming(
                                this.ParseMetricKey(OperationContext.Current.IncomingMessageHeaders, this.reportRequestTime.KeyPrefix).ToLowerInvariant(),
                                profiler.ElapsedMilliseconds);
                        }
                    }

                    if (this.reportHitCount != null && this.reportHitCount.Enable)
                    {
                        if (!string.IsNullOrEmpty(this.reportHitCount.FixedKey))
                        {
                            profiler.ReportCounter(
                                this.reportHitCount.FixedKey.ToLowerInvariant(),
                                1);
                        }
                        else if (OperationContext.Current != null && OperationContext.Current.IncomingMessageHeaders != null)
                        {
                            profiler.ReportCounter(
                                this.ParseMetricKey(OperationContext.Current.IncomingMessageHeaders, this.reportHitCount.KeyPrefix).ToLowerInvariant(),
                                1);
                        }
                    }
                }
            }
            catch (SystemException exception)
            {
                Trace.TraceError(exception.Format());
            }

            if (profiler != null)
            {
                profiler.Dispose();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Starts a new MetricsPipe instance.
        /// </summary>
        /// <returns></returns>
        public MetricsPipe Start()
        {
            var context = OperationContext.Current;

            if (context == null)
            {
                return(null);
            }

            var result = new MetricsPipe(GraphiteConfigurationProvider.Get(), this, StopwatchWrapper.StartNew);

            Current = result;

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Starts a new MetricsPipe instance.
        /// </summary>
        /// <returns></returns>
        public MetricsPipe Start()
        {
            var context = HttpContext.Current;

            if (context == null)
            {
                return(null);
            }

            var result = new MetricsPipe(GraphiteConfiguration.Instance, this, StopwatchWrapper.StartNew);

            Current = result;

            return(result);
        }