Merge pull request #712 from sagor999/limit-colors

color cpu and memory limit fields in different color if close to threshold
mine
Fernand Galiana 2020-07-02 12:30:57 -06:00 committed by GitHub
commit b42a67c875
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 0 deletions

View File

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

View File

@ -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 + "::b]" + re.Row.Fields[colIndex]
}
}
}
return data
}

View File

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