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