Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just use http module #4

Closed
caub opened this issue Dec 2, 2018 · 4 comments
Closed

Just use http module #4

caub opened this issue Dec 2, 2018 · 4 comments

Comments

@caub
Copy link

caub commented Dec 2, 2018

I saw you kinda reimplemented http in dockerSocket.js

you could just use http module, example in this lib I made

fetchu({ path: '/v1.39/services', socketPath: '/var/run/docker.sock' })

from discussion in node-fetch/node-fetch#336 (comment)

@sebhildebrandt
Copy link
Owner

@caub thank you for your comment! Will think how this can improve the library. Generally I want to keep dependencies very low ... and as sockets work fine so far, I will think of how I can/should use http module ... closing it for now.

@caub
Copy link
Author

caub commented Dec 3, 2018

@sebhildebrandt Thanks, fair enough

One quick question, could you comment on how cpuPercent is calculated in your lib, and below:

const dockerStats = async containerId => {
  const { name, cpu_stats, precpu_stats, memory_stats } = await fetch(`http://v1.39/containers/${containerId}/stats?stream=false`, { socketPath: '/var/run/docker.sock' });
  const cpuPercent = (cpu_stats.cpu_usage.total_usage - precpu_stats.cpu_usage.total_usage) / (cpu_stats.system_cpu_usage - precpu_stats.system_cpu_usage) * cpu_stats.cpu_usage.percpu_usage.length * 100;
  return {id, name, cpuPercent, memPercent: memory_stats.usage * 100 / memory_stats.limit};
}

Is this the percentage of increase of CPU? (if precpu_stats stands for previouscpu_stats). I doubt since it's constantly positive while the process is stable
What does it measure so?

@sebhildebrandt
Copy link
Owner

So this is a longer story. First: yes, the calculation is based on previous stats. I actually did this wrong but then I based my calculation on the way how docker does it in his own code for calculating stats (actually to get in sync with docker stats). Took me some while to get there, but now I think this should be correct. In cpu_stats.cpu_usage.total_usage, ... there are no percent values so the result must be always positive. Any doubts?

@caub
Copy link
Author

caub commented Dec 3, 2018

Thanks, it looks weird, but yea, good idea I'll look at docker CLI source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants