Commit 7e23fb052f26383c53c09370d6298d0c77510107
1 parent
572da06d
Pinger javítgatása
Showing
4 changed files
with
66 additions
and
19 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
... | ... | @@ -93,6 +93,40 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
93 | 93 | } |
94 | 94 | |
95 | 95 | /// <summary> |
96 | + /// Törli az aktuális sort (szóközökkel) a pillanatnyi pozíciótól a megadott szélességben | |
97 | + /// </summary> | |
98 | + /// <param name="width">ha 0, akkor a sor végéig</param> | |
99 | + public static void ClearLine(int width=0,char fillchar=' ') | |
100 | + { | |
101 | + int currentLineCursor = Console.CursorTop; | |
102 | + int currentColCursor = Console.CursorLeft; | |
103 | + if (width == 0) { width = Console.WindowWidth - currentColCursor; } | |
104 | + Console.SetCursorPosition(currentColCursor, Console.CursorTop); | |
105 | + Console.Write(new string(fillchar, width)); | |
106 | + Console.SetCursorPosition(currentColCursor, currentLineCursor); | |
107 | + } | |
108 | + | |
109 | + | |
110 | + /// <summary> | |
111 | + /// Törli (szóközökkel) a megadott szélességű és magasságú területet a megadott cursor pozíciótól véve | |
112 | + /// </summary> | |
113 | + /// <param name="height">ha 0, akkor az ablak aljáig</param> | |
114 | + /// <param name="width">ha 0, akkor a sorok végéig</param> | |
115 | + public static void ClearArea(int width=0, int height=0, char fillchar = ' ') | |
116 | + { | |
117 | + int currentLineCursor = Console.CursorTop; | |
118 | + int currentColCursor = Console.CursorLeft; | |
119 | + if (height == 0) { height = Console.WindowHeight; } | |
120 | + for (var i=0;i<height;i++) | |
121 | + { | |
122 | + ClearLine(width, fillchar); | |
123 | + Console.CursorTop++; | |
124 | + } | |
125 | + Console.SetCursorPosition(currentColCursor, currentLineCursor); | |
126 | + } | |
127 | + | |
128 | + | |
129 | + /// <summary> | |
96 | 130 | /// Beolvas egy sort a consolról, vagy commandmode-ban a bufferból |
97 | 131 | /// </summary> |
98 | 132 | /// <param name="text"></param> | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools - TcpIp.cs
... | ... | @@ -35,7 +35,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
35 | 35 | private Pinger(string hostNameOrAddress, PingerConfig pc) |
36 | 36 | { |
37 | 37 | this.HostNameOrAddress = hostNameOrAddress; |
38 | - this.History = new PingHistory(hostNameOrAddress, pc.pingerhistorylength, pc.pingcyclefrequency); | |
38 | + this.History = new PingHistory(hostNameOrAddress, pc); | |
39 | 39 | this.PingTimeout = pc.pingtimeout; |
40 | 40 | this.PingCycleFrequency = pc.pingcyclefrequency; |
41 | 41 | this.PingCycleNumberOfPackages = pc.pingcyclenumofpackages; |
... | ... | @@ -269,9 +269,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
269 | 269 | var _pingcyclenumofpackages = GetPositiveIntFromXml(PINGCYCLENUMOFPACKAGES, pingerconfig); |
270 | 270 | var _pingerlifetime = GetPositiveIntFromXml(PINGERACTIVELENGTHTOSTOPPERIOD, pingerconfig); |
271 | 271 | var _pingerhistorylength = GetPositiveIntFromXml(PINGERHISTORYLENGTH, pingerconfig); |
272 | + var _optimizehistorylength = pingerconfig.Element(OPTIMIZEHISTORYLENGTH)?.Value; ; | |
272 | 273 | var _roundtriptimelimits = pingerconfig.Element(ROUNDTRIPTIMELIMITS)?.Value; |
273 | 274 | var _roundtriptimecategorylimits = pingerconfig.Element(ROUNDTRIPTIMECATEGORYLIMITS)?.Value; |
274 | - SetValues(_pingtimeout, _pingcyclefrequency, _pingcyclenumofpackages, _pingerlifetime, _pingerhistorylength, _roundtriptimelimits, _roundtriptimecategorylimits); | |
275 | + SetValues(_pingtimeout, _pingcyclefrequency, _pingcyclenumofpackages, _pingerlifetime, _pingerhistorylength, _roundtriptimelimits, _roundtriptimecategorylimits,_optimizehistorylength); | |
275 | 276 | } |
276 | 277 | else { SetValues(); } |
277 | 278 | } |
... | ... | @@ -284,9 +285,9 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
284 | 285 | /// <param name="pingcyclenumofpackages">pcs</param> |
285 | 286 | /// <param name="pingeractivelength">minutes</param> |
286 | 287 | /// <param name="pingerhistorylength">minutes</param> |
287 | - public PingerConfig(int pingtimeout = 0, int pingcyclefrequency = 0, int pingcyclenumofpackages = 0, int pingeractivelength = 0, int pingerhistorylength = 0,string rttlimits=null, string rttcatlimits=null) | |
288 | + public PingerConfig(int pingtimeout = 0, int pingcyclefrequency = 0, int pingcyclenumofpackages = 0, int pingeractivelength = 0, int pingerhistorylength = 0,string rttlimits=null, string rttcatlimits=null,string optimizehlength=null) | |
288 | 289 | { |
289 | - SetValues(pingtimeout, pingcyclefrequency, pingcyclenumofpackages, pingeractivelength, pingerhistorylength, rttlimits , rttcatlimits); | |
290 | + SetValues(pingtimeout, pingcyclefrequency, pingcyclenumofpackages, pingeractivelength, pingerhistorylength, rttlimits , rttcatlimits, optimizehlength); | |
290 | 291 | } |
291 | 292 | |
292 | 293 | /// <summary> |
... | ... | @@ -297,11 +298,14 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
297 | 298 | /// <param name="pingcyclenumofpackages">pcs</param> |
298 | 299 | /// <param name="pingeractivelength">minutes</param> |
299 | 300 | /// <param name="pingerhistorylength">minutes</param> |
300 | - private void SetValues(int pingtimeout = 0, int pingcyclefrequency = 0, int pingcyclenumofpackages = 0, int pingeractivelength = 0, int pingerhistorylength = 0, string rttlimits = null, string rttcatlimits = null) | |
301 | + private void SetValues(int pingtimeout = 0, int pingcyclefrequency = 0, int pingcyclenumofpackages = 0, int pingeractivelength = 0, int pingerhistorylength = 0, string rttlimits = null, string rttcatlimits = null,string optimizehlength=null) | |
301 | 302 | { |
302 | 303 | this.pingcyclenumofpackages = pingcyclenumofpackages <= 0 ? PingerConfig.DEFAULT_PINGCYCLENUMOFPACKAGES : pingcyclenumofpackages; |
303 | 304 | this.pingeractivlength = (pingeractivelength <= 0 ? PingerConfig.DEFAULT_PINGERACTIVELENGTH : pingeractivelength) * 60 * 1000; |
304 | 305 | this.pingerhistorylength = (pingerhistorylength <= 0 ? PingerConfig.DEFAULT_PINGERHISTORYLENGTH : pingerhistorylength) * 60 * 1000; |
306 | + bool optimizehlengthbool=true; | |
307 | + if (optimizehlength != null) { optimizehlengthbool = bool.TryParse(optimizehlength.ToLower(), out optimizehlengthbool) ? optimizehlengthbool : true; } | |
308 | + this.optimizehistorylength = optimizehlengthbool; | |
305 | 309 | |
306 | 310 | try |
307 | 311 | { |
... | ... | @@ -354,12 +358,14 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
354 | 358 | public int pingcyclenumofpackages; |
355 | 359 | public int pingeractivlength; |
356 | 360 | public int pingerhistorylength; |
361 | + public bool optimizehistorylength; | |
357 | 362 | |
358 | 363 | const string PINGTIMEOUT = "PingTimeout"; |
359 | 364 | const string PINGCYCLEFREQUENCY = "PingCycleFrequency"; |
360 | 365 | const string PINGCYCLENUMOFPACKAGES = "PingCycleNumOfPackages"; |
361 | 366 | const string PINGERACTIVELENGTHTOSTOPPERIOD = "PingerActiveLength"; |
362 | 367 | const string PINGERHISTORYLENGTH = "PingerHistoryLength"; |
368 | + const string OPTIMIZEHISTORYLENGTH = "OptimizeHistoryLength"; | |
363 | 369 | const string ROUNDTRIPTIMELIMITS = "RoundTripTimeLimits"; |
364 | 370 | const string ROUNDTRIPTIMECATEGORYLIMITS = "RoundTripCategoryLimits"; |
365 | 371 | public const int DEFAULT_PINGTIMEOUT = 0; |
... | ... | @@ -397,19 +403,25 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
397 | 403 | /// </summary> |
398 | 404 | public int PingCycleFrequency; |
399 | 405 | |
406 | + /// <summary> | |
407 | + /// Az érvényes configuráció | |
408 | + /// </summary> | |
409 | + public PingerConfig PingerConfig; | |
410 | + | |
400 | 411 | public string HostNameOrAddress; |
401 | 412 | public PingerStatus PingerState = PingerStatus.Still; |
402 | 413 | public DateTime StartTime; |
403 | 414 | |
404 | 415 | private object historylocker = new object(); |
405 | 416 | |
406 | - public PingHistory(string hostnameoraddress, int pingerhistorylength,int pingcyclefrequency) | |
417 | + public PingHistory(string hostnameoraddress, PingerConfig pingerconfig) | |
407 | 418 | { |
408 | 419 | this.HostNameOrAddress = hostnameoraddress; |
409 | 420 | this.PingStateQueue = new List<PingCycle>(); |
410 | 421 | this.LastPingCycle = null; |
411 | - this.Length = pingerhistorylength; | |
412 | - this.PingCycleFrequency = pingcyclefrequency; | |
422 | + this.Length = pingerconfig.pingerhistorylength; | |
423 | + this.PingCycleFrequency = pingerconfig.pingcyclefrequency; | |
424 | + this.PingerConfig = pingerconfig; | |
413 | 425 | } |
414 | 426 | public PingHistory(PingHistory ph) |
415 | 427 | { |
... | ... | @@ -418,6 +430,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
418 | 430 | this.LastPingCycle = ph.LastPingCycle; |
419 | 431 | this.Length = ph.Length; |
420 | 432 | this.PingCycleFrequency = ph.PingCycleFrequency; |
433 | + this.PingerConfig = ph.PingerConfig; | |
421 | 434 | } |
422 | 435 | |
423 | 436 | public void Dispose() |
... | ... | @@ -433,7 +446,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
433 | 446 | { |
434 | 447 | lock (historylocker) |
435 | 448 | { |
436 | - if (this.LastPingCycle?.isDifferent(newpc) ?? true) { this.PingStateQueue.Add(newpc); this.LastPingCycle = newpc; } | |
449 | + if (!this.PingerConfig.optimizehistorylength || (this.LastPingCycle?.isDifferent(newpc) ?? true)) { this.PingStateQueue.Add(newpc); this.LastPingCycle = newpc; } | |
437 | 450 | else |
438 | 451 | { |
439 | 452 | var totalrtt = ((this.LastPingCycle.RoundtripTimeAverage * this.LastPingCycle.NumberOfCycles) + newpc.RoundtripTimeAverage); |
... | ... | @@ -590,7 +603,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
590 | 603 | /// <returns></returns> |
591 | 604 | public bool isDifferent(PingCycle pc) |
592 | 605 | { |
593 | - return this.StatusCategory != pc.StatusCategory || this.RoundtripTime != pc.RoundtripTime; | |
606 | + return this.StatusCategory != pc.StatusCategory | |
607 | + || this.RoundtripTime != pc.RoundtripTime; | |
594 | 608 | } |
595 | 609 | #endregion isDifferent |
596 | 610 | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs
... | ... | @@ -191,6 +191,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS |
191 | 191 | ColorConsole.WriteLine((pconfig.pingcyclefrequency / 1000).ToString(), ConsoleColor.Yellow, prefix: " cycle frequency:", suffix: "sec"); |
192 | 192 | ColorConsole.WriteLine((pconfig.pingeractivlength / 60000).ToString(), ConsoleColor.Yellow, prefix: " pinger liftime :", suffix: "min"); |
193 | 193 | ColorConsole.WriteLine((pconfig.pingerhistorylength / 60000).ToString(), ConsoleColor.Yellow, prefix: " history length :", suffix: "min"); |
194 | + ColorConsole.WriteLine((pconfig.optimizehistorylength).ToString(), ConsoleColor.Yellow, prefix: " optimize history length :", suffix: ""); | |
194 | 195 | var rttlstring = (string.Join(",", pconfig.RoundTripTimeLimits)).ToString(); |
195 | 196 | ColorConsole.WriteLine(rttlstring.Substring(0, rttlstring.Length>20?20: rttlstring.Length) + (rttlstring.Length > 20 ? "..." : ""), ConsoleColor.Yellow, prefix: " roundtrip time limit values :", suffix: "ms"); |
196 | 197 | ColorConsole.WriteLine((string.Join(",", pconfig.RoundTripTimeyCategoryLimits)).ToString(), ConsoleColor.Yellow, prefix: " roundtrip time category limit values:", suffix: "ms"); |
... | ... | @@ -198,13 +199,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS |
198 | 199 | private static void DisplayPingerHistory(List<Pinger> selectedpingers,int firstrow,int cc) |
199 | 200 | { |
200 | 201 | if (selectedpingers == null || !selectedpingers.Any()) { return; } |
201 | - var lastrow = ColorConsole.CursorTop; | |
202 | - ColorConsole.SetCursorPosition(cc,firstrow); | |
203 | - for (var i= 0; i< lastrow - firstrow;i++) { ColorConsole.WriteLine(new string(' ',100)); } | |
204 | 202 | ColorConsole.SetCursorPosition(cc, firstrow); |
205 | 203 | |
206 | - ColorConsole.WriteLine(); | |
207 | - ColorConsole.WriteLine($"Pinger History:", ConsoleColor.Yellow); | |
204 | + ColorConsole.ClearLine();ColorConsole.WriteLine(); | |
205 | + ColorConsole.ClearLine();ColorConsole.WriteLine($"Pinger History:", ConsoleColor.Yellow); | |
208 | 206 | var cursorleftposition = ColorConsole.CursorLeft; |
209 | 207 | var cursortopposition = ColorConsole.CursorTop; |
210 | 208 | while (true) |
... | ... | @@ -215,8 +213,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS |
215 | 213 | foreach (var pinger in selectedpingers) { pingcyclefrequency=DisplayOnePingerHistory(pinger); if (ColorConsole.KeyAvailable) { goto finishdisplayhistory; };} |
216 | 214 | var elapsed = DateTime.Now.Subtract(monitorcyclestart).TotalMilliseconds; |
217 | 215 | if (elapsed < pingcyclefrequency) { Thread.Sleep((int)((double)pingcyclefrequency - elapsed)); } |
218 | - ColorConsole.WriteLine(); | |
219 | - ColorConsole.WriteLine($"Press any key to exit from monitoring...", ConsoleColor.Yellow); | |
216 | + ColorConsole.ClearLine(); ColorConsole.WriteLine(); | |
217 | + ColorConsole.ClearLine(); ColorConsole.WriteLine($"Press any key to exit from monitoring...", ConsoleColor.Yellow); | |
220 | 218 | } |
221 | 219 | finishdisplayhistory:; |
222 | 220 | } |
... | ... | @@ -225,6 +223,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS |
225 | 223 | var _h = pinger.GetHistory(); |
226 | 224 | if (_h == null) { return 0; } |
227 | 225 | var h = new Pinger.PingHistory(_h);//klónozzuk, mert egyébként ha az adatgyűjtés miatt megváltozik akkor exception-re fut a foreach |
226 | + ColorConsole.ClearLine(); | |
228 | 227 | ColorConsole.Write(pinger.HostNameOrAddress, ConsoleColor.Yellow, suffix: ": ",prefix:" "); |
229 | 228 | var pingerstatus = pinger.Operating ? "pinging" : "still"; |
230 | 229 | var pingerstatuscolor = pinger.Operating ? ConsoleColor.Green : ConsoleColor.Yellow; | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
... | ... | @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; |
32 | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
33 | 33 | // by using the '*' as shown below: |
34 | 34 | // [assembly: AssemblyVersion("1.0.*")] |
35 | -[assembly: AssemblyVersion("1.8.2.0")] | |
36 | -[assembly: AssemblyFileVersion("1.8.2.0")] | |
35 | +[assembly: AssemblyVersion("1.8.3.0")] | |
36 | +[assembly: AssemblyFileVersion("1.8.3.0")] | ... | ... |