mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
Merge remote-tracking branch 'remotes/stokito/uptime'
This commit is contained in:
@ -2,9 +2,11 @@ package connector
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/op/go-logging"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/op/go-logging"
|
||||
|
||||
"github.com/bcicen/ctop/connector/collector"
|
||||
"github.com/bcicen/ctop/connector/manager"
|
||||
@ -174,6 +176,7 @@ func (cm *Docker) refresh(c *container.Container) {
|
||||
c.SetMeta("IPs", ipsFormat(insp.NetworkSettings.Networks))
|
||||
c.SetMeta("ports", portsFormat(insp.NetworkSettings.Ports))
|
||||
c.SetMeta("created", insp.Created.Format("Mon Jan 2 15:04:05 2006"))
|
||||
c.SetMeta("uptime", calcUptime(insp))
|
||||
c.SetMeta("health", insp.State.Health.Status)
|
||||
c.SetMeta("[ENV-VAR]", strings.Join(insp.Config.Env, ";"))
|
||||
c.SetState(insp.State.Status)
|
||||
@ -192,6 +195,15 @@ func (cm *Docker) inspect(id string) (insp *api.Container, found bool, failed bo
|
||||
return c, true, false
|
||||
}
|
||||
|
||||
func calcUptime(insp *api.Container) string {
|
||||
endTime := insp.State.FinishedAt
|
||||
if endTime.IsZero() {
|
||||
endTime = time.Now()
|
||||
}
|
||||
uptime := endTime.Sub(insp.State.StartedAt)
|
||||
return uptime.Truncate(time.Second).String()
|
||||
}
|
||||
|
||||
// Mark all container IDs for refresh
|
||||
func (cm *Docker) refreshAll() {
|
||||
opts := api.ListContainersOptions{All: true}
|
||||
|
Reference in New Issue
Block a user