Open
Description
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 returnsnull
. - 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.
Metadata
Metadata
Assignees
Labels
No labels