Clean stats api response to have specific response types
This commit is contained in:
@@ -64,9 +64,10 @@ async function getContainerStats(name, fromMinutes, noNullPoints) {
|
||||
if (error) throw new BoxError(BoxError.NETWORK_ERROR, error.message);
|
||||
if (response.status !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, `Unknown error with ${target}: ${response.status} ${response.text}`);
|
||||
|
||||
results.push(response.body[0]);
|
||||
results.push(response.body[0] && response.body[0].datapoints ? response.body[0].datapoints : []);
|
||||
}
|
||||
|
||||
// results are datapoints[[value, ts], [value, ts], ...];
|
||||
return {
|
||||
cpu: results[0],
|
||||
memory: results[1],
|
||||
@@ -74,10 +75,10 @@ async function getContainerStats(name, fromMinutes, noNullPoints) {
|
||||
blockWrite: results[3],
|
||||
networkRead: results[4],
|
||||
networkWrite: results[5],
|
||||
blockReadTotal: results[6].datapoints[0] ? results[6].datapoints[0][0] : 0,
|
||||
blockWriteTotal: results[7].datapoints[0] ? results[6].datapoints[0][0] : 0,
|
||||
networkReadTotal: results[8].datapoints[0] ? results[6].datapoints[0][0] : 0,
|
||||
networkWriteTotal: results[9].datapoints[0] ? results[6].datapoints[0][0] : 0,
|
||||
blockReadTotal: results[6][0] || 0,
|
||||
blockWriteTotal: results[7][0] || 0,
|
||||
networkReadTotal: results[8][0] || 0,
|
||||
networkWriteTotal: results[9][0] || 0,
|
||||
cpuCount: os.cpus().length
|
||||
};
|
||||
}
|
||||
@@ -114,8 +115,8 @@ async function getSystem(fromMinutes, noNullPoints) {
|
||||
}
|
||||
|
||||
return {
|
||||
cpu: memCpuResponse.body[0],
|
||||
memory: memCpuResponse.body[1],
|
||||
cpu: memCpuResponse.body[0] && memCpuResponse.body[0].datapoints ? memCpuResponse.body[0].datapoints : [],
|
||||
memory: memCpuResponse.body[1] && memCpuResponse.body[1].datapoints ? memCpuResponse.body[1].datapoints : [],
|
||||
apps: appResponses,
|
||||
services: serviceResponses,
|
||||
cpuCount: os.cpus().length
|
||||
|
||||
Reference in New Issue
Block a user