From 3e4b3cbbf579316c607cff4447bd13c488b9b661 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Thu, 27 Jul 2017 13:15:53 +0000 Subject: [PATCH] Add pod restart count to details pane --- probe/kubernetes/pod.go | 13 +++++++++++++ probe/kubernetes/reporter.go | 1 + 2 files changed, 14 insertions(+) diff --git a/probe/kubernetes/pod.go b/probe/kubernetes/pod.go index ecba038bd..2614a14f0 100644 --- a/probe/kubernetes/pod.go +++ b/probe/kubernetes/pod.go @@ -1,6 +1,8 @@ package kubernetes import ( + "strconv" + "github.com/weaveworks/scope/report" apiv1 "k8s.io/client-go/pkg/api/v1" @@ -10,6 +12,7 @@ import ( const ( State = "kubernetes_state" IsInHostNetwork = "kubernetes_is_in_host_network" + RestartCount = "kubernetes_restart_count" StateDeleted = "deleted" ) @@ -20,6 +23,7 @@ type Pod interface { AddParent(topology, id string) NodeName() string GetNode(probeID string) report.Node + RestartCount() uint } type pod struct { @@ -58,11 +62,20 @@ func (p *pod) NodeName() string { return p.Spec.NodeName } +func (p *pod) RestartCount() uint { + count := uint(0) + for _, cs := range p.Status.ContainerStatuses { + count += uint(cs.RestartCount) + } + return count +} + func (p *pod) GetNode(probeID string) report.Node { latests := map[string]string{ State: p.State(), IP: p.Status.PodIP, report.ControlProbeID: probeID, + RestartCount: strconv.FormatUint(uint64(p.RestartCount()), 10), } if p.Pod.Spec.HostNetwork { diff --git a/probe/kubernetes/reporter.go b/probe/kubernetes/reporter.go index 369dc1038..519c5ba11 100644 --- a/probe/kubernetes/reporter.go +++ b/probe/kubernetes/reporter.go @@ -32,6 +32,7 @@ var ( report.Container: {ID: report.Container, Label: "# Containers", From: report.FromCounters, Datatype: "number", Priority: 4}, Namespace: {ID: Namespace, Label: "Namespace", From: report.FromLatest, Priority: 5}, Created: {ID: Created, Label: "Created", From: report.FromLatest, Datatype: "datetime", Priority: 6}, + RestartCount: {ID: RestartCount, Label: "Restart #", From: report.FromLatest, Priority: 7}, } PodMetricTemplates = docker.ContainerMetricTemplates