Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Statistics Objects always return null despite change in container stats #2383

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

Open
DeshyDan opened this issue Mar 3, 2025 · 0 comments
Open

Comments

@DeshyDan
Copy link

DeshyDan commented Mar 3, 2025

Description

When calling getContainerStats(String containerId), the Statistics object returned is null, even though the logs show a value. Specifically, when calling cpuUsage.getTotalUsage(), the function returns null, but the log output suggests that a value is present.

Code Sample

Here is the code used to retrieve container stats:

public Statistics getContainerStats(String containerId) {  
    InvocationBuilder.AsyncResultCallback<Statistics> callback = new InvocationBuilder.AsyncResultCallback<>();  
    dockerClient.statsCmd(containerId).exec(callback);  
    Statistics stats;  
    try {  
        stats = callback.awaitResult();  
        callback.close();  
    } catch (IOException e) {  
        log.error("Failed to get container stats: {}", containerId, e);  
        throw new RuntimeException("Failed to get container stats", e);  
    }  
    return stats;  
}

To fetch CPU usage:

private long getTotalCpuUsage(CpuStatsConfig cpuStats) {  
    CpuUsageConfig cpuUsage = cpuStats.getCpuUsage();  
    log.info("Total CPU usage: {}", cpuUsage.getTotalUsage());  
    return cpuUsage.getTotalUsage();  
}

Observed Behavior

  • The cpuUsage.getTotalUsage() method always returns null.
  • However, the log statement log.info("Total CPU usage: {}", cpuUsage.getTotalUsage()); correctly displays a value.

Expected Behavior

  • cpuUsage.getTotalUsage() should return the same value as seen in the logs.
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

1 participant