I'm running a node.js application from within a docker container. I'm trying to retrieve system usage metrics of the container the node.js application is running inside of. Right now I'm using https://www.npmjs.com/package/dockerstats but it consistently shows no cpu or memory usage, running docker stats shows usage in each.
My code resembles the following:
let dockerId = setUp.getDockerId();
dockerId.then(dockerId => {
if (dockerId !== null) {
console.log(`dockerId: ${dockerId}`);
dockerstats.dockerContainerStats(dockerId, data => {
console.log(`cpu_percent: ${data.cpu_percent}`);
console.log(`memPercent: ${data.memPercent}`);
console.log(`memUsage: ${data.memUsage}`);
});
}
});
The setUp class resembles the following and uses https://www.npmjs.com/package/docker-container-id:
const getId = require('docker-container-id');
module.exports = class setUp {
getDockerId () {
return getId().then(id => {
if (!id) {
return null;
}
return id;
});
}
}