beb988f1 by Rafal Wilinski Committed by GitHub

Merge pull request #21 from jdormit/master

Do not rely on changing Array.prototype
2 parents fd8ad210 ecd6d5f8
Showing 1 changed file with 6 additions and 10 deletions
......@@ -22,10 +22,6 @@
}]
};
Array.prototype.last = function() {
return this[this.length - 1];
};
const gatherOsMetrics = (io, span) => {
const defaultResponse = {
'2': 0,
......@@ -38,14 +34,14 @@
};
pidusage.stat(process.pid, (err, stat) => {
const last = span.responses[span.responses.length - 1];
// Convert from B to MB
stat.memory = stat.memory / 1024 / 1024;
stat.load = os.loadavg();
stat.timestamp = Date.now();
span.os.push(stat);
if (!span.responses[0] || span.responses.last().timestamp + (span.interval * 1000) < Date.now()) span.responses.push(defaultResponse);
if (!span.responses[0] || last.timestamp + (span.interval * 1000) < Date.now()) span.responses.push(defaultResponse);
if (span.os.length >= span.retention) span.os.shift();
if (span.responses[0] && span.responses.length > span.retention) span.responses.shift();
......@@ -105,10 +101,10 @@
config.spans.forEach((span) => {
const last = span.responses[span.responses.length - 1];
if (last !== undefined &&
span.responses.last().timestamp / 1000 + span.interval > Date.now() / 1000) {
span.responses.last()[category]++;
span.responses.last().count++;
span.responses.last().mean = span.responses.last().mean + ((responseTime - span.responses.last().mean) / span.responses.last().count);
last.timestamp / 1000 + span.interval > Date.now() / 1000) {
last[category]++;
last.count++;
last.mean = last.mean + ((responseTime - last.mean) / last.count);
} else {
span.responses.push({
'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!