Ejemplo n.º 1
0
        /// <summary>
        /// Analyzes all the PingReply objects and derives some statistics
        /// </summary>
        public void ComputeStatistics()
        {
            log.Debug("Starting to compute statistics for " + Host + " for " + ReplyQueue.Count + " replies");

            if (ReplyQueue.Count > 0)
            {
                MaxLatency = ReplyQueue.Peek().RoundtripTime;
                MinLatency = MaxLatency;
                long runningTotal = 0;
                int  errorCount   = 0;

                foreach (ICMPReply reply in ReplyQueue)
                {
                    if (reply.Status == IPStatus.Success)
                    {
                        if (reply.RoundtripTime < MinLatency)
                        {
                            MinLatency = reply.RoundtripTime;
                        }
                        if (reply.RoundtripTime > MaxLatency)
                        {
                            MaxLatency = reply.RoundtripTime;
                        }
                        runningTotal += reply.RoundtripTime;
                    }
                    else
                    {
                        errorCount++;
                    }
                }

                AverageLatency    = runningTotal / ReplyQueue.Count;
                Jitter            = MaxLatency - MinLatency;
                PacketLostPercent = Math.Round(errorCount / (float)ReplyQueue.Count * 100, 1);

                log.Debug("Min=" + MinLatency);
                log.Debug("Max=" + MaxLatency);
                log.Debug("Avg=" + AverageLatency);
                log.Debug("Jitter=" + Jitter);
                log.Debug("PacketLoss%=" + PacketLostPercent);
            }
            else
            {
                log.Warn("The PingReplyQueue is empty");
            }

            log.Debug("Completed calculating statistics");
        }