Merge pull request #489 from binarycoded/resource_limits
Show resource limit % next to request % in Pod view (fix #413)mine
commit
995158d446
|
|
@ -31,11 +31,11 @@ func asSelector(s *metav1.LabelSelector) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
type metric struct {
|
type metric struct {
|
||||||
cpu, mem string
|
cpu, mem, cpuLim, memLim string
|
||||||
}
|
}
|
||||||
|
|
||||||
func noMetric() metric {
|
func noMetric() metric {
|
||||||
return metric{cpu: NAValue, mem: NAValue}
|
return metric{cpu: NAValue, mem: NAValue, cpuLim: NAValue, memLim: NAValue}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToSelector flattens a map selector to a string selector.
|
// ToSelector flattens a map selector to a string selector.
|
||||||
|
|
|
||||||
|
|
@ -78,8 +78,8 @@ func (Pod) Header(ns string) HeaderRow {
|
||||||
Header{Name: "RESTART", Align: tview.AlignRight},
|
Header{Name: "RESTART", Align: tview.AlignRight},
|
||||||
Header{Name: "CPU", Align: tview.AlignRight},
|
Header{Name: "CPU", Align: tview.AlignRight},
|
||||||
Header{Name: "MEM", Align: tview.AlignRight},
|
Header{Name: "MEM", Align: tview.AlignRight},
|
||||||
Header{Name: "%CPU", Align: tview.AlignRight},
|
Header{Name: "%CPU (LIM)", Align: tview.AlignRight},
|
||||||
Header{Name: "%MEM", Align: tview.AlignRight},
|
Header{Name: "%MEM (LIM)", Align: tview.AlignRight},
|
||||||
Header{Name: "IP"},
|
Header{Name: "IP"},
|
||||||
Header{Name: "NODE"},
|
Header{Name: "NODE"},
|
||||||
Header{Name: "QOS"},
|
Header{Name: "QOS"},
|
||||||
|
|
@ -116,8 +116,8 @@ func (p Pod) Render(o interface{}, ns string, r *Row) error {
|
||||||
strconv.Itoa(rc),
|
strconv.Itoa(rc),
|
||||||
c.cpu,
|
c.cpu,
|
||||||
c.mem,
|
c.mem,
|
||||||
perc.cpu,
|
perc.cpu+" ("+fmt.Sprintf("%3v",perc.cpuLim)+")",
|
||||||
perc.mem,
|
perc.mem+" ("+fmt.Sprintf("%3v",perc.memLim)+")",
|
||||||
na(po.Status.PodIP),
|
na(po.Status.PodIP),
|
||||||
na(po.Spec.NodeName),
|
na(po.Spec.NodeName),
|
||||||
p.mapQOS(po.Status.QOSClass),
|
p.mapQOS(po.Status.QOSClass),
|
||||||
|
|
@ -159,9 +159,12 @@ func (*Pod) gatherPodMX(pod *v1.Pod, mx *mv1beta1.PodMetrics) (c, p metric) {
|
||||||
}
|
}
|
||||||
|
|
||||||
rc, rm := requestedRes(pod)
|
rc, rm := requestedRes(pod)
|
||||||
|
lc, lm := resourceLimits(pod)
|
||||||
p = metric{
|
p = metric{
|
||||||
cpu: AsPerc(toPerc(float64(cpu.MilliValue()), float64(rc.MilliValue()))),
|
cpu: AsPerc(toPerc(float64(cpu.MilliValue()), float64(rc.MilliValue()))),
|
||||||
mem: AsPerc(toPerc(ToMB(mem.Value()), ToMB(rm.Value()))),
|
mem: AsPerc(toPerc(ToMB(mem.Value()), ToMB(rm.Value()))),
|
||||||
|
cpuLim: AsPerc(toPerc(float64(cpu.MilliValue()), float64(lc.MilliValue()))),
|
||||||
|
memLim: AsPerc(toPerc(ToMB(mem.Value()), ToMB(lm.Value()))),
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
@ -180,6 +183,21 @@ func containerResources(co v1.Container) (cpu, mem *resource.Quantity) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resourceLimits(po *v1.Pod) (cpu, mem resource.Quantity) {
|
||||||
|
for _, co := range po.Spec.Containers {
|
||||||
|
limit := co.Resources.Limits
|
||||||
|
if len(limit) != 0 {
|
||||||
|
if limit.Cpu() != nil {
|
||||||
|
cpu.Add(*limit.Cpu())
|
||||||
|
}
|
||||||
|
if limit.Memory() != nil {
|
||||||
|
mem.Add(*limit.Memory())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func requestedRes(po *v1.Pod) (cpu, mem resource.Quantity) {
|
func requestedRes(po *v1.Pod) (cpu, mem resource.Quantity) {
|
||||||
for _, co := range po.Spec.Containers {
|
for _, co := range po.Spec.Containers {
|
||||||
c, m := containerResources(co)
|
c, m := containerResources(co)
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ func TestPodRender(t *testing.T) {
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "default/nginx", r.ID)
|
assert.Equal(t, "default/nginx", r.ID)
|
||||||
e := render.Fields{"default", "nginx", "1/1", "Running", "0", "10", "10", "10", "14", "172.17.0.6", "minikube", "BE"}
|
e := render.Fields{"default", "nginx", "1/1", "Running", "0", "10", "10", "10 ( 0)", "14 ( 5)", "172.17.0.6", "minikube", "BE"}
|
||||||
assert.Equal(t, e, r.Fields[:12])
|
assert.Equal(t, e, r.Fields[:12])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,7 +101,7 @@ func TestPodInitRender(t *testing.T) {
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "default/nginx", r.ID)
|
assert.Equal(t, "default/nginx", r.ID)
|
||||||
e := render.Fields{"default", "nginx", "1/1", "Init:0/1", "0", "10", "10", "10", "14", "172.17.0.6", "minikube", "BE"}
|
e := render.Fields{"default", "nginx", "1/1", "Init:0/1", "0", "10", "10", "10 ( 0)", "14 ( 5)", "172.17.0.6", "minikube", "BE"}
|
||||||
assert.Equal(t, e, r.Fields[:12])
|
assert.Equal(t, e, r.Fields[:12])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue