0

I am trying to obtain the amount of cpu (measured in time or percentage, any one) utilized by a specific container deployed using docker as:

docker run <container_name>

or using lxc as:

lxc-start -n <container_name>

I see that the container deployed using lxc has cpu usage statistics stored in /sys/fs/cgroup/cpuacct/cpuacct.stat

However, I want to obtain these stats using the java API that can be obtained from here:

https://github.com/docker-java/docker-java

I see that the API provides methods to start, stop containers, image information, etc. However, I don't see a way that can provide container statistics such as cpu, memory and other resource usage statistics. From this question I see that this should have been present in API 1.0.

How do I get the cpu, memory, network and other resource usage statistics from the java API?

I would also very much appreciate an online blog or tutorial that can provide more insights into this too.


Specifications:

Docker:

Client version: 1.1.2
Client API version: 1.13
Go version (client): go1.2.1
Git commit (client): d84a070
Server version: 1.1.2
Server API version: 1.13
Go version (server): go1.2.1
Git commit (server): d84a070

Host OS:

  • Ubuntu 14.04 Trusty Tahr LTS
  • Java 1.7
Community
  • 1
  • 1
jobin
  • 2,600
  • 7
  • 32
  • 59
  • To get memory and CPU usage in Java code, see my answer here [https://stackoverflow.com/questions/45230004/how-to-get-docker-stats-detail-in-java-code/57986518#57986518](https://stackoverflow.com/questions/45230004/how-to-get-docker-stats-detail-in-java-code/57986518#57986518) – Mithilesh Tipkari Sep 18 '19 at 06:47

2 Answers2

1

If you are still interested, the latest version of cadvisor (github.com/google/cadvisor) added support for networking, filesystem, and many other stats. Give it another try.

Rohit Jnagal
  • 1,182
  • 9
  • 8
0

You can use this API to monitor cpu and memory usage : https://github.com/google/cadvisor

Regan
  • 8,231
  • 5
  • 23
  • 23
  • Is the docker java API itself not capable of doing this? And I would like to see an extensible Java API. – jobin Aug 20 '14 at 13:46
  • The docker api doesn't include easy way to monitor performance. But they still stock those information, see http://blog.docker.com/2013/10/gathering-lxc-docker-containers-metrics/ for more information. You can then write a small java library that would exploit those information. – Regan Aug 20 '14 at 14:04