mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
Add health check to container list
This commit is contained in:
parent
69f32d52d1
commit
305b9630a0
2 changed files with 31 additions and 11 deletions
|
|
@ -53,17 +53,18 @@ type Details struct {
|
||||||
Path string `json:"Path"`
|
Path string `json:"Path"`
|
||||||
Args []string `json:"Args"`
|
Args []string `json:"Args"`
|
||||||
State struct {
|
State struct {
|
||||||
Status string `json:"Status"`
|
Status string `json:"Status"`
|
||||||
Running bool `json:"Running"`
|
Running bool `json:"Running"`
|
||||||
Paused bool `json:"Paused"`
|
Paused bool `json:"Paused"`
|
||||||
Restarting bool `json:"Restarting"`
|
Restarting bool `json:"Restarting"`
|
||||||
OOMKilled bool `json:"OOMKilled"`
|
OOMKilled bool `json:"OOMKilled"`
|
||||||
Dead bool `json:"Dead"`
|
Dead bool `json:"Dead"`
|
||||||
Pid int `json:"Pid"`
|
Pid int `json:"Pid"`
|
||||||
ExitCode int `json:"ExitCode"`
|
ExitCode int `json:"ExitCode"`
|
||||||
Error string `json:"Error"`
|
Error string `json:"Error"`
|
||||||
StartedAt time.Time `json:"StartedAt"`
|
StartedAt time.Time `json:"StartedAt"`
|
||||||
FinishedAt time.Time `json:"FinishedAt"`
|
FinishedAt time.Time `json:"FinishedAt"`
|
||||||
|
Health types.Health `json:"Health"`
|
||||||
} `json:"State"`
|
} `json:"State"`
|
||||||
Image string `json:"Image"`
|
Image string `json:"Image"`
|
||||||
ResolvConfPath string `json:"ResolvConfPath"`
|
ResolvConfPath string `json:"ResolvConfPath"`
|
||||||
|
|
@ -259,6 +260,12 @@ func (c *Container) GetDisplayStatus() string {
|
||||||
if c.Container.State == "exited" {
|
if c.Container.State == "exited" {
|
||||||
state += " (" + strconv.Itoa(c.Details.State.ExitCode) + ")"
|
state += " (" + strconv.Itoa(c.Details.State.ExitCode) + ")"
|
||||||
}
|
}
|
||||||
|
if c.Container.State == "running" && c.Details.State.Health.Status != "" {
|
||||||
|
state += " (" + c.Details.State.Health.Status + ")";
|
||||||
|
}
|
||||||
|
if c.Container.State == "running" && c.Details.State.Health.Status == "unhealthy" {
|
||||||
|
return utils.MultiColoredString(state, c.GetColor(), color.BgRed)
|
||||||
|
}
|
||||||
|
|
||||||
return utils.ColoredString(state, c.GetColor())
|
return utils.ColoredString(state, c.GetColor())
|
||||||
}
|
}
|
||||||
|
|
@ -305,6 +312,12 @@ func (c *Container) GetColor() color.Attribute {
|
||||||
case "created":
|
case "created":
|
||||||
return color.FgCyan
|
return color.FgCyan
|
||||||
case "running":
|
case "running":
|
||||||
|
if c.Details.State.Health.Status == "starting" {
|
||||||
|
return color.FgYellow
|
||||||
|
}
|
||||||
|
if c.Details.State.Health.Status == "unhealthy" {
|
||||||
|
return color.FgBlack
|
||||||
|
}
|
||||||
return color.FgGreen
|
return color.FgGreen
|
||||||
case "paused":
|
case "paused":
|
||||||
return color.FgYellow
|
return color.FgYellow
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,13 @@ func ColoredString(str string, colorAttribute color.Attribute) string {
|
||||||
return ColoredStringDirect(str, colour)
|
return ColoredStringDirect(str, colour)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MultiColoredString takes a string and an array of colour attributes and returns a colored
|
||||||
|
// string with those attributes
|
||||||
|
func MultiColoredString(str string, colorAttribute ...color.Attribute) string {
|
||||||
|
colour := color.New(colorAttribute...)
|
||||||
|
return ColoredStringDirect(str, colour)
|
||||||
|
}
|
||||||
|
|
||||||
// ColoredStringDirect used for aggregating a few color attributes rather than
|
// ColoredStringDirect used for aggregating a few color attributes rather than
|
||||||
// just sending a single one
|
// just sending a single one
|
||||||
func ColoredStringDirect(str string, colour *color.Color) string {
|
func ColoredStringDirect(str string, colour *color.Color) string {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue