WIP
parent
c9b145482d
commit
602930972f
|
@ -11,7 +11,6 @@ using System;
|
|||
using ln.types.odb;
|
||||
using ln.skyscanner.entities;
|
||||
using System.IO;
|
||||
using LiteDB;
|
||||
using ln.http.resources;
|
||||
using System.Linq;
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ using ln.logging;
|
|||
using Newtonsoft.Json;
|
||||
using ln.types.odb;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
namespace ln.skyscanner.checks
|
||||
{
|
||||
public class CheckJob : PoolJob
|
||||
|
@ -21,10 +22,19 @@ namespace ln.skyscanner.checks
|
|||
[JsonIgnore]
|
||||
public Node Node { get; }
|
||||
|
||||
Dictionary<string, SkyCheckState> checkStates = new Dictionary<string, SkyCheckState>();
|
||||
|
||||
public CheckJob(Node node)
|
||||
{
|
||||
Name = String.Format("Interval check: {0} [{1}]",node.UniqueIdentity,node.PrimaryIP.ToString());
|
||||
Node = node;
|
||||
|
||||
Query stateQuery = Query.Equals<SkyCheckState>("UniqueNodeIdentifier", Node.UniqueIdentity);
|
||||
SkyCheckState[] skyCheckStates = SkyScanner.Instance.Checker.checkStates.Select(stateQuery).ToArray();
|
||||
foreach (SkyCheckState checkState in skyCheckStates)
|
||||
{
|
||||
checkStates.Add(checkState.CheckName, checkState);
|
||||
}
|
||||
}
|
||||
|
||||
public override void RunJob()
|
||||
|
@ -38,17 +48,18 @@ namespace ln.skyscanner.checks
|
|||
|
||||
if (checks[n].IsValid(Node))
|
||||
{
|
||||
Query stateQuery = Query.AND(
|
||||
Query.Equals<SkyCheckState>("CheckName",checks[n].Name),
|
||||
Query.Equals<SkyCheckState>("UniqueNodeIdentifier", Node.UniqueIdentity)
|
||||
);
|
||||
SkyCheckState checkState = SkyScanner.Instance.Checker.CheckStates.Select(stateQuery).FirstOrDefault();
|
||||
|
||||
try
|
||||
{
|
||||
SkyCheckState checkState = checkStates.ContainsKey(checks[n].Name) ? checkStates[checks[n].Name] : null;
|
||||
|
||||
if (checkState != null)
|
||||
{
|
||||
checkState.LastCheckTime = DateTime.Now;
|
||||
}
|
||||
|
||||
checks[n].Check(SkyScanner.Instance.Checker, ref checkState, Node);
|
||||
if (checkState != null)
|
||||
SkyScanner.Instance.Checker.CheckStates.Upsert(checkState);
|
||||
SkyScanner.Instance.Checker.Save(checkState);
|
||||
|
||||
} catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -31,6 +31,13 @@ namespace ln.skyscanner.checks
|
|||
|
||||
public override void Check(SkyChecker skyChecker,ref SkyCheckState checkState,Node node)
|
||||
{
|
||||
if (checkState == null)
|
||||
{
|
||||
checkState = new SkyCheckState(this, node);
|
||||
checkState.WarnLower = 0.6;
|
||||
checkState.CritLower = 0.3;
|
||||
}
|
||||
|
||||
long roundTripTime = 0;
|
||||
int success = 0;
|
||||
int n;
|
||||
|
@ -53,6 +60,7 @@ namespace ln.skyscanner.checks
|
|||
roundTripTime /= success;
|
||||
skyChecker.WritePerfValue(this, "rta", node, roundTripTime);
|
||||
}
|
||||
SetState(checkState, fSuccess);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,20 @@ namespace ln.skyscanner.checks
|
|||
public abstract bool IsValid(Node node);
|
||||
public abstract void Check(SkyChecker skyChecker,ref SkyCheckState checkState,Node node);
|
||||
|
||||
public virtual void SetState(SkyCheckState checkState,double value)
|
||||
{
|
||||
if ((value < checkState.CritLower) || (value > checkState.CritUpper))
|
||||
{
|
||||
checkState.CheckState = CheckState.CRITICAL;
|
||||
} else if ((value < checkState.WarnLower) || (value > checkState.WarnUpper))
|
||||
{
|
||||
checkState.CheckState = CheckState.WARN;
|
||||
}
|
||||
else
|
||||
{
|
||||
checkState.CheckState = CheckState.OK;
|
||||
}
|
||||
}
|
||||
|
||||
static SkyCheck()
|
||||
{
|
||||
|
|
|
@ -9,12 +9,19 @@
|
|||
// **/
|
||||
using System;
|
||||
using ln.skyscanner.entities;
|
||||
using ln.types.odb;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
namespace ln.skyscanner.checks
|
||||
{
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum CheckState { OK, WARN, CRITICAL, FAIL, ERROR }
|
||||
|
||||
public class SkyCheckState
|
||||
{
|
||||
[DocumentID]
|
||||
public Guid ID = Guid.NewGuid();
|
||||
|
||||
public readonly String CheckName;
|
||||
public readonly String UniqueNodeIdentifier;
|
||||
|
||||
|
@ -25,6 +32,8 @@ namespace ln.skyscanner.checks
|
|||
public double CritLower { get; set; } = Double.MinValue;
|
||||
public double CritUpper { get; set; } = Double.MaxValue;
|
||||
|
||||
public CheckState CheckState { get; set; }
|
||||
|
||||
protected SkyCheckState()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ using ln.logging;
|
|||
using ln.snmp;
|
||||
using ln.http.resources;
|
||||
using ln.types.odb;
|
||||
using System.Collections.Generic;
|
||||
namespace ln.skyscanner.checks
|
||||
{
|
||||
public class SkyChecker
|
||||
|
@ -29,6 +30,9 @@ namespace ln.skyscanner.checks
|
|||
public PoolJob[] CurrentJobs => checkPool.CurrentPoolJobs;
|
||||
[Callable]
|
||||
public PoolJob[] QueuedJobs => checkPool.QueuedJobs;
|
||||
[Callable]
|
||||
public SkyCheckState[] CheckStates => checkStates.ToArray();
|
||||
|
||||
|
||||
[Callable]
|
||||
public string[] PerfNames => perfFiles.Keys.ToArray();
|
||||
|
@ -44,7 +48,9 @@ namespace ln.skyscanner.checks
|
|||
bool stopping;
|
||||
|
||||
ODB odb;
|
||||
public ODBCollection<SkyCheckState> CheckStates { get; private set; }
|
||||
public ODBCollection<SkyCheckState> checkStates { get; private set; }
|
||||
|
||||
List<SkyCheckState> saveQueue = new List<SkyCheckState>();
|
||||
|
||||
public SkyChecker()
|
||||
{
|
||||
|
@ -54,9 +60,9 @@ namespace ln.skyscanner.checks
|
|||
SNMPEngine.Timeout = 4000;
|
||||
|
||||
odb = new ODB(Path.Combine(BasePath));
|
||||
CheckStates = odb.GetCollection<SkyCheckState>();
|
||||
CheckStates.EnsureIndex("CheckName");
|
||||
CheckStates.EnsureIndex("UniqueNodeIdentifier");
|
||||
checkStates = odb.GetCollection<SkyCheckState>();
|
||||
checkStates.EnsureIndex("CheckName");
|
||||
checkStates.EnsureIndex("UniqueNodeIdentifier");
|
||||
}
|
||||
|
||||
public void Start()
|
||||
|
@ -64,7 +70,9 @@ namespace ln.skyscanner.checks
|
|||
if ((threadScheduler != null) && (threadScheduler.IsAlive))
|
||||
throw new NotSupportedException("SkyChecker.scheduler() already running");
|
||||
|
||||
checkPool.SetPoolSize(128);
|
||||
checkPool.SetPoolSize(256);
|
||||
|
||||
Thread.Sleep(2500);
|
||||
|
||||
threadScheduler = new Thread(scheduler);
|
||||
threadScheduler.Start();
|
||||
|
@ -154,14 +162,28 @@ namespace ln.skyscanner.checks
|
|||
{
|
||||
while (!stopping)
|
||||
{
|
||||
int n = 0;
|
||||
List<CheckJob> checkJobs = new List<CheckJob>();
|
||||
|
||||
Logging.Log(LogLevel.INFO, "SkyChecker.scheduler(): scheduler save CheckStates");
|
||||
|
||||
lock (saveQueue)
|
||||
{
|
||||
foreach (SkyCheckState checkState in saveQueue)
|
||||
{
|
||||
SkyScanner.Instance.Checker.checkStates.Upsert(checkState);
|
||||
}
|
||||
saveQueue.Clear();
|
||||
}
|
||||
|
||||
Logging.Log(LogLevel.INFO, "SkyChecker.scheduler(): scheduler starts");
|
||||
|
||||
foreach (Node node in SkyScanner.Instance.Entities.GlobalNetwork.Nodes)
|
||||
{
|
||||
CheckJob checkJob = new CheckJob(node);
|
||||
if (checkPool.Enqueue(checkJob))
|
||||
n++;
|
||||
checkJobs.Add(checkJob);
|
||||
}
|
||||
Logging.Log(LogLevel.INFO, "SkyChecker.scheduler(): scheduled {0} checks", n);
|
||||
Logging.Log(LogLevel.INFO, "SkyChecker.scheduler(): prepared {0} checks", checkJobs.Count);
|
||||
Logging.Log(LogLevel.INFO, "SkyChecker.scheduler(): scheduled {0} checks", checkPool.Enqueue(checkJobs));
|
||||
|
||||
while ((nextMinute - DateTimeOffset.Now.ToUnixTimeMilliseconds()) < 0)
|
||||
nextMinute += 60000;
|
||||
|
@ -176,6 +198,14 @@ namespace ln.skyscanner.checks
|
|||
|
||||
}
|
||||
|
||||
public void Save(SkyCheckState checkState)
|
||||
{
|
||||
lock (saveQueue)
|
||||
{
|
||||
saveQueue.Add(checkState);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ComponentState State
|
||||
{
|
||||
|
|
|
@ -56,6 +56,7 @@ namespace ln.skyscanner.checks
|
|||
|
||||
}
|
||||
}
|
||||
checkState.CheckState = CheckState.OK;
|
||||
}
|
||||
|
||||
public override bool IsValid(Node node)
|
||||
|
|
|
@ -13,7 +13,6 @@ using ln.types;
|
|||
using System.Net;
|
||||
using System.Linq;
|
||||
using ln.snmp.rfc1213;
|
||||
using LiteDB;
|
||||
using ln.types.odb;
|
||||
using ln.types.net;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace ln.skyscanner.entities
|
|||
public SkyEntities SkyEntities { get; private set; }
|
||||
|
||||
public IEnumerable<Subnet> Subnets => SkyEntities.subnetCollection;
|
||||
public IEnumerable<Node> Nodes => SkyEntities.nodeCollection;
|
||||
public IEnumerable<Node> Nodes => SkyEntities.nodeCollection.ToArray();
|
||||
|
||||
public HopMap DefaultHopMap { get; private set; } = new HopMap();
|
||||
|
||||
|
|
|
@ -9,15 +9,11 @@
|
|||
// **/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections;
|
||||
using Castle.Core.Logging;
|
||||
using ln.types.odb;
|
||||
using System.Linq;
|
||||
using ln.types.btree;
|
||||
using Castle.Components.DictionaryAdapter.Xml;
|
||||
using Newtonsoft.Json;
|
||||
using ln.types.net;
|
||||
using System.Net.Sockets;
|
||||
namespace ln.skyscanner.entities
|
||||
{
|
||||
public class HopMap : Persistent
|
||||
|
|
|
@ -13,7 +13,6 @@ using ln.types;
|
|||
using ln.skyscanner.crawl;
|
||||
using ln.types.odb;
|
||||
using Newtonsoft.Json;
|
||||
using LiteDB;
|
||||
using ln.logging;
|
||||
using ln.types.net;
|
||||
namespace ln.skyscanner.entities
|
||||
|
|
|
@ -13,7 +13,6 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using ln.types.odb;
|
||||
using Newtonsoft.Json;
|
||||
using LiteDB;
|
||||
using ln.types.threads;
|
||||
using ln.types.net;
|
||||
namespace ln.skyscanner.entities
|
||||
|
|
|
@ -36,13 +36,7 @@
|
|||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Castle.Core">
|
||||
<HintPath>..\packages\Castle.Core.4.3.1\lib\net45\Castle.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="LiteDB">
|
||||
<HintPath>..\packages\LiteDB.4.1.4\lib\net40\LiteDB.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -166,6 +160,9 @@
|
|||
<None Include="templates\static\checks\status.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="templates\static\checks\checkstates.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="identify\" />
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Castle.Core" version="4.3.1" targetFramework="net47" />
|
||||
<package id="LiteDB" version="4.1.4" targetFramework="net47" />
|
||||
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net47" />
|
||||
<package id="SSH.NET" version="2016.1.0" targetFramework="net47" />
|
||||
</packages>
|
|
@ -0,0 +1,42 @@
|
|||
<%frame "frame.html"%>
|
||||
|
||||
<h1>Check Stati</h1>
|
||||
<br/>
|
||||
|
||||
<div class="flex column">
|
||||
<div>
|
||||
<div style="width: 100%;">
|
||||
<table id="CheckStates"></table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var pbar = $().dataTable.render.percentBar('round','#fff', '#FF9CAB', '#FF0033', '#FF9CAB', 0, 'solid');
|
||||
var dtDef = {
|
||||
columns: [
|
||||
{ title: "CheckName", data: "CheckName" },
|
||||
{ title: "UniqueNodeIdentifier", data: "UniqueNodeIdentifier" },
|
||||
{ title: "LastCheckTime", data: "LastCheckTime" },
|
||||
{ title: "CheckState", data: "CheckState" },
|
||||
],
|
||||
};
|
||||
|
||||
$("#CheckStates").DataTable( dtDef );
|
||||
|
||||
function refresh()
|
||||
{
|
||||
skyapi().getJson("checker/CheckStates", function(data){
|
||||
if (!data)
|
||||
data = []
|
||||
|
||||
$("#CheckStates").DataTable().clear();
|
||||
$("#CheckStates").DataTable().rows.add( data ).draw();
|
||||
});
|
||||
}
|
||||
|
||||
refresh();
|
||||
skyapi().addRefresh( refresh, 15 );
|
||||
|
||||
</script>
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
<script type="text/javascript">
|
||||
moment.defaultFormat = "DD.MM.YYYY HH:mm";
|
||||
//Chart.defaults.global.defaultColor = 'rgba(0.1,0.1,1.0,1.0)';
|
||||
|
||||
var chartCTX = $("#perfChart");
|
||||
var chart = new Chart( chartCTX, {
|
||||
|
@ -29,7 +30,8 @@
|
|||
datasets: [
|
||||
{
|
||||
label: "-",
|
||||
data: []
|
||||
data: [],
|
||||
backgroundColor: '#04E000',
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -38,7 +40,8 @@
|
|||
yAxes: [
|
||||
{
|
||||
ticks: {
|
||||
callback: ScaleSI
|
||||
callback: ScaleSI,
|
||||
beginAtZero: true,
|
||||
}
|
||||
}
|
||||
],
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
<a href="/static/checks/index.html" onclick="skyapi().loadPage('static/checks/index.html'); return false;"><div>Checks</div></a>
|
||||
</div>
|
||||
<div>
|
||||
<a href="#" onclick="skyapi().loadPage('static/checker.html'); return false;"><div>Hosts</div></a>
|
||||
<a href="/static/checks/checkstates.html" onclick="skyapi().loadPage('static/checks/checkstates.html'); return false;"><div>Check States</div></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue