23 using System.Collections.Generic;
25 using System.Globalization;
32 namespace Ntp.Analyzer.Graph
39 config = configuration;
44 private readonly List<double> dropped =
new List<double>();
45 private readonly List<double> droppedAvg =
new List<double>();
47 private readonly List<double> ignored =
new List<double>();
48 private readonly List<double> ignoredAvg =
new List<double>();
49 private readonly List<double> notSent =
new List<double>();
50 private readonly List<double> notSentAvg =
new List<double>();
51 private readonly List<double> received =
new List<double>();
52 private readonly List<double> receivedAvg =
new List<double>();
53 private readonly List<double> receivedAvgTot =
new List<double>();
54 private readonly List<double> sent =
new List<double>();
55 private readonly List<double> sentAvg =
new List<double>();
56 private readonly List<DateTime> time =
new List<DateTime>();
58 protected override string YLabel
64 switch (config.PacketRate)
73 rate = config.PacketRate > 60
74 ?
"second/" + config.PacketRate/60
75 :
"minute/" + config.PacketRate;
79 return $
"Packets per {rate}";
85 if (config.Received.HasValue)
87 var receivedPlot = SetupPlot(
"Packets received" + FText(config.Received.Value), Color.Green, time,
92 if (config.ReceivedAvg.HasValue)
94 var receivedAvgPlot = SetupPlot(
95 "Packets received accumulated" + FText(config.ReceivedAvg.Value),
102 var receivedAvgTotPlot = SetupPlot(
103 "Packets received since reset" + FText(config.ReceivedAvg.Value),
111 if (config.Dropped.HasValue)
113 var droppedPlot = SetupPlot(
"Packets dropped" + FText(config.Dropped.Value), Color.Red, time, dropped);
117 if (config.Ignored.HasValue)
119 var ignoredPlot = SetupPlot(
"Packets ignored" + FText(config.Ignored.Value), Color.Blue, time, ignored);
123 if (config.Sent.HasValue)
125 var sentPlot = SetupPlot(
"Packets sent" + FText(config.Sent.Value), Color.Black, time, sent);
129 if (config.NotSent.HasValue)
131 var notSentPlot = SetupPlot(
"Packets not sent" + FText(config.NotSent.Value), Color.DarkRed, time,
141 dataMapper.
FilterTime = DateTime.UtcNow.Subtract(GraphTimeSpan);
143 var startTime = DateTime.MinValue;
145 var firstTime = DateTime.MinValue;
146 long firstReceived = 0;
147 long firstIgnored = 0;
148 long firstDropped = 0;
150 long firstNotSent = 0;
152 var lastTime = DateTime.MinValue;
153 long lastReceived = 0;
154 long lastIgnored = 0;
155 long lastDropped = 0;
157 long lastNotSent = 0;
159 bool firstRun =
true;
160 int disFactor = config.PacketRate;
161 int interval = config.PlotInterval*config.Timespan;
163 foreach (var reading
in dataMapper)
165 bool readNext =
false;
166 var readingTime = config.GraphTime == DateTimeKind.Local
167 ? reading.RoundedLocalTime
168 : reading.RoundedUtcTime;
172 double minutes = readingTime.Subtract(lastTime).TotalMinutes;
173 double totalMinutes = readingTime.Subtract(firstTime).TotalMinutes;
174 double minutesSinceReset = readingTime.Subtract(startTime).TotalMinutes;
176 if (minutes >= interval)
178 time.Add(readingTime);
180 received.Add((reading.ReceivedPackets - lastReceived)*config.Received/minutes/disFactor ?? 0.0);
181 ignored.Add((reading.IgnoredPackets - lastIgnored)*config.Ignored/minutes/disFactor ?? 0.0);
182 dropped.Add((reading.DroppedPackets - lastDropped)*config.Dropped/minutes/disFactor ?? 0.0);
183 sent.Add((reading.PacketsSent - lastSent)*config.Sent/minutes/disFactor ?? 0.0);
184 notSent.Add((reading.PacketsNotSent - lastNotSent)*config.NotSent/minutes/disFactor ?? 0.0);
185 receivedAvg.Add((reading.ReceivedPackets - firstReceived)*config.ReceivedAvg/totalMinutes/
189 if (config.ReceivedAvg.HasValue)
190 receivedAvgTot.Add(reading.ReceivedPackets*config.ReceivedAvg.Value/minutesSinceReset/
193 receivedAvgTot.Add(0.0);
195 if (config.IgnoredAvg.HasValue)
196 ignoredAvg.Add((reading.IgnoredPackets - firstIgnored)*config.IgnoredAvg.Value/totalMinutes/
201 if (config.DroppedAvg.HasValue)
202 droppedAvg.Add((reading.DroppedPackets - firstDropped)*config.DroppedAvg.Value/totalMinutes/
207 if (config.SentAvg.HasValue)
208 sentAvg.Add((reading.PacketsSent - firstSent)*config.SentAvg.Value/totalMinutes/disFactor);
212 if (config.NotSentAvg.HasValue)
213 notSentAvg.Add((reading.PacketsNotSent - firstNotSent)*config.NotSentAvg.Value/totalMinutes/
223 int hours = reading.TimeSinceReset/(60*60);
224 int mins = (reading.TimeSinceReset - hours*60*60)/60;
225 int seconds = reading.TimeSinceReset - hours*60*60 - mins*60;
226 var span =
new TimeSpan(hours, mins, seconds);
227 startTime = readingTime.Subtract(span);
229 firstTime = readingTime;
230 firstReceived = reading.ReceivedPackets;
231 firstIgnored = reading.IgnoredPackets;
232 firstDropped = reading.DroppedPackets;
233 firstSent = reading.PacketsSent;
234 firstNotSent = reading.PacketsNotSent;
237 if (firstRun || readNext)
239 lastTime = readingTime;
240 lastReceived = reading.ReceivedPackets;
241 lastIgnored = reading.IgnoredPackets;
242 lastDropped = reading.DroppedPackets;
243 lastSent = reading.PacketsSent;
244 lastNotSent = reading.PacketsNotSent;
255 Surface.YAxis1.NumberFormat =
"{0:####0}";
258 private static string FText(
double value)
260 return Math.Abs(value - 1.0) > 0.0
261 ?
" x " + value.ToString(
"0", CultureInfo.InvariantCulture)
DateTime FilterTime
Gets or sets the time to use when extracting data. Only readings with a timestamp later than FilterTi...
Host FilterHost
Gets or sets the host
override void PreRender()
readonly ITrafficGraphConfiguration config
Singleton facade class used to access memory persistent data.
TrafficGraph(ITrafficGraphConfiguration configuration, Host host)
static DataFace Instance
Gets the Singleton instance.
static string FText(double value)
HostIoReadingDatabaseMapper HostIoReadings
Gets the host IO reading mapper.