mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 01:39:34 +08:00
make sure deletion of container stats is thread safe
This commit is contained in:
@@ -175,7 +175,7 @@ func getDockerStats() ([]*ContainerStats, error) {
|
||||
// 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(containerStatsMap, ctr.IdShort)
|
||||
deleteContainerStatsSync(ctr.IdShort)
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
@@ -183,7 +183,7 @@ func getDockerStats() ([]*ContainerStats, error) {
|
||||
cstats, err := getContainerStats(ctr)
|
||||
if err != nil {
|
||||
// delete container from map and retry once
|
||||
delete(containerStatsMap, ctr.IdShort)
|
||||
deleteContainerStatsSync(ctr.IdShort)
|
||||
cstats, err = getContainerStats(ctr)
|
||||
if err != nil {
|
||||
log.Printf("Error getting container stats: %+v\n", err)
|
||||
@@ -277,6 +277,13 @@ func getContainerStats(ctr *Container) (*ContainerStats, error) {
|
||||
return cStats, nil
|
||||
}
|
||||
|
||||
// delete container stats from map using mutex
|
||||
func deleteContainerStatsSync(id string) {
|
||||
containerStatsMutex.Lock()
|
||||
defer containerStatsMutex.Unlock()
|
||||
delete(containerStatsMap, id)
|
||||
}
|
||||
|
||||
func gatherStats() *SystemData {
|
||||
systemInfo, systemStats := getSystemStats()
|
||||
stats := &SystemData{
|
||||
|
Reference in New Issue
Block a user