Skip to content

Commit

Permalink
Working on res monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
veniware committed Feb 9, 2024
1 parent 6d06efb commit 66cf511
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Protest/Database/DeviceConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static byte[] Fetch(Dictionary<string, string> parameters, HttpListenerCo
return Data.CODE_INVALID_ARGUMENT.Array;
}

string username = null, password = null;
string username = null!, password = null!;
using (StreamReader reader = new StreamReader(ctx.Request.InputStream, ctx.Request.ContentEncoding)) {
string payload = reader.ReadToEnd().Trim();
string[] split = payload.Split((char)127);
Expand Down
2 changes: 1 addition & 1 deletion Protest/Front/monitor.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
.monitor-template {
display: inline-block;
vertical-align: top;
width: 150px;
width: 125px;
height: 64px;
line-height: 64px;
padding: 8px;
Expand Down
98 changes: 66 additions & 32 deletions Protest/Front/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ class Monitor extends Window {

this.toggleConsoleButton.onclick = ()=> this.ToggleConsole();

this.chartsList.push(this.CreateChart("ping", 75, { type:"ping", prefix:"RTT", unit:"ms" }));
this.chartsList.push(this.CreateChart("cpu", 75, { type:"percent", prefix:"Usage", unit:"%" }));
this.chartsList.push(this.CreateChart("cores", 75, { type:"percents", prefix:"Usage", unit:"%" }));
this.chartsList.push(this.CreateChart("ping", 75, { index:0, protocol:"icmp", type:"ping", prefix:"RTT", unit:"ms" }));

this.InitializeSubnetEmblem();
this.InitializeSocketConnection();
Expand Down Expand Up @@ -162,7 +160,7 @@ class Monitor extends Window {
}

for (let i=0; i<this.chartsList.length; i++) {
if (this.chartsList[i].name !== message.result) { continue; }
if (this.chartsList[i].index !== message.index) { continue; }

if (this.chartsList[i].options.type === "percents") {
this.chartsList[i].Update(message.value);
Expand Down Expand Up @@ -274,9 +272,6 @@ class Monitor extends Window {
btnOK.disabled = false;

innerBox.style.margin = "16px";
innerBox.style.display = "grid";
innerBox.style.gridTemplateColumns = "45% 16px auto";
innerBox.style.gridTemplateRows = "32px 8px auto 100px 8px 64px 8px 64px";

const templatesTab = document.createElement("button");
templatesTab.className = "win-dialog-tab";
Expand Down Expand Up @@ -324,14 +319,31 @@ class Monitor extends Window {
formatInput.appendChild(newOption);
}

const CreateTemplate = (name, icon, type, query, options) => {
let chartOptions = {};
let selectedElement = null;

const CreateTemplate = (name, icon, protocol, query, options) => {
const template = document.createElement("div");
template.textContent = name;
template.style.backgroundImage = `url(${icon})`;
template.className = "monitor-template";

template.onclick = ()=> {
switch (type) {
if (selectedElement) {
selectedElement.style.backgroundColor = "";
}

selectedElement = template;
template.style.backgroundColor = "var(--clr-select)";

formatInput.value = options.format;

chartOptions = options;
chartOptions.name = name;
chartOptions.icon = icon;
chartOptions.protocol = protocol;

switch (protocol) {
case "wmi":
queryInput.value = query;
break;
Expand All @@ -344,14 +356,12 @@ class Monitor extends Window {
break;
}

formatInput.value = options.format;

};

template.ondblclick = ()=> {
switch (type) {
switch (protocol) {
case "wmi":
wmiTab.onclick();
btnOK.onclick();
break;

case "snmp":
Expand All @@ -367,9 +377,10 @@ class Monitor extends Window {

templatesTab.onclick = ()=> {
innerBox.textContent = "";
innerBox.style.display = "block";
innerBox.style.border = "var(--clr-control) solid 1.5px";

const templatesBox = document.createElement("div");
templatesBox.style.border = "var(--clr-control) solid 1.5px";
templatesBox.style.gridArea = "1 / 1 / 9 / 4";
templatesBox.style.overflowY = "scroll";
innerBox.appendChild(templatesBox);
Expand Down Expand Up @@ -415,7 +426,9 @@ class Monitor extends Window {
"wmi",
"SELECT PercentIdleTime FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'",
{
format: "Line chart"
format: "Line chart",
prefix: "Usage",
unit: "%"
}
));

Expand All @@ -425,7 +438,9 @@ class Monitor extends Window {
"wmi",
"SELECT PercentIdleTime FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name != '_Total'",
{
format: "Line charts (grid)"
format: "Line charts (grid)",
prefix: "Usage",
unit: "%"
}
));

Expand All @@ -435,7 +450,9 @@ class Monitor extends Window {
"wmi",
"SELECT FreePhysicalMemory, TotalVisibleMemorySize FROM Win32_OperatingSystem",
{
format: "Line chart"
format: "Line chart",
prefix: "Usage",
unit: "%"
}
));

Expand All @@ -445,7 +462,9 @@ class Monitor extends Window {
"wmi",
"SELECT PercentIdleTime FROM Win32_PerfFormattedData_PerfDisk_PhysicalDisk",
{
format: "Line chart"
format: "Delta chart",
prefix: "Usage",
unit: "%"
}
));

Expand All @@ -455,7 +474,9 @@ class Monitor extends Window {
"wmi",
"SELECT BytesReceivedPersec, BytesSentPersec FROM Win32_PerfFormattedData_Tcpip_NetworkInterface",
{
format: "Delta chart"
format: "Delta chart",
prefix: "Usage",
unit: "%"
}
));

Expand All @@ -465,7 +486,9 @@ class Monitor extends Window {
"icmp",
"",
{
format: "Ping"
format: "Ping",
prefix: "RTT",
unit: "ms"
}
));

Expand All @@ -485,7 +508,9 @@ class Monitor extends Window {
"wmi",
"SELECT * FROM Win32_Battery",
{
format: "List"
format: "List",
prefix: "Usage",
unit: "%"
}
));

Expand All @@ -512,6 +537,10 @@ class Monitor extends Window {

wmiTab.onclick = ()=> {
innerBox.textContent = "";
innerBox.style.border = "none";
innerBox.style.display = "grid";
innerBox.style.gridTemplateColumns = "45% 16px auto";
innerBox.style.gridTemplateRows = "32px 8px auto 100px 8px 64px 8px 64px";

templatesTab.style.background = "";
templatesTab.style.backgroundColor = "";
Expand Down Expand Up @@ -546,7 +575,6 @@ class Monitor extends Window {

optionsBox.append(formatLabel, formatInput);


const minmaxBox = document.createElement("div");
minmaxBox.style.gridArea = "2 / 1 / 2 / 3";
optionsBox.appendChild(minmaxBox);
Expand Down Expand Up @@ -644,20 +672,22 @@ class Monitor extends Window {
txtClassFilter.oninput();
};

templatesTab.onclick();
btnOK.onclick = ()=> {
dialog.Close();

btnOK.addEventListener("click", ()=> {
this.count++;

const chart = {
action: "addwmi",
value: queryInput.value,
id: this.count
index: this.count
};

this.chartsList.push(chart);
this.chartsList.push(this.CreateChart(chartOptions.name, 75, chartOptions));
this.socket.send(JSON.stringify(chart));
});
};

templatesTab.onclick();
}

Start() {
Expand Down Expand Up @@ -708,10 +738,10 @@ class Monitor extends Window {

const dot = document.createElement("div");
dot.style.position = "absolute";
dot.style.right = "192px";
dot.style.top = "10px";
dot.style.width = "9px";
dot.style.height = "9px";
dot.style.right = "190px";
dot.style.top = "9px";
dot.style.width = "10px";
dot.style.height = "10px";
dot.style.borderRadius = "5px";
inner.parentElement.appendChild(dot);

Expand Down Expand Up @@ -741,6 +771,7 @@ class Monitor extends Window {
for (let i=list.length-1; i>=0; i--) {
let x = canvas.width - (list.length-i-1)*gap;
let y = list[i] < 0 ? height-10 : 24 + Math.min((height - 24) * list[i] / 1000, height - 10);

let color;
if (list[i] < 0) { //unreachable/timed out
color = "rgb(240,16,16)";
Expand Down Expand Up @@ -780,12 +811,12 @@ class Monitor extends Window {

dot.style.backgroundColor = (list[list.length-1] < 0) ? "rgb(240,16,16)" : UI.PingColor(list[list.length-1]);
dot.style.boxShadow = `${dot.style.backgroundColor} 0 0 2px`;

dot.style.animation = "";
setTimeout(()=>{ dot.style.animation = "heart-beat .1s ease-out 1"; }, 0);
};

return {
index: this.count,
name: name,
options: options,
Update: Update
Expand Down Expand Up @@ -837,6 +868,7 @@ class Monitor extends Window {
};

return {
index: this.count,
name: name,
options: options,
Update: Update
Expand Down Expand Up @@ -913,6 +945,7 @@ class Monitor extends Window {
};

return {
index: this.count,
name: name,
options: options,
Update: Update
Expand Down Expand Up @@ -974,6 +1007,7 @@ class Monitor extends Window {
};

return {
index: this.count,
name: name,
options: options,
Update: Update
Expand Down
20 changes: 10 additions & 10 deletions Protest/Front/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ const UI = {
logo.style.top = pos.l_top;
logo.style.width = pos.l_width;
logo.style.height = pos.l_height;
}

if (pos.l_top === "48px") {
MENU.isDetached = false;
attachedmenubutton.style.transform = "none";
attachedmenubutton.style.boxShadow = "#202020 0 0 0 3px inset";
menubutton.style.transform = "scaleY(0)";
menubutton.children[0].style.top = "48px";
}
else {
MENU.isDetached = true;
if (pos.l_top === "48px") {
MENU.isDetached = false;
attachedmenubutton.style.transform = "none";
attachedmenubutton.style.boxShadow = "#202020 0 0 0 3px inset";
menubutton.style.transform = "scaleY(0)";
menubutton.children[0].style.top = "48px";
}
else {
MENU.isDetached = true;
}
}
},

Expand Down
2 changes: 1 addition & 1 deletion Protest/Front/window.css
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
width: 0;
height: 0;
border-left: 6px solid transparent;
border-right: 6px solid transparent;
border-right: 6px solid transparent;
border-bottom: 9px solid;
border-radius: 3px;

Expand Down
2 changes: 1 addition & 1 deletion Protest/Front/wmiclasses.json
Original file line number Diff line number Diff line change
Expand Up @@ -2539,7 +2539,7 @@
]
},
{
"class": "Win32_PerfFormattedData_PerfDisk_PhysicalDisk ",
"class": "Win32_PerfFormattedData_PerfDisk_PhysicalDisk",
"properties": [
"AvgDiskBytesPerRead",
"AvgDiskBytesPerTransfer",
Expand Down
2 changes: 1 addition & 1 deletion Protest/Protocols/Telnet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static async void WebSocketHandler(HttpListenerContext ctx) {
while (ws.State == WebSocketState.Open) { //ws to server loop

byte[] buff = new byte[2048];
WebSocketReceiveResult receiveResult = null;
WebSocketReceiveResult receiveResult = null!;
try {
receiveResult = await ws.ReceiveAsync(new ArraySegment<byte>(buff), CancellationToken.None);

Expand Down
Loading

0 comments on commit 66cf511

Please sign in to comment.