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

Question: Getting Container Statistics #113

Closed
rwmajor2 opened this issue Dec 4, 2019 · 2 comments
Closed

Question: Getting Container Statistics #113

rwmajor2 opened this issue Dec 4, 2019 · 2 comments

Comments

@rwmajor2
Copy link

rwmajor2 commented Dec 4, 2019

Hi @dmandalidis. Quick question as you are now my expert on this client SDK. :)

When I call docker.stats(containerId), it returns to me statistics and there is always about a 1-2 second wait time. This is equivalent to what you experience with the Docker CLI. However, with the Docker CLI, I am say docker stats (meaning show stats for all containers) and this experiences the same 1-2 second wait time and then displays all containers and resource consumption.

With this SDK, only stats(containerId) exists. The only way I know how to do this is loop over all the containers I have running and call it on each container. However, in this scenario, I experience the same 1-2 second delay but on each time it gets called. For a Docker environment running many containers (e.g. 50), this takes an excruciatingly long time.

Do you have any suggestions on how to improve this so that it behaves similar to the Docker CLI?

Below is my java code.

 public JSONArray getAllContainerStatsLocal() throws AdminException {

    DockerClient docker;
    try {
      docker = DefaultDockerClient.fromEnv().build();
    } catch (DockerCertificateException e) {
      logger.debug(e.getLocalizedMessage());
      throw new AdminException(TuringAdminLogCode.FAILED_TO_ESTABLISH_DOCKER_ENVIRONMENT.message(), e);
    }

    try {
      JSONArray array = new JSONArray();
      ContainerStats stats = null;
      Container[] cns = getAllContainersLocal(ServerIPUtil.getFQLocalHost());
      for (int i = 0; i < cns.length; i++) {
        stats = docker.stats(cns[i].getContainerId());   //   <--  Slow line
        ContainerStatistics cs = null;
        if (stats != null) {
          cs = createContainerStatisticsObject(stats, cns[i].getId(), cns[i].getContainerId());
          array.put(cs.toJSON());
        }
      }
      return array;
    } catch (Exception e) {
      logger.debug(e);
      throw new AdminException(e);
    } finally {
      if (null != docker) {
        docker.close();
      }
    }
  }
@dmandalidis
Copy link
Owner

Hi @rwmajor2 ,

Unfortunately the plain docker stats (without a container) is a docker cli enhancement. This project acts as a Java binding over the REST API instead which doesn't have such an endpoint. Adding such features from other REST implementations will probably lead to confusion and maintenance chaos. Sorry :)

@rwmajor2
Copy link
Author

rwmajor2 commented Dec 4, 2019

@dmandalidis Thanks for the feedback.

@rwmajor2 rwmajor2 closed this as completed Dec 4, 2019
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