mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 01:39:34 +08:00
fix agent losing track of container after restart
This commit is contained in:
@@ -178,14 +178,21 @@ func getDockerStats() ([]*ContainerStats, error) {
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
for _, ctr := range containers {
|
for _, ctr := range containers {
|
||||||
ctr.IdShort = ctr.ID[:12]
|
ctr.IdShort = ctr.Id[:12]
|
||||||
validIds[ctr.IdShort] = struct{}{}
|
validIds[ctr.IdShort] = struct{}{}
|
||||||
|
// check if container is less than 1 minute old (possible restart)
|
||||||
|
// note: can't use Created field because it's not updated on restart
|
||||||
|
if strings.HasSuffix(ctr.Status, "seconds") {
|
||||||
|
// if so, remove old container data
|
||||||
|
delete(containerCpuMap, ctr.IdShort)
|
||||||
|
}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
cstats, err := getContainerStats(ctr)
|
cstats, err := getContainerStats(ctr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// retry once
|
// delete container from map and retry once
|
||||||
|
delete(containerCpuMap, ctr.IdShort)
|
||||||
cstats, err = getContainerStats(ctr)
|
cstats, err = getContainerStats(ctr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error getting container stats: %+v\n", err)
|
log.Printf("Error getting container stats: %+v\n", err)
|
||||||
|
@@ -42,23 +42,23 @@ type ContainerStats struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Container struct {
|
type Container struct {
|
||||||
ID string `json:"Id"`
|
Id string
|
||||||
IdShort string
|
IdShort string
|
||||||
Names []string
|
Names []string
|
||||||
Image string
|
Status string
|
||||||
ImageID string
|
// Image string
|
||||||
Command string
|
// ImageID string
|
||||||
Created int64
|
// Command string
|
||||||
|
// Created int64
|
||||||
// Ports []Port
|
// Ports []Port
|
||||||
SizeRw int64 `json:",omitempty"`
|
// SizeRw int64 `json:",omitempty"`
|
||||||
SizeRootFs int64 `json:",omitempty"`
|
// SizeRootFs int64 `json:",omitempty"`
|
||||||
Labels map[string]string
|
// Labels map[string]string
|
||||||
State string
|
// State string
|
||||||
Status string
|
// HostConfig struct {
|
||||||
HostConfig struct {
|
// NetworkMode string `json:",omitempty"`
|
||||||
NetworkMode string `json:",omitempty"`
|
// Annotations map[string]string `json:",omitempty"`
|
||||||
Annotations map[string]string `json:",omitempty"`
|
// }
|
||||||
}
|
|
||||||
// NetworkSettings *SummaryNetworkSettings
|
// NetworkSettings *SummaryNetworkSettings
|
||||||
// Mounts []MountPoint
|
// Mounts []MountPoint
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user