mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-07-14 10:17:26 +08:00
Omit race conditions and update swarm info events
This commit is contained in:
parent
84da622775
commit
a7811b4e33
@ -1,12 +1,12 @@
|
|||||||
version: '2'
|
version: '2'
|
||||||
services:
|
services:
|
||||||
web:
|
pwd:
|
||||||
# pwd daemon container always needs to be named this way
|
# pwd daemon container always needs to be named this way
|
||||||
container_name: pwd
|
container_name: pwd
|
||||||
# use the latest golang image
|
# use the latest golang image
|
||||||
image: golang
|
image: golang
|
||||||
# go to the right place and starts the app
|
# go to the right place and starts the app
|
||||||
command: /bin/sh -c 'cd /go/src/github.com/franela/play-with-docker; go run api.go'
|
command: /bin/sh -c 'cd /go/src/github.com/franela/play-with-docker; go run -race api.go'
|
||||||
ports:
|
ports:
|
||||||
# app exposes port 3000
|
# app exposes port 3000
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
|
@ -9,6 +9,8 @@ func (c checkSwarmStatusTask) Run(i *Instance) {
|
|||||||
if info, err := GetDaemonInfo(i); err == nil {
|
if info, err := GetDaemonInfo(i); err == nil {
|
||||||
if info.Swarm.LocalNodeState != swarm.LocalNodeStateInactive && info.Swarm.LocalNodeState != swarm.LocalNodeStateLocked {
|
if info.Swarm.LocalNodeState != swarm.LocalNodeStateInactive && info.Swarm.LocalNodeState != swarm.LocalNodeStateLocked {
|
||||||
i.IsManager = &info.Swarm.ControlAvailable
|
i.IsManager = &info.Swarm.ControlAvailable
|
||||||
|
} else {
|
||||||
|
i.IsManager = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ type collectStatsTask struct {
|
|||||||
mem float64
|
mem float64
|
||||||
memLimit float64
|
memLimit float64
|
||||||
memPercent float64
|
memPercent float64
|
||||||
v *types.StatsJSON
|
|
||||||
|
|
||||||
cpuPercent float64
|
cpuPercent float64
|
||||||
previousCPU uint64
|
previousCPU uint64
|
||||||
@ -27,24 +26,25 @@ func (c collectStatsTask) Run(i *Instance) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
dec := json.NewDecoder(reader)
|
dec := json.NewDecoder(reader)
|
||||||
e := dec.Decode(&c.v)
|
var v *types.StatsJSON
|
||||||
|
e := dec.Decode(&v)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
log.Println("Error while trying to collect instance stats", e)
|
log.Println("Error while trying to collect instance stats", e)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Memory
|
// Memory
|
||||||
if c.v.MemoryStats.Limit != 0 {
|
if v.MemoryStats.Limit != 0 {
|
||||||
c.memPercent = float64(c.v.MemoryStats.Usage) / float64(c.v.MemoryStats.Limit) * 100.0
|
c.memPercent = float64(v.MemoryStats.Usage) / float64(v.MemoryStats.Limit) * 100.0
|
||||||
}
|
}
|
||||||
c.mem = float64(c.v.MemoryStats.Usage)
|
c.mem = float64(v.MemoryStats.Usage)
|
||||||
c.memLimit = float64(c.v.MemoryStats.Limit)
|
c.memLimit = float64(v.MemoryStats.Limit)
|
||||||
|
|
||||||
i.Mem = fmt.Sprintf("%.2f%% (%s / %s)", c.memPercent, units.BytesSize(c.mem), units.BytesSize(c.memLimit))
|
i.Mem = fmt.Sprintf("%.2f%% (%s / %s)", c.memPercent, units.BytesSize(c.mem), units.BytesSize(c.memLimit))
|
||||||
|
|
||||||
// cpu
|
// cpu
|
||||||
c.previousCPU = c.v.PreCPUStats.CPUUsage.TotalUsage
|
c.previousCPU = v.PreCPUStats.CPUUsage.TotalUsage
|
||||||
c.previousSystem = c.v.PreCPUStats.SystemUsage
|
c.previousSystem = v.PreCPUStats.SystemUsage
|
||||||
c.cpuPercent = calculateCPUPercentUnix(c.previousCPU, c.previousSystem, c.v)
|
c.cpuPercent = calculateCPUPercentUnix(c.previousCPU, c.previousSystem, v)
|
||||||
i.Cpu = fmt.Sprintf("%.2f%%", c.cpuPercent)
|
i.Cpu = fmt.Sprintf("%.2f%%", c.cpuPercent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,8 @@ func (s *Session) SchedulePeriodicTasks() {
|
|||||||
for range s.ticker.C {
|
for range s.ticker.C {
|
||||||
var wg = sync.WaitGroup{}
|
var wg = sync.WaitGroup{}
|
||||||
wg.Add(len(s.Instances))
|
wg.Add(len(s.Instances))
|
||||||
for _, i := range s.Instances {
|
for _, ins := range s.Instances {
|
||||||
|
var i *Instance = ins
|
||||||
if i.dockerClient == nil {
|
if i.dockerClient == nil {
|
||||||
// Need to create client to the DinD docker daemon
|
// Need to create client to the DinD docker daemon
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user