mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
add container state checks, set status icon based on state string
This commit is contained in:
@@ -7,6 +7,9 @@ import (
|
||||
// Docker collector
|
||||
type Docker struct {
|
||||
Metrics
|
||||
id string
|
||||
client *api.Client
|
||||
running bool
|
||||
stream chan Metrics
|
||||
done chan bool
|
||||
lastCpu float64
|
||||
@@ -14,22 +17,27 @@ type Docker struct {
|
||||
}
|
||||
|
||||
func NewDocker(client *api.Client, id string) *Docker {
|
||||
c := &Docker{
|
||||
return &Docker{
|
||||
Metrics: Metrics{},
|
||||
id: id,
|
||||
client: client,
|
||||
stream: make(chan Metrics),
|
||||
done: make(chan bool),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Docker) Start() {
|
||||
stats := make(chan *api.Stats)
|
||||
|
||||
go func() {
|
||||
opts := api.StatsOptions{
|
||||
ID: id,
|
||||
ID: c.id,
|
||||
Stats: stats,
|
||||
Stream: true,
|
||||
Done: c.done,
|
||||
}
|
||||
client.Stats(opts)
|
||||
c.client.Stats(opts)
|
||||
c.running = false
|
||||
}()
|
||||
|
||||
go func() {
|
||||
@@ -42,7 +50,11 @@ func NewDocker(client *api.Client, id string) *Docker {
|
||||
}
|
||||
}()
|
||||
|
||||
return c
|
||||
c.running = true
|
||||
}
|
||||
|
||||
func (c *Docker) Running() bool {
|
||||
return c.running
|
||||
}
|
||||
|
||||
func (c *Docker) Stream() chan Metrics {
|
||||
|
||||
Reference in New Issue
Block a user