-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.js
46 lines (39 loc) · 1.59 KB
/
display.js
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
require('console.table');
// This module contains functions to display results in the console
module.exports = {
// General print function (the only one called outside of this module)
printData: function(timeFrame, timestamp, data, alertLog, websites){
console.log('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n');
console.log("\x1b[36m%s\x1b[0m", 'ALERT LOG :');
this.printAlerts(alertLog);
// We specify if the analysis has been made over 10 minutes or 1 hour
if(timeFrame == 600){
console.log("\x1b[36m%s\x1b[0m", 'ANALYSIS OVER THE LAST 10 MINUTES :');
} else {
console.log("\x1b[36m%s\x1b[0m", 'ANALYSIS OVER THE LAST HOUR :');
}
this.printNice(data, websites);
console.log("\x1b[36m%s\x1b[0m", 'Seconds since start : ' + timestamp);
},
// Prints the table with website data
printNice: function(data, websites){
var printableData = [];
for(var i = 0; i < websites.length; i++){
var dataDict = {
'host': websites[i][0],
'availability': Math.floor((data[0][i]*100)).toString() + "%",
'average response time': Math.floor((data[1][i]*1000))/1000,
'max response time': Math.floor((data[2][i]*1000))/1000,
};
var fullData = Object.assign({}, dataDict, data[3][i]); // merge the two dictionnaries in a single one
printableData.push(fullData);
}
console.table(printableData);
},
// Prints the alerts saved in the alert log
printAlerts: function(alertLog) {
for(var i = 0; i < alertLog.length; i++){
console.log(alertLog[i]);
}
},
}