-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Container uptime can differ from docker ps statistics #1607
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
Comments
We generally try not to rely on docker's APIs. What event happened 19 hours ago? Did cAdvisor restart? |
I cannot find any events at that time that might have caused the issue. The same thing happened a few times more but cAdvisor did not restart ( |
+1 I have the same issue. |
Any update on this, I have plenty of invalid container restart alerts which makes me crazy... |
Any update on this? We have meet some problems described in #1704 in 0.26.2 and fall back to 0.25.0, then meet this problem. Aha, still receive some restart emails per day. Hope it can be resolved in the near future. The docker ps
|
I dont have bandwidth to look at this right now. If someone has time to dig into this, that would be greatly appreciated. |
Looks like the problem comes from taking the container creation time from cgroups properties. Here is the part from container/common/helpers.go responsible for this: // Assume unified hierarchy containers.
// Get the lowest creation time from all hierarchies as the container creation time.
now := time.Now()
lowestTime := now
for _, cgroupPath := range cgroupPaths {
// The modified time of the cgroup directory changes whenever a subcontainer is created.
// eg. /docker will have creation time matching the creation of latest docker container.
// Use clone_children as a workaround as it isn't usually modified. It is only likely changed
// immediately after creating a container.
cgroupPath = path.Join(cgroupPath, "cgroup.clone_children")
fi, err := os.Stat(cgroupPath)
if err == nil && fi.ModTime().Before(lowestTime) {
lowestTime = fi.ModTime()
}
}
if lowestTime != now {
spec.CreationTime = lowestTime
} |
fix #1607; use container creation time provided by Docker handler
Cherrypick: fix #1607; use container creation time provided by Docker handler
Also having this issue. Weirdly enough I so far only have it on a single host though. Not sure why |
It turns out cgroup files are not actual files. If the dentry caches are cleared, the next time the file is touched it has a new modification time. I believe this can occur when running low on memory. I havent found a good way to reliably get the start time of a cgroup. We use the start time for docker containers that docker gives us, so that shouldn't be a problem. but for other cgroups and runtimes it may be an issue. |
When I use the
container_start_time_seconds
metric to substract it from the current time, I expect this to be equal to the container uptime as can be obtained from runningdocker ps
.However, I've noticed that this is not the case. When I create (for example) the following alert:
(time() - container_start_time_seconds{image!="",id=~"^/docker.*",name="mongodb"} ) < 60
I receive alert from time to time that my container restarted. When I look at the output of
docker ps
, I see that the container did not crash or restart at all.For example, the current output of
docker ps
:And the current value of

time() - container_start_time_seconds
for these containers:I'm using:
cAdvisor version v0.24.1
Docker version 1.12.1 (build 23cf638)
Docker-compose version 1.8.0 (build f3628c7)
I wonder if this is a known bug, or if it might be possible to use and include the container uptime information from the docker stats, e.g. the same information as shown by from
sudo docker inspect --format='{{.State.StartedAt}}' cadvisor
The text was updated successfully, but these errors were encountered: