-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstable.html
693 lines (607 loc) · 29.5 KB
/
stable.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
<html>
<head>
<title>Heat Map </title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript"
src="https://static.codehs.com/gulp/1819a98e50d8278c5368fd54959eb0fc77db61ec/chs-js-lib/chs.js"></script>
<style>
canvas {
border: 1px solid black;
display: inline-block;
vertical-align: top;
}
pre {
border: 1px solid white;
display: inline-block;
width: 1400px;
height: 1px;
background-color: #F5F5F5;
}
svg {
position: absolute;
left: 1400px;
top: 1220px;
background-color: "black";
}
h1 {
text-align: center;
}
img {
position: absolute;
top: 890px;
left: 1175px;
}
</style>
</head>
<body>
<h1>Heat Map of HPCC</h1>
<canvas
id="canvas"
width="1400"
height="800"
class="codehs-editor-canvas">
</canvas>
<pre id="console"></pre>
<button onclick="sendData(1)">Help</button>
<button onclick="sendData(2)">Control Panel</button>
<button onclick="sendData(3)">Graphs</button>
<button onclick="redfishRequest()">Redfish</button>
<button onclick="completeMetrics()">Metrics</button>
<div id="outputConsole" style="border:1px solid black; width:310; height:100px; background-color:lightgray">
<p> No machines selected </p>
</div>
<!-- <div id="hoverBox" style="border:1px solid black; width:100; height:20; background-color:white">
<p> Hey </p>
</div>-->
<img src="http://www.ttusbdc.org/lubbock/wp-content/uploads/2015/07/ttu.jpg"
alt="HTML5 Icon" style="width:200px; height:150px;">
<svg
id="row" viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">
<rect id="hover" x="10" y="10" width="80" height="750" />
</svg>
<script>
var numShelves = 72;
var numRacks = prompt("Enter number of racks to display", "12");
var numRows = 1;
var numMachines = numShelves * numRacks;
var id;
var payload = [
{
"name": "compute-1-3",
"temp": "24 F",
"speed": "19 rpm",
"usage": "29%",
"power": "4.11 V"
},
{
"name": "compute-2-1",
"temp": "72 F",
"speed": "5919 rpm",
"usage": "29%",
"power": "4.11 V"
},
{
"name": "compute-2-2",
"temp": "8 F",
"speed": "50 rpm",
"usage": "56%",
"power": "5.07 V"
},
{
"name": "compute-3-12",
"temp": "50 F",
"speed": "120 rpm",
"usage": "29%",
"power": "4.11 V"
},
{
"name": "compute-3-71",
"temp": "8 F",
"speed": "150 rpm",
"usage": "56%",
"power": "5.07 V"
},
{
"name": "compute-3-72",
"temp": "8 F",
"speed": "150 rpm",
"usage": "56%",
"power": "5.07 V"
},
];
// So this only gets called if there is an alert after it. Sometimes.
// I guess it has something to do with the order in which the page
// evaluates the script? Find alternatives to alert, so you
// don't have to deal with alert every time you reload the page.
$.getJSON("http://localhost:8888/test_two.json", function(data){
console.log(data);
for (var key in data){
var snippet = {
"name": data[key].name,
"temp": data[key].temp,
"speed": data[key].speed,
"usage": data[key].usage,
"power": data[key].power
};
payload.push(snippet);
}
});
/*$.getJSON("http://localhost:8888/completeMetrics.json", function(data){
console.log(data);
alert("hello");
for (var key in data){
var snippet = {
"name": data[key].name,
"id": data[key].id,
"state": data[key].state,
"health": data[key].health,
"readingCelsius": data[key].temp.readingCelsius,
"criticalUpperTemp": data[key].temp.criticalUpper,
"fatalUpper": data[key].temp.fatalUpper,
"speed": data[key].speed,
"usage": data[key].usage,
"consumedWatts": data[key].power.consumedWatts,
"requestedWatts": data[key].power.requestedWatts,
"availableWatts": data[key].power.availableWatts,
"voltage": data[key].power.volts.voltage,
"criticalUpperVolt": data[key].power.volts.criticalUpper,
"fatalUpperVolt": data[key].power.volts.fatalUpper,
"criticalLowerVolt": data[key].power.volts.criticalLower,
"fatalLowerVolt": data[key].power.volts.fatalLower,
};
payload.push(snippet);
alert("Working");
}
});*/
//alert("outer"); // Uncomment alert to make getJSON work. Ask Dr. Turner about this.
window.onload = function() {
var timer;
$(document.getElementById('row')).mouseenter(function() {
var that = this;
timer = setTimeout(function(){
$('row').removeClass('hovered');
$(that).addClass('hovered');
drawHoverBox(10,10);
}, 10);
}).mouseleave(function() {
clearHoverBox();
clearTimeout(timer);
});
// Hover box functions are not working yet. But this is just a graphics nicety.
// Get the Redfish queries working first.
function drawHoverBox(x,y){
var NS = "http://www.w3.org/2000/svg";
var box = document.createElementNS(NS, "rect");
console.log(box);
box.setAttribute("x", x);
box.setAttribute("y", y);
box.setAttribute("width", 90);
box.setAttribute("height", 40);
box.style.strokeWidth="1";
box.style.stroke="#111111";
box.style.fillOpacity="1.0";
box.style.fill="white";
row.appendChild(box);
var text = document.createTextNode("Compute id relevant metrics");
row.appendChild(text);
}
function clearHoverBox(){
var box = document.getElementById("row");
while (box.firstChild){
box.removeChild(box.firstChild);
}
}
var machineHeight = getHeight()/(numShelves+2);
var rackHeight = numShelves * machineHeight + 4;
var rackWidth = 100;
// This sizing method works much better. Rack width is constant,
// canvas is adjusted depending on how many racks are displayed.
var canvasWidth = 110 * numRacks;
var originalHeight = getHeight();
document.getElementById("canvas").setAttribute("width",canvasWidth);
//document.getElementById("canvas").setAttribute("height",originalHeight+10);
var NUM_ROWS = numShelves;
var NUM_COLS = numRacks;
var ROW_HEIGHT = (originalHeight-10);
var COL_WIDTH = getWidth()/NUM_COLS;
// Adjust these values for whatever a suitable core temperature is
var coreTempGreenZone = 10;
var coreTempYellowZone = 20;
var coreTempOrangeZone = 30;
var coreTempRedZone = 40;
// Adjust these values for whatever a suitable fan speed is
var fanSpeedGreenZone = 50;
var fanSpeedYellowZone = 100;
var fanSpeedOrangeZone = 150;
var fanSpeedRedZone = 200;
// These values should represent percent used or # tasks processing
var usageGreenZone = 25;
var usageYellowZone = 50;
var usageOrangeZone = 75;
var usageRedZone = 90;
// Power draw thresholds
var powerGreenZone = 2;
var powerYellowZone = 6;
var powerOrangeZone = 8;
var powerRedZone = 12;
// Toggle frame line definitions
var top = new Line(0, 0, 0, 0);
var bot = new Line(0, 0, 0, 0);
var left = new Line(0, 0, 0, 0);
var right = new Line(0, 0, 0, 0);
var outputConsole = document.getElementById("outputConsole");
var selected = document.getElementById("textBox");
// Data duplication (for testing visualization only)
/* for (var j=4; j<=12; j++){
for (var i=1; i<72; i++){
var name = "compute-"+j+"-"+i;
var temp = Randomizer.nextInt(1,10);
var speed = Randomizer.nextInt(2,50);
var usage = Randomizer.nextInt(0,100);
var power = Randomizer.nextInt(1,2);
var chunk = {
name: name,
temp: temp+" F",
speed: speed+" rpm",
usage: usage+"%",
power: power+" V"
};
payload.push(chunk);
}
}*/
// Draw Row
for (var i=0; i<numRacks; i++){
// +10 for spacing
addRackNumber((10+rackWidth)* i,10,i);
draw_rack((10+rackWidth)* i,10); // Reset to 10 if new spacing doesn't work out
}
setTimer(masterUpdate, 5000);
function masterUpdate(){
// Parse JSON payload
for (var i=0; i<payload.length; i++){
//alert(payload.length);
var json = payload[i];
var name = json.name;
var temp = parseInt(json.temp);
var speed = parseInt(json.speed);
var usage = parseInt(json.usage);
var power = parseInt(json.power);
// Isolate rack number from original name string
var rack = '';
var j = 8;
while (name[j] != "-"){
rack += name[j];
j += 1;
}
// Isolate shelf number from original name string
var shelf = name.slice(j+1);
// Coordinates to draw machine at
var x = (rack - 1) * (rackWidth + 10) + 6;
var y = (getHeight() - 15) - (shelf * (machineHeight) - 2); // Reset to 15 if new spacing doesn't work out
// Draw row is the first thing called, shouldn't ever have to update
// Draw machine and parse in the json will be on a loop (periodically
// request a json payload and redraw machines (but leave racks alone))
drawMachine(name,temp,speed,20,power,x,y);
// This is working backwards from draw machine. Given a location
// (where you clicked) this function fetches relevant info associated
// with that location
mouseClickMethod(whatRack);
}
}
function drawMachine(name,temp,speed,usage,power,x,y){
var innerRect = new Rectangle(rackWidth-5, machineHeight-4);
var outerRect = new Rectangle(rackWidth-2,machineHeight-2);
var core = new Rectangle(12,machineHeight-4);
var fan = new Rectangle(12,machineHeight-4);
var tasks = new Rectangle(12,machineHeight-4);
var draw = new Rectangle(12,machineHeight-4);
outerRect.setPosition(x, y);
innerRect.setPosition(x+1, y+1);
core.setPosition(x+4,y+1);
fan.setPosition(x+18,y+1);
tasks.setPosition(x+32,y+1);
draw.setPosition(x+47,y+1);
outerRect.setColor(Color.black);
innerRect.setColor(Color.gray);
// Temperature (C)
var coreColor = coreTempColorSpectrum(temp);
core.setColor(coreColor);
// Fan Speed (rpm)
var fanColor = fanSpeedColorSpectrum(speed);
fan.setColor(fanColor);
// Power Draw (V)
var powerColor = powerColorSpectrum(power);
draw.setColor(powerColor);
// % CPU usage
var use = usageColorSpectrum(usage);
tasks.setColor(use);
add(outerRect);
add(innerRect);
add(core);
add(fan);
add(draw);
add(tasks);
}
// These color spectrum functions determine machine color based off thresholds
// for metrics like heat, speed, etc.
function fanSpeedColorSpectrum(speed){
if (speed <= 0){
return "white";
}
else if (speed > 0 && speed <= fanSpeedGreenZone){
return "green";
}
else if (speed > fanSpeedGreenZone && speed <= fanSpeedYellowZone){
return "yellow";
}
else if (speed > fanSpeedYellowZone && speed <= fanSpeedOrangeZone){
return "orange";
}
else if (speed > fanSpeedOrangeZone && speed <= fanSpeedRedZone){
return "red"
}
else if (speed > fanSpeedRedZone){
return "black";
}
}
function coreTempColorSpectrum(temp){
if (temp <= 0){
return "white";
}
else if (temp <= coreTempGreenZone){
return "green";
}
else if (temp > coreTempGreenZone && temp <= coreTempYellowZone){
return "yellow";
}
else if (temp > coreTempYellowZone && temp <= coreTempOrangeZone){
return "orange";
}
else if (temp > coreTempOrangeZone && temp <= coreTempRedZone){
return "red"
}
else if (temp > coreTempRedZone){
return "black";
}
}
function powerColorSpectrum(power){
if (power <= 0){
return "white";
}
else if (power <= powerGreenZone){
return "green";
}
else if (power > powerGreenZone && power <= powerYellowZone){
return "yellow";
}
else if (power > powerYellowZone && power <= powerOrangeZone){
return "orange";
}
else if (power > powerOrangeZone && power <= powerRedZone){
return "red"
}
else if (power > powerRedZone){
return "black";
}
}
function usageColorSpectrum(use){
if (use <= 0){
return "white";
}
else if (use <= usageGreenZone){
return "green";
}
else if (use > usageGreenZone && use <= usageYellowZone){
return "yellow";
}
else if (use > usageYellowZone && use <= usageOrangeZone){
return "orange";
}
else if (use > usageOrangeZone && use <= usageRedZone){
return "red"
}
else if (use > usageRedZone){
return "black";
}
}
function draw_rack(x,y){
var border = new Rectangle(rackWidth,rackHeight);
border.setPosition(x+5,y-4);
border.setColor(Color.black);
add(border);
var inner = new Rectangle(rackWidth-4,rackHeight-4);
inner.setPosition(x+7,y-2);
inner.setColor('#9bb29d');
add(inner);
}
function addRackNumber(x,y,i){
var j = i + 1;
var number = new Text("Rack# " + j, "11pt Arial");
number.setPosition(x+25, y+rackHeight+8);
number.set
add(number);
}
// plan D: iA - A <= x <= iA where i is col #, x is xCor, A is column width. find i given x.
// Apparently without the heading (<h1>), the top 2 or 3 shelves won't register with e.getX()/e.getY()
function whatRack(e){
var xCor = e.getX();
var yCor = e.getY();
var elem = getElementAt(xCor,yCor);
if (elem != null){
var i = 0;
while(true){
i++;
if((i*COL_WIDTH - COL_WIDTH) <= xCor && xCor <= i*COL_WIDTH){
whatMachine(yCor,i);
break;
}
}
}
}
// This function determines what machine # is clicked on, passes that value
// to displayReadings.
function whatMachine(yCor,i){
var rackNum = i;
var j = 0;
while(true){
j++;
if((j*machineHeight - machineHeight) <= yCor && yCor <= j*machineHeight){
var shelfNum = Math.abs(72 - (j-1)); // Reset to 72 if new spacing doesn't work out
shelfNum += 1;
displayReadings(rackNum,shelfNum);
toggleFrame(rackNum, shelfNum);
break;
}
}
}
// This function should display the numeric values (core temp, fan speed, etc)
// of the object the mouse clicked on.
function displayReadings(rackNum,shelfNum){
$(document).ready(function(){
$("div").empty();
});
id = ("compute-"+rackNum+"-"+shelfNum);
// Eventually clicking on the Graphs button will pass selected_node to Graphs
// That way Graphs can build the graphs by searching the database for all info
// related to selected_node
// Surely there is a faster way to find the right json object
// instead of searching the whole list (payload) change this to a whille loop? sholdnt matter bc break
for (var i=0; i<payload.length; i++){
var json = payload[i];
var nameTwo = json.name;
if (nameTwo == id){
// I guess I could just cocatenate these all into one text node
var id_text = document.createTextNode("Name: "+id+"\n");
var ct = document.createTextNode("The core temperature is "+json.temp+"\n");
var fd = document.createTextNode("The fan speed is "+json.speed+"\n");
var us = document.createTextNode("The usage is "+json.usage+"\n");
var pw = document.createTextNode("The power is "+json.power+"\r\n");
outputConsole.appendChild(id_text);
var br = document.createElement("br");
outputConsole.append(br);
outputConsole.appendChild(ct);
var br = document.createElement("br");
outputConsole.append(br);
outputConsole.appendChild(fd);
var br = document.createElement("br");
outputConsole.append(br);
outputConsole.appendChild(us);
var br = document.createElement("br");
outputConsole.append(br);
outputConsole.appendChild(pw);
break;
}
}
}
function toggleFrame(rackNum, shelfNum){
var x1 = (rackNum - 1) * (rackWidth + 10) + 6;
var y1 = (getHeight() - 15) - (shelfNum * (machineHeight));
var x2 = x1 + rackWidth - 2;
var y2 = y1 + machineHeight;
top.setPosition(x1, y1);
top.setEndpoint(x2, y1);
bot.setPosition(x1, y2);
bot.setEndpoint(x2, y2);
left.setPosition(x1, y1);
left.setEndpoint(x1, y2);
right.setPosition(x2, y1);
right.setEndpoint(x2, y2);
top.setColor(Color.blue);
bot.setColor(Color.blue);
right.setColor(Color.blue);
left.setColor(Color.blue);
top.setLineWidth(4);
bot.setLineWidth(4);
left.setLineWidth(4);
right.setLineWidth(4);
add(top);
add(bot);
add(left);
add(right);
}
var somethingDifferent = document.getElementById("hover");
somethingDifferent.style.fill = "#24b70b";
//alert("hey");
}
//Wow it worked!
function sendData(num){
if (num == 3){
window.open('http://localhost:8888/Graphs.html?id='+id);
} else if (num == 2){
window.open('http://localhost:8888/heatMapControlPanel.html?id='+id);
} else {
window.open('http://localhost:8888/heatMapHelp.html?id='+id);
}
}
function redfishRequest(){
var main_link = "http://localhost:8080/redfish/v1/";
var thermal_link = "http://localhost:8080/redfish/v1/Chassis/Thermal/1U/Thermal#/Temperatures/";
var power_link = "http://localhost:8080/redfish/v1/Chassis/Thermal/1U/Power/";
var temp_list = [];
var power_list = [];
// Should open connection to Froda via RedfishQueryScript.sh
// Still needs work
/* var exec = require('child_process').exec, child;
child = exec('cat *.js bad_file | wc -l',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
child();*/
// So far so good for this chunk
// Will I need a seperate GET request for every metric?
// Or can I pull the full payload and parse it locally?
$.get(main_link, function(data){
//alert("ok");
for (var key in data){
alert(key);
}
});
$.get(thermal_link, function(data){
for (var i = 0; i < key.length; i++){
temp_list.append(key[i].ReadingCelcisus);
}
});
$.get(power_link, function(data){
for (var i = 0; i < key.length; i++){
power_list.append(key[i].PowerConsumedWatts);
}
});
}
function completeMetrics(){
//alert("one");
$.getJSON("http://localhost:8888/completeMetrics.json", function(data){
//alert(payload.length);
console.log(data);
var snippet = {
"name": data.name,
"id": data.id,
"state": data.state,
"health": data.health,
"readingCelsius": data.temp.readingCelsius,
"criticalUpperTemp": data.temp.criticalUpper,
"fatalUpper": data.temp.fatalUpper,
"speed": data.speed,
"usage": data.usage,
"consumedWatts": data.power.consumedWatts,
"requestedWatts": data.power.requestedWatts,
"availableWatts": data.power.availableWatts,
"voltage": data.power.volts.voltage,
"criticalUpperVolt": data.power.volts.criticalUpper,
"fatalUpperVolt": data.power.volts.fatalUpper,
"criticalLowerVolt": data.power.volts.criticalLower,
"fatalLowerVolt": data.power.volts.fatalLower,
};
payload.push(snippet);
//alert(payload.length);
});
/*for (var i = 0; i < payload.length; i++){
alert(payload[i].name);
} */
}
</script>
</body>
</html>