From 30b9980a51bf408b1515ca822df57c13859f9867 Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Mon, 8 Apr 2019 13:06:06 +0200 Subject: [PATCH] WIP --- SkyEntities.cs | 1 + checks/CheckJob.cs | 2 ++ checks/Hostalive.cs | 4 +-- checks/SkyCheckState.cs | 39 ++++++++++++++++++++-- checks/SkyChecker.cs | 19 +++++++++-- checks/Ubiquity.cs | 12 +++---- ln.skyscanner.csproj | 3 ++ templates/static/checks/issues.html | 51 +++++++++++++++++++++++++++++ templates/static/topnav.html | 2 +- 9 files changed, 118 insertions(+), 15 deletions(-) create mode 100644 templates/static/checks/issues.html diff --git a/SkyEntities.cs b/SkyEntities.cs index 7a89996..0eeddc8 100644 --- a/SkyEntities.cs +++ b/SkyEntities.cs @@ -41,6 +41,7 @@ namespace ln.skyscanner nodeCollection = odDatabase.GetCollection(); subnetCollection = odDatabase.GetCollection(); + nodeCollection.EnableStrongCache(true); nodeCollection.EnsureIndex("PrimaryIP"); nodeCollection.EnsureIndex("Interfaces[].ConfiguredIPs[].IP"); nodeCollection.EnsureIndex("Interfaces[].ConfiguredIPs[].Network"); diff --git a/checks/CheckJob.cs b/checks/CheckJob.cs index 5adfac5..4ddffbf 100644 --- a/checks/CheckJob.cs +++ b/checks/CheckJob.cs @@ -33,6 +33,8 @@ namespace ln.skyscanner.checks SkyCheckState[] skyCheckStates = SkyScanner.Instance.Checker.checkStates.Query(stateQuery).ToArray(); foreach (SkyCheckState checkState in skyCheckStates) { + //if (checkState.Node == null) + //checkState.Node = node; checkStates.Add(checkState.CheckName, checkState); } } diff --git a/checks/Hostalive.cs b/checks/Hostalive.cs index 08add17..4d222f0 100644 --- a/checks/Hostalive.cs +++ b/checks/Hostalive.cs @@ -54,11 +54,11 @@ namespace ln.skyscanner.checks float fSuccess = (float)success / (float)n; - skyChecker.WritePerfValue(this,"replies",node,fSuccess); + skyChecker.WritePerfValue(this,checkState,"replies",node,fSuccess); if (success > 0) { roundTripTime /= success; - skyChecker.WritePerfValue(this, "rta", node, roundTripTime); + skyChecker.WritePerfValue(this, checkState, "rta", node, roundTripTime); } SetState(checkState, fSuccess); } diff --git a/checks/SkyCheckState.cs b/checks/SkyCheckState.cs index 07feade..269a73e 100644 --- a/checks/SkyCheckState.cs +++ b/checks/SkyCheckState.cs @@ -14,11 +14,24 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System.Linq; using ln.types.odb.attributes; +using System.Collections.Generic; namespace ln.skyscanner.checks { [JsonConverter(typeof(StringEnumConverter))] public enum CheckState { OK, WARN, CRITICAL, FAIL, ERROR } + public struct CheckStateChange + { + public CheckState NewState; + public DateTime Timestamp; + + public CheckStateChange(CheckState checkState) + { + NewState = checkState; + Timestamp = DateTime.Now; + } + } + public class SkyCheckState { [DocumentID] @@ -27,8 +40,8 @@ namespace ln.skyscanner.checks public readonly String CheckName; public readonly String UniqueNodeIdentifier; - [ByReference] - public Node Node; + public String[] PerformanceValues => performanceValues.ToArray(); + List performanceValues = new List(); public DateTime LastCheckTime { get; set; } @@ -37,7 +50,11 @@ namespace ln.skyscanner.checks public double CritLower { get; set; } = Double.MinValue; public double CritUpper { get; set; } = Double.MaxValue; - public CheckState CheckState { get; set; } + public CheckState CheckState { get => currentCheckState; set { if (currentCheckState != value) history.Add(new CheckStateChange(value)); currentCheckState = value; } } + CheckState currentCheckState; + + public CheckStateChange[] History => history.ToArray(); + List history = new List(); protected SkyCheckState() { @@ -47,5 +64,21 @@ namespace ln.skyscanner.checks CheckName = skyCheck.Name; UniqueNodeIdentifier = node.UniqueIdentity; } + + public void EnsurePerformanceValue(String perfName) + { + if (performanceValues == null) + performanceValues = new List(); + + if (!performanceValues.Contains(perfName)) + performanceValues.Add(perfName); + } + + + public class PerformanceValue + { + + } + } } diff --git a/checks/SkyChecker.cs b/checks/SkyChecker.cs index 6609866..e5026b6 100644 --- a/checks/SkyChecker.cs +++ b/checks/SkyChecker.cs @@ -39,6 +39,17 @@ namespace ln.skyscanner.checks public string[] PerfNames => perfFiles.Keys.ToArray(); public bool ContainsPerfFile(String perfName) => perfFiles.ContainsKey(perfName); + [Callable] + public SkyCheckState[] Issues => checkStates.Query( + //Query.Contains("CheckState",new CheckState[] { CheckState.CRITICAL, CheckState.WARN, CheckState.ERROR }) + Query.OR( + Query.Equals("currentCheckState", CheckState.CRITICAL), + Query.Equals("currentCheckState", CheckState.FAIL), + Query.Equals("currentCheckState", CheckState.WARN) + ) + ).ToArray(); + + public SNMPEngine SNMPEngine { get; } BTree perfFiles = new BTree(); @@ -62,6 +73,7 @@ namespace ln.skyscanner.checks odb = new ODB(Path.Combine(BasePath)); checkStates = odb.GetCollection(); + checkStates.EnableStrongCache(true); checkStates.EnsureIndex("CheckName"); checkStates.EnsureIndex("UniqueNodeIdentifier"); } @@ -100,9 +112,9 @@ namespace ln.skyscanner.checks perfFiles.Clear(); } - public void WritePerfValue(SkyCheck skyCheck,String vName,Node node,double value) + public void WritePerfValue(SkyCheck skyCheck,SkyCheckState checkState,String vName,Node node,double value) { - PerfFile perfFile = GetPerfFile(skyCheck, vName, node); + PerfFile perfFile = GetPerfFile(skyCheck, checkState, vName, node); lock (perfFile) { perfFile.EnsureOpen(); @@ -116,7 +128,7 @@ namespace ln.skyscanner.checks return perfFiles[perfName]; } - private PerfFile GetPerfFile(SkyCheck skyCheck, String vName, Node node) + private PerfFile GetPerfFile(SkyCheck skyCheck,SkyCheckState checkState,String vName, Node node) { String checkPath = String.Format("{0}_{1}", node.UniqueIdentity, skyCheck.Name); String perfName = String.Format("{0}_{1}",checkPath,vName); @@ -125,6 +137,7 @@ namespace ln.skyscanner.checks { SkyScanner.Instance.Entities.nodeCollection.Upsert(node); } + checkState.EnsurePerformanceValue(perfName); lock (this) { diff --git a/checks/Ubiquity.cs b/checks/Ubiquity.cs index c994f6a..92460c1 100644 --- a/checks/Ubiquity.cs +++ b/checks/Ubiquity.cs @@ -39,10 +39,10 @@ namespace ln.skyscanner.checks foreach (Sequence[] row in ptp) { - skyChecker.WritePerfValue(this, "ptp_rx_capa", node, (double)((Integer)(row[0].Items[1])).LongValue); - skyChecker.WritePerfValue(this, "ptp_tx_capa", node, (double)((Integer)(row[1].Items[1])).LongValue); - skyChecker.WritePerfValue(this, "ptp_rx_pwr", node, (double)((Integer)(row[2].Items[1])).LongValue); - skyChecker.WritePerfValue(this, "ptp_tx_pwr", node, (double)((Integer)(row[3].Items[1])).LongValue); + skyChecker.WritePerfValue(this, checkState, "ptp_rx_capa", node, (double)((Integer)(row[0].Items[1])).LongValue); + skyChecker.WritePerfValue(this, checkState, "ptp_tx_capa", node, (double)((Integer)(row[1].Items[1])).LongValue); + skyChecker.WritePerfValue(this, checkState, "ptp_rx_pwr", node, (double)((Integer)(row[2].Items[1])).LongValue); + skyChecker.WritePerfValue(this, checkState, "ptp_tx_pwr", node, (double)((Integer)(row[3].Items[1])).LongValue); long rxBytes = ((Integer)(row[4].Items[1])).LongValue; long txBytes = ((Integer)(row[5].Items[1])).LongValue; @@ -50,8 +50,8 @@ namespace ln.skyscanner.checks ubiquityCheckState.RXRate.Update(rxBytes * 8); ubiquityCheckState.TXRate.Update(txBytes * 8); - skyChecker.WritePerfValue(this, "ptp_rx_rate", node, ubiquityCheckState.RXRate.Current); - skyChecker.WritePerfValue(this, "ptp_tx_rate", node, ubiquityCheckState.TXRate.Current); + skyChecker.WritePerfValue(this, checkState, "ptp_rx_rate", node, ubiquityCheckState.RXRate.Current); + skyChecker.WritePerfValue(this, checkState, "ptp_tx_rate", node, ubiquityCheckState.TXRate.Current); } } diff --git a/ln.skyscanner.csproj b/ln.skyscanner.csproj index a154b07..b37d9c7 100644 --- a/ln.skyscanner.csproj +++ b/ln.skyscanner.csproj @@ -196,6 +196,9 @@ PreserveNewest + + PreserveNewest + diff --git a/templates/static/checks/issues.html b/templates/static/checks/issues.html new file mode 100644 index 0000000..a8abf6a --- /dev/null +++ b/templates/static/checks/issues.html @@ -0,0 +1,51 @@ +<%frame "frame.html"%> + +

Aktuelle Störfälle

+
+ +
+
+
+
+ + + + diff --git a/templates/static/topnav.html b/templates/static/topnav.html index 18ba7a8..681fdaa 100644 --- a/templates/static/topnav.html +++ b/templates/static/topnav.html @@ -1,7 +1,7 @@