diff --git a/internal/view/container.go b/internal/view/container.go index 2f2993cb..28178723 100644 --- a/internal/view/container.go +++ b/internal/view/container.go @@ -27,11 +27,16 @@ func NewContainer(gvr client.GVR) ResourceViewer { c.SetEnvFn(c.k9sEnv) c.GetTable().SetEnterFn(c.viewLogs) c.GetTable().SetColorerFn(render.Container{}.ColorerFunc()) + c.GetTable().SetDecorateFn(c.decorateRows) c.SetBindKeysFn(c.bindKeys) return &c } +func (c *Container) decorateRows(data render.TableData) render.TableData { + return decorateCpuMemHeaderRows(c.App(), data) +} + // Name returns the component name. func (c *Container) Name() string { return containerTitle } diff --git a/internal/view/helpers.go b/internal/view/helpers.go index 2ec5223c..96522367 100644 --- a/internal/view/helpers.go +++ b/internal/view/helpers.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "strconv" "strings" "github.com/derailed/k9s/internal" @@ -177,3 +178,40 @@ func fqn(ns, n string) string { } return ns + "/" + n } + +func decorateCpuMemHeaderRows(app *App, data render.TableData) render.TableData { + for colIndex, header := range data.Header { + check := "" + if header.Name == "%CPU/L" { + check = "cpu" + } + if header.Name == "%MEM/L" { + check = "memory" + } + if len(check) == 0 { + continue + } + for _, re := range data.RowEvents { + if re.Row.Fields[colIndex] == render.NAValue { + continue + } + n, err := strconv.Atoi(re.Row.Fields[colIndex]) + if err != nil { + continue + } + if n > 100 { + n = 100 + } + severity := app.Config.K9s.Thresholds.LevelFor(check, n) + if severity == config.SeverityLow { + continue + } + color := app.Config.K9s.Thresholds.SeverityColor(check, n) + if len(color) > 0 { + re.Row.Fields[colIndex] = "[" + color + "]" + re.Row.Fields[colIndex] + } + } + } + + return data +} diff --git a/internal/view/pod.go b/internal/view/pod.go index 90aa4cb4..b0cf1ae0 100644 --- a/internal/view/pod.go +++ b/internal/view/pod.go @@ -34,10 +34,15 @@ func NewPod(gvr client.GVR) ResourceViewer { p.SetBindKeysFn(p.bindKeys) p.GetTable().SetEnterFn(p.showContainers) p.GetTable().SetColorerFn(render.Pod{}.ColorerFunc()) + p.GetTable().SetDecorateFn(p.decorateRows) return &p } +func (p *Pod) decorateRows(data render.TableData) render.TableData { + return decorateCpuMemHeaderRows(p.App(), data) +} + func (p *Pod) bindDangerousKeys(aa ui.KeyActions) { aa.Add(ui.KeyActions{ tcell.KeyCtrlK: ui.NewKeyAction("Kill", p.killCmd, true),