Merge pull request #201 from stirante/health-check

Add health check to container list
This commit is contained in:
Jesse Duffield 2020-09-23 20:15:42 +10:00 committed by GitHub
commit 386334b1f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 13 deletions

View file

@ -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

View file

@ -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 {