ecd6d5f8 by EighthNote Committed by GitHub

Do not rely on changing Array.prototype

1 parent fd8ad210
Showing 1 changed file with 6 additions and 10 deletions
...@@ -22,10 +22,6 @@ ...@@ -22,10 +22,6 @@
22 }] 22 }]
23 }; 23 };
24 24
25 Array.prototype.last = function() {
26 return this[this.length - 1];
27 };
28
29 const gatherOsMetrics = (io, span) => { 25 const gatherOsMetrics = (io, span) => {
30 const defaultResponse = { 26 const defaultResponse = {
31 '2': 0, 27 '2': 0,
...@@ -38,14 +34,14 @@ ...@@ -38,14 +34,14 @@
38 }; 34 };
39 35
40 pidusage.stat(process.pid, (err, stat) => { 36 pidusage.stat(process.pid, (err, stat) => {
41 37 const last = span.responses[span.responses.length - 1];
42 // Convert from B to MB 38 // Convert from B to MB
43 stat.memory = stat.memory / 1024 / 1024; 39 stat.memory = stat.memory / 1024 / 1024;
44 stat.load = os.loadavg(); 40 stat.load = os.loadavg();
45 stat.timestamp = Date.now(); 41 stat.timestamp = Date.now();
46 42
47 span.os.push(stat); 43 span.os.push(stat);
48 if (!span.responses[0] || span.responses.last().timestamp + (span.interval * 1000) < Date.now()) span.responses.push(defaultResponse); 44 if (!span.responses[0] || last.timestamp + (span.interval * 1000) < Date.now()) span.responses.push(defaultResponse);
49 45
50 if (span.os.length >= span.retention) span.os.shift(); 46 if (span.os.length >= span.retention) span.os.shift();
51 if (span.responses[0] && span.responses.length > span.retention) span.responses.shift(); 47 if (span.responses[0] && span.responses.length > span.retention) span.responses.shift();
...@@ -105,10 +101,10 @@ ...@@ -105,10 +101,10 @@
105 config.spans.forEach((span) => { 101 config.spans.forEach((span) => {
106 const last = span.responses[span.responses.length - 1]; 102 const last = span.responses[span.responses.length - 1];
107 if (last !== undefined && 103 if (last !== undefined &&
108 span.responses.last().timestamp / 1000 + span.interval > Date.now() / 1000) { 104 last.timestamp / 1000 + span.interval > Date.now() / 1000) {
109 span.responses.last()[category]++; 105 last[category]++;
110 span.responses.last().count++; 106 last.count++;
111 span.responses.last().mean = span.responses.last().mean + ((responseTime - span.responses.last().mean) / span.responses.last().count); 107 last.mean = last.mean + ((responseTime - last.mean) / last.count);
112 } else { 108 } else {
113 span.responses.push({ 109 span.responses.push({
114 '2': category === 2 ? 1 : 0, 110 '2': category === 2 ? 1 : 0,
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!