broken
Harald Wolff 2019-04-17 22:56:31 +02:00
parent d40ca501f8
commit 2f5b2f9a92
4 changed files with 143 additions and 47 deletions

View File

@ -44,11 +44,13 @@ namespace ln.skyscanner.crawl
Name = String.Format("Subnet crawl {0} [{1}]", subnet.Network, network); Name = String.Format("Subnet crawl {0} [{1}]", subnet.Network, network);
} }
private int maxScanWidth = 28;
public override void RunJob() public override void RunJob()
{ {
if (Network.Width < 26) if (Network.Width < maxScanWidth)
{ {
SplitJob(Network.Divide(26 - (int)Network.Width).Select((n) => new CrawlNetwork(Crawler, Subnet, n)).ToArray()); SplitJob(Network.Divide(maxScanWidth - (int)Network.Width).Select((n) => new CrawlNetwork(Crawler, Subnet, n)).ToArray());
return; return;
} }
@ -101,7 +103,7 @@ namespace ln.skyscanner.crawl
Subnet.NextScan = startTime + TimeSpan.FromHours(24); Subnet.NextScan = startTime + TimeSpan.FromHours(24);
} }
SkyScanner.Instance.Entities.CrawledHosts.Upsert(Subnet); SkyScanner.Instance.Entities.CrawledSubnets.Upsert(Subnet);
} }
public override int GetHashCode() public override int GetHashCode()

View File

@ -16,7 +16,7 @@ namespace ln.skyscanner.http
public SkyScanner SkyScanner { get; } public SkyScanner SkyScanner { get; }
public String BasePath { get; private set; } public String BasePath { get; private set; }
public String TemplatesBasePath => Path.Combine(BasePath, "templates","static"); public String TemplatesBasePath { get; private set; }
ReflectiveResource refChecker; ReflectiveResource refChecker;
ReflectiveResource refEntities; ReflectiveResource refEntities;
@ -26,6 +26,12 @@ namespace ln.skyscanner.http
SkyScanner = skyScanner; SkyScanner = skyScanner;
BasePath = Path.GetFullPath("."); BasePath = Path.GetFullPath(".");
TemplatesBasePath = Path.Combine(BasePath, "templates", "static");
/* Development hint */
if (Directory.Exists("../../templates/static"))
TemplatesBasePath = Path.Combine(BasePath, "..", "..", "templates", "static");
DirectoryResource staticTemplates = new DirectoryResource(RootResource, TemplatesBasePath); DirectoryResource staticTemplates = new DirectoryResource(RootResource, TemplatesBasePath);

View File

@ -1,8 +1,11 @@
<%frame "frame.html"%> <%frame "frame.html"%>
<h1>Aktuelle Störfälle</h1> <h1>Aktuelle Störfälle (<span id="lastUpdate"></span>)</h1>
<span id="nCRITICAL" class="CRITICAL"></span> <div style="background-color: #404040; color: white;">
<span id="nWARN" class="WARN"></span><br/> Kritisch: <span id="nCRITICAL" class="CRITICAL"></span>
Warnungen: <span id="nWARN" class="WARN"></span><br/>
</div>
<br/> <br/>
<select id="interval" style="width: 180px;"> <select id="interval" style="width: 180px;">
<option value="3600">1 Stunde</option> <option value="3600">1 Stunde</option>
@ -13,22 +16,28 @@
</select> </select>
<button onclick="refresh();">Aktualisieren</button> <button onclick="refresh();">Aktualisieren</button>
<br/> <br/>
<div class="flex row">
<div class="flex column"> <div class="">
<div id="CRITICAL"></div> <div id="CRITICAL"></div>
<div id="WARN"></div> <div id="WARN"></div>
<div id="FAIL"></div> <div id="FAIL"></div>
<div id="ERROR"></div> <div id="ERROR"></div>
</div>
<div class="grow" style="">
</div>
</div> </div>
<div style="visibility: hidden;"> <div style="visibility: hidden;">
<div id="nodetemplate" class="issue-box" style="margin-bottom: 16px;"> <div id="nodetemplate" class="issue-box" style="margin-bottom: 16px;">
<h2 id="title"></h2> <h2 id="title"></h2>
<div> <div class="flex row">
Last Check: <span id="LastCheckTime"></span><br> <div class="fill">
Current State for: <span id="UnchangedTime"></span><br> Last Check: <span id="LastCheckTime"></span><br>
</div> Current State for: <span id="UnchangedTime"></span><br>
<div id="PerfValues"> </div>
<div id="History">
</div>
<div id="PerfValues" class="fill">
</div>
</div> </div>
</div> </div>
<div id="pvtemplate" class="performance-value flex"> <div id="pvtemplate" class="performance-value flex">
@ -41,14 +50,15 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
moment.defaultFormat = "DD.MM.YYYY HH:mm"; moment.defaultFormat = "DD.MM.YYYY HH:mm:ss";
var issues = {} var issues = {}
var charts = [] var charts = []
var chartTimeout = null;
function graphLoaded(pv, performanceValue, perfData) function graphLoaded(pv, performanceValue, perfData)
{ {
var chartColor = performanceValue.CheckState == "CRITICAL" ? '#FF0000' : (performanceValue.CheckState == "WARN") ? '#FFFF00' : '#000000'; var chartColor = performanceValue.CheckState == "CRITICAL" ? '#FF0000' : (performanceValue.CheckState == "WARN") ? '#C0C000' : '#000000';
var chart = new Chart( $("#chart", pv), { var chart = new Chart( $("#chart", pv), {
type: 'bar', type: 'bar',
data: { data: {
@ -89,9 +99,9 @@
chart.data.labels.length = 0; chart.data.labels.length = 0;
chart.data.datasets[0].data.length = 0; chart.data.datasets[0].data.length = 0;
chart.data.datasets[0].label = perfName; chart.data.datasets[0].label = performanceValue.PerfName;
$.each( perfValues, function(){ $.each( perfData, function(){
if (this.TimeStamp != 0) if (this.TimeStamp != 0)
chart.data.datasets[0].data.push( { x: this.TimeStamp, y: this.Value } ); chart.data.datasets[0].data.push( { x: this.TimeStamp, y: this.Value } );
}); });
@ -103,29 +113,61 @@
var ne = $("#" + issue.ID ); var ne = $("#" + issue.ID );
if (!ne.length) if (!ne.length)
ne = $("#nodetemplate").clone().attr("id",issue.ID); ne = $("#nodetemplate").clone().attr("id",issue.ID);
ne.appendTo($("#" + issue.CheckState)); var p = $("#" + issue.CheckState);
if (!p.is(ne.parent()))
{
ne.detach();
ne.appendTo(p);
}
ne.removeClass("issue-WARN issue-CRITICAL");
ne.addClass("issue-" + issue.CheckState ); ne.addClass("issue-" + issue.CheckState );
$("h2", ne).text(issue.CheckName + ": " + issue.Node.Name + " ( " + issue.Node.UniqueIdentity + " )"); $("h2", ne).text(issue.CheckName + ": " + issue.Node.Name + " ( " + issue.Node.UniqueIdentity + " )");
$("#LastCheckTime", ne).text(issue.LastCheckTime); $("#LastCheckTime", ne).text(issue.LastCheckTime);
$("#UnchangedTime", ne).text(issue.UnchangedTime); $("#UnchangedTime", ne).text(issue.UnchangedTime);
var histParent = $("#History", ne);
histParent.empty();
var lastHistTime = moment();
$.each( issue.History.slice().reverse(), function(){
var m = moment(this.Timestamp);
var d = lastHistTime == null ? "" : lastHistTime.diff(m, 'minutes');
lastHistTime = m;
$("<span class='" + this.NewState + "'>" + m.format() + " [ " + d + "min ]</span><br>").appendTo( histParent );
});
var pvparent = $("#PerfValues", ne);
pvparent.empty();
$.each( issue.PerformanceValues, function(){ $.each( issue.PerformanceValues, function(){
var pv = $("#" + this.PerfName.replace(/\//g,"-")); pvparent.append( $("<span class='" + this.CheckState + "'>" + this.PerfName + "</span><br>") );
/*
var pv = $("#" + this.PerfName.replace(/[./]/g,""), ne);
if (!pv.length) if (!pv.length)
pv = $("#pvtemplate").clone().attr("id", this.PerfName.replace(/\//g,"-")); pv = $("#pvtemplate").clone().attr("id", this.PerfName.replace(/[./]/g,""));
$("#PerfName", pv).text(this.PerfName); $("#PerfName", pv).text(this.PerfName);
$("#CheckState", pv).text(this.CheckState).addClass(this.CheckState); $("#CheckState", pv).text(this.CheckState).addClass(this.CheckState);
pv.appendTo($("#PerfValues", ne)); var pvparent = $("#PerfValues", ne);
if (!pvparent.is(pv.parent()))
{
pv.detach();
pv.appendTo(pvparent);
}
var _perfValue = this; var _perfValue = this;
var _pv = pv; var _pv = pv;
var perfName = this.PerfName; var perfName = this.PerfName;
charts.push( { pv: _pv, performanceValue: this } ); charts.push( { pv: _pv, performanceValue: this } );
*/
}); });
//loadNextChart(); //loadNextChart();
@ -134,14 +176,21 @@
function loadNextChart() function loadNextChart()
{ {
if (charts.length == 0) if (charts.length == 0)
return; {
clearTimeout(chartTimeout);
chartTimeout = null;
} else {
if (chartTimeout == null)
{
chartTimeout = setTimeout( loadNextChart, 100 );
}
next = charts.shift(); next = charts.shift();
skyapi().getJson("api/checker/checks/" + encodeURIComponent(next.performanceValue.PerfName) + "?interval=" + $("#interval").children("option:selected").val(), function(perfData){ skyapi().getJson("api/checker/checks/" + encodeURIComponent(next.performanceValue.PerfName) + "?interval=" + $("#interval").children("option:selected").val(), function(perfData){
graphLoaded(next.pv, next.performanceValue, perfData); graphLoaded(next.pv, next.performanceValue, perfData);
loadNextChart(); });
}); }
} }
@ -153,7 +202,7 @@
$("#nCRITICAL").text( $("#CRITICAL > div").length ); $("#nCRITICAL").text( $("#CRITICAL > div").length );
$("#nWARN").text( $("#WARN > div").length ); $("#nWARN").text( $("#WARN > div").length );
$("#lastUpdate").text( moment().format() );
} }
skyapi().getJson("/checker/Issues", updateIssueList ); skyapi().getJson("/checker/Issues", updateIssueList );
@ -161,5 +210,8 @@
function refresh() function refresh()
{ {
skyapi().getJson("/checker/Issues", updateIssueList ); skyapi().getJson("/checker/Issues", updateIssueList );
} }
skyapi().addRefresh( refresh, 15 );
</script> </script>

View File

@ -145,18 +145,22 @@ button {
} }
.flex { .flex {
display: flex; display: flex;
position: relative;
} }
.flex.row { .flex.row {
flex-direction: row; flex-direction: row;
} }
.flex.column { .flex.column {
flex-direction: column; flex-direction: column;
} }
.flex > div { .flex > div {
margin: 4px; margin: 4px;
display: inline-block;
} }
.skylogo { .skylogo {
@ -324,6 +328,8 @@ fieldset > label {
} }
.issue-box { .issue-box {
display: block;
border-radius: 6px 6px 0px 0px; border-radius: 6px 6px 0px 0px;
border: 3px solid silver; border: 3px solid silver;
} }
@ -339,9 +345,15 @@ fieldset > label {
padding: 4px; padding: 4px;
} }
.issue-box #History {
max-height: 80px;
overflow-x: hidden;
overflow-y: auto;
}
.issue-WARN { .issue-WARN {
border-color: yellow; border-color: #C0C000;
background-color: yellow; background-color: #C0C000;
color: black; color: black;
} }
.issue-CRITICAL { .issue-CRITICAL {
@ -353,11 +365,35 @@ fieldset > label {
#CheckState { #CheckState {
font-size: 20px; font-size: 20px;
} }
#CheckState.WARN, span#WARN { #CheckState.WARN, span#nWARN {
color: yellow; color: #C0C000;
} }
#CheckState.CRITICAL, span#CRITICAL{ #CheckState.CRITICAL, span#nCRITICAL{
color: RED; color: RED;
margin-right: 12px;
}
#PerfValues > span, #History > span {
display: inline-block;
width: 100%;
}
#History > span {
color: green;
margin-right: 24px;
}
#PerfValues > .WARN, #History > .WARN {
color: #C0C000;
}
#PerfValues > .CRITICAL, #History > .CRITICAL {
color: white;
background-color: red;
}
span#nWARN, span#nCRITICAL {
font-size: 24px;
} }
.performance-value > div { .performance-value > div {