mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-22 15:11:02 +00:00
Merge pull request #201 from stirante/health-check
Add health check to container list
This commit is contained in:
commit
386334b1f0
2 changed files with 37 additions and 13 deletions
|
|
@ -53,17 +53,18 @@ type Details struct {
|
|||
Path string `json:"Path"`
|
||||
Args []string `json:"Args"`
|
||||
State struct {
|
||||
Status string `json:"Status"`
|
||||
Running bool `json:"Running"`
|
||||
Paused bool `json:"Paused"`
|
||||
Restarting bool `json:"Restarting"`
|
||||
OOMKilled bool `json:"OOMKilled"`
|
||||
Dead bool `json:"Dead"`
|
||||
Pid int `json:"Pid"`
|
||||
ExitCode int `json:"ExitCode"`
|
||||
Error string `json:"Error"`
|
||||
StartedAt time.Time `json:"StartedAt"`
|
||||
FinishedAt time.Time `json:"FinishedAt"`
|
||||
Status string `json:"Status"`
|
||||
Running bool `json:"Running"`
|
||||
Paused bool `json:"Paused"`
|
||||
Restarting bool `json:"Restarting"`
|
||||
OOMKilled bool `json:"OOMKilled"`
|
||||
Dead bool `json:"Dead"`
|
||||
Pid int `json:"Pid"`
|
||||
ExitCode int `json:"ExitCode"`
|
||||
Error string `json:"Error"`
|
||||
StartedAt time.Time `json:"StartedAt"`
|
||||
FinishedAt time.Time `json:"FinishedAt"`
|
||||
Health types.Health `json:"Health"`
|
||||
} `json:"State"`
|
||||
Image string `json:"Image"`
|
||||
ResolvConfPath string `json:"ResolvConfPath"`
|
||||
|
|
@ -257,10 +258,26 @@ func (c *Container) GetDisplayStrings(isFocused bool) []string {
|
|||
func (c *Container) GetDisplayStatus() string {
|
||||
state := c.Container.State
|
||||
if c.Container.State == "exited" {
|
||||
state += " (" + strconv.Itoa(c.Details.State.ExitCode) + ")"
|
||||
return utils.ColoredString(state+" ("+strconv.Itoa(c.Details.State.ExitCode)+")", c.GetColor())
|
||||
}
|
||||
|
||||
return utils.ColoredString(state, c.GetColor())
|
||||
return utils.ColoredString(state, c.GetColor()) + c.healthStatusString()
|
||||
}
|
||||
|
||||
func (c *Container) healthStatusString() string {
|
||||
healthStatusColorMap := map[string]color.Attribute{
|
||||
"healthy": color.FgGreen,
|
||||
"unhealthy": color.FgRed,
|
||||
"starting": color.FgYellow,
|
||||
}
|
||||
if c.Container.State != "running" {
|
||||
return ""
|
||||
}
|
||||
healthStatus := c.Details.State.Health.Status
|
||||
if healthStatusColor, ok := healthStatusColorMap[healthStatus]; ok {
|
||||
return utils.ColoredString(" ("+healthStatus+")", healthStatusColor)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetDisplayCPUPerc colors the cpu percentage based on how extreme it is
|
||||
|
|
|
|||
|
|
@ -52,6 +52,13 @@ func ColoredString(str string, colorAttribute color.Attribute) string {
|
|||
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
|
||||
// just sending a single one
|
||||
func ColoredStringDirect(str string, colour *color.Color) string {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue