forked from oslabs-beta/cacheflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetricsTerminal.js
129 lines (124 loc) · 4.2 KB
/
metricsTerminal.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
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
const readline = require('readline');
const fs = require('fs');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
function terminalPrompt() {
rl.question(
'\nEnter your desired metrics:\n --> Global Metrics\n --> Name of Resolver\n\n=======================================================================================================\n\n',
(answer) => {
if (
answer.toLowerCase() === 'global metrics' ||
answer.toLowerCase() === 'global'
) {
const globalMetricsData = fs.readFileSync(
'./globalMetrics.json',
'utf-8'
);
const jsonGMD = JSON.parse(globalMetricsData);
console.log(
'\n======================================================================================================='
);
console.log(
'\nTotal Number of Query Requests: ' +
jsonGMD.totalNumberOfRequests +
' requests'
);
console.log(
'\nAverage Number of Requests Per Resolver: ' +
jsonGMD.averageNumberOfCalls +
' requests'
);
console.log(
'\nNumber of Uncached Requests: ' +
jsonGMD.numberOfUncachedRequests +
' requests'
);
console.log(
'\nNumber of Cached Requests: ' +
jsonGMD.numberOfCachedRequests +
' requests'
);
console.log(
'\nAverage Cached Latency: ' + jsonGMD.averageUncachedLatency + ' ms'
);
console.log(
'\nAverage Cached Latency: ' + jsonGMD.averageCachedLatency + ' ms'
);
console.log('Total Time Saved: ' + jsonGMD.totalTimeSaved + ' ms');
console.log(
'\nUnique Resolvers: ' + jsonGMD.uniqueResolvers + ' requests'
);
console.log(
'Total Amount of Data Saved to Redis: ' +
jsonGMD.sizeOfDataRedis +
' bytes'
);
console.log(
'Total Amount of Data Saved Locally: ' +
jsonGMD.sizeOfDataLocal +
' bytes'
);
console.log(
'\n======================================================================================================='
);
} else {
const localMetricsData = fs.readFileSync(
'./localMetricsStorage.json',
'utf-8'
);
const jsonLMD = JSON.parse(localMetricsData);
if (jsonLMD[answer]) {
console.log(
'\n=======================================================================================================',
`\n\nData for "${answer}":`
);
console.log(
'\nFirst Time Called: ',
new Date(jsonLMD[answer].firstCall).toString()
);
console.log(
'Last Time Called: ',
new Date(
jsonLMD[answer].allCalls[jsonLMD[answer].allCalls.length - 1]
).toString()
);
console.log('Number of Calls: ' + jsonLMD[answer].numberOfCalls);
console.log(
'Average Time Between calls: ',
jsonLMD[answer].averageCallSpan === 'Insufficient Data'
? 'Insufficient Data'
: jsonLMD[answer].averageCallSpan + ' ms'
);
console.log(
'Uncached Latency: ' + jsonLMD[answer].uncachedCallTime + ' ms'
);
console.log(
'Cached Latency: ' + jsonLMD[answer].cachedCallTime + ' ms'
);
console.log(
'Time Saved by Caching: ' +
(jsonLMD[answer].uncachedCallTime -
jsonLMD[answer].cachedCallTime) +
' ms'
);
console.log(
'Size of Cached Query: ' + jsonLMD[answer].dataSize + ' bytes'
);
console.log(
'Location of Cached Data:',
jsonLMD[answer].storedLocation
);
console.log(
'\n======================================================================================================='
);
} else {
console.log('\nNo Cached Data Found for', `"${answer}"`);
}
}
terminalPrompt();
}
);
}
terminalPrompt();