Merge pull request #712 from sagor999/limit-colors
color cpu and memory limit fields in different color if close to thresholdmine
commit
b42a67c875
|
|
@ -27,11 +27,16 @@ func NewContainer(gvr client.GVR) ResourceViewer {
|
||||||
c.SetEnvFn(c.k9sEnv)
|
c.SetEnvFn(c.k9sEnv)
|
||||||
c.GetTable().SetEnterFn(c.viewLogs)
|
c.GetTable().SetEnterFn(c.viewLogs)
|
||||||
c.GetTable().SetColorerFn(render.Container{}.ColorerFunc())
|
c.GetTable().SetColorerFn(render.Container{}.ColorerFunc())
|
||||||
|
c.GetTable().SetDecorateFn(c.decorateRows)
|
||||||
c.SetBindKeysFn(c.bindKeys)
|
c.SetBindKeysFn(c.bindKeys)
|
||||||
|
|
||||||
return &c
|
return &c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Container) decorateRows(data render.TableData) render.TableData {
|
||||||
|
return decorateCpuMemHeaderRows(c.App(), data)
|
||||||
|
}
|
||||||
|
|
||||||
// Name returns the component name.
|
// Name returns the component name.
|
||||||
func (c *Container) Name() string { return containerTitle }
|
func (c *Container) Name() string { return containerTitle }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/derailed/k9s/internal"
|
"github.com/derailed/k9s/internal"
|
||||||
|
|
@ -177,3 +178,40 @@ func fqn(ns, n string) string {
|
||||||
}
|
}
|
||||||
return ns + "/" + n
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,15 @@ func NewPod(gvr client.GVR) ResourceViewer {
|
||||||
p.SetBindKeysFn(p.bindKeys)
|
p.SetBindKeysFn(p.bindKeys)
|
||||||
p.GetTable().SetEnterFn(p.showContainers)
|
p.GetTable().SetEnterFn(p.showContainers)
|
||||||
p.GetTable().SetColorerFn(render.Pod{}.ColorerFunc())
|
p.GetTable().SetColorerFn(render.Pod{}.ColorerFunc())
|
||||||
|
p.GetTable().SetDecorateFn(p.decorateRows)
|
||||||
|
|
||||||
return &p
|
return &p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Pod) decorateRows(data render.TableData) render.TableData {
|
||||||
|
return decorateCpuMemHeaderRows(p.App(), data)
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Pod) bindDangerousKeys(aa ui.KeyActions) {
|
func (p *Pod) bindDangerousKeys(aa ui.KeyActions) {
|
||||||
aa.Add(ui.KeyActions{
|
aa.Add(ui.KeyActions{
|
||||||
tcell.KeyCtrlK: ui.NewKeyAction("Kill", p.killCmd, true),
|
tcell.KeyCtrlK: ui.NewKeyAction("Kill", p.killCmd, true),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue