Squashed commit of the following:
commit 9968c504a585e0c340555f78699d5f582c843caa Author: Florian Vahl <florian@flova.de> Date: Tue Feb 1 00:37:31 2022 +0100 Fix formating (Spaces -> Tabs) commit 6b8840647e4da6dd8e273353c44bf42cb58c7f7c Author: Florian <florian@flova.de> Date: Tue Feb 1 00:27:44 2022 +0100 Use better duration formating commit 815dc6ec840c268b29e0f2075c4bbf78b18ac1dd Author: Florian <florian@flova.de> Date: Tue Feb 1 00:27:04 2022 +0100 Fix date formating in 'created' col commit 05b17798f899048877730b21b5109510ed344aa4 Author: Florian <florian@flova.de> Date: Tue Feb 1 00:26:08 2022 +0100 Add fix from #275 for uptime of running containers
This commit is contained in:
+4
-3
@@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/op/go-logging"
|
||||
"github.com/hako/durafmt"
|
||||
|
||||
"github.com/bcicen/ctop/connector/collector"
|
||||
"github.com/bcicen/ctop/connector/manager"
|
||||
@@ -187,7 +188,7 @@ func (cm *Docker) refresh(c *container.Container) {
|
||||
if webPort != "" {
|
||||
c.SetMeta("Web Port", webPort)
|
||||
}
|
||||
c.SetMeta("created", insp.Created.Format("Mon Jan 2 15:04:05 2006"))
|
||||
c.SetMeta("created", insp.Created.Format("Mon Jan 02 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, ";"))
|
||||
@@ -209,11 +210,11 @@ func (cm *Docker) inspect(id string) (insp *api.Container, found bool, failed bo
|
||||
|
||||
func calcUptime(insp *api.Container) string {
|
||||
endTime := insp.State.FinishedAt
|
||||
if endTime.IsZero() {
|
||||
if endTime.IsZero() || insp.State.Running {
|
||||
endTime = time.Now()
|
||||
}
|
||||
uptime := endTime.Sub(insp.State.StartedAt)
|
||||
return uptime.Truncate(time.Second).String()
|
||||
return durafmt.Parse(uptime).LimitFirstN(1).String()
|
||||
}
|
||||
|
||||
// Mark all container IDs for refresh
|
||||
|
||||
Reference in New Issue
Block a user