Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async readContainerStats() {
// Prevent overlapping read of stats
if (this.isReading) {
return;
} else {
this.isReading = true;
let startPromises = [];
try {
for (let i = 0; i < this.containers.length; i++) {
if (this.containers[i].remote === null) {
// local
startPromises.push(SystemInformation.dockerContainerStats(this.containers[i].id));
} else {
// remote
startPromises.push(this.containers[i].remote.stats({ stream: false }));
}
}
const results = await Promise.all(startPromises);
this.stats.time.push(Date.now() / 1000);
for (let i = 0; i < results.length; i++) {
let stat = results[i];
let id = stat.id;
if (this.containers.length <= i) {
break;
}
if (id !== this.containers[i].id) {
Logger.warn('inconsistent id within statistics gathering');