Show more information in describe node/pod

This commit is contained in:
Janet Kuo 2015-08-13 17:28:01 -07:00
parent ae7b13d40e
commit 6e76f1aef7

View File

@ -460,6 +460,9 @@ func describePod(pod *api.Pod, rcs []api.ReplicationController, events *api.Even
fmt.Fprintf(out, "Namespace:\t%s\n", pod.Namespace)
fmt.Fprintf(out, "Image(s):\t%s\n", makeImageList(&pod.Spec))
fmt.Fprintf(out, "Node:\t%s\n", pod.Spec.NodeName+"/"+pod.Status.HostIP)
if pod.Status.StartTime != nil {
fmt.Fprintf(out, "Start Time:\t%s\n", pod.Status.StartTime.Time.Format(time.RFC1123Z))
}
fmt.Fprintf(out, "Labels:\t%s\n", labels.FormatLabels(pod.Labels))
if pod.DeletionTimestamp != nil {
fmt.Fprintf(out, "Status:\tTerminating (expires %s)\n", pod.DeletionTimestamp.Time.Format(time.RFC1123Z))
@ -707,7 +710,9 @@ func describeContainers(pod *api.Pod, out io.Writer) {
state := status.State
fmt.Fprintf(out, " %v:\n", container.Name)
fmt.Fprintf(out, " Container ID:\t%s\n", status.ContainerID)
fmt.Fprintf(out, " Image:\t%s\n", container.Image)
fmt.Fprintf(out, " Image ID:\t%s\n", status.ImageID)
if len(container.Resources.Limits) > 0 {
fmt.Fprintf(out, " Limits:\n")
@ -716,6 +721,13 @@ func describeContainers(pod *api.Pod, out io.Writer) {
fmt.Fprintf(out, " %s:\t%s\n", name, quantity.String())
}
if len(container.Resources.Requests) > 0 {
fmt.Fprintf(out, " Requests:\n")
}
for name, quantity := range container.Resources.Requests {
fmt.Fprintf(out, " %s:\t%s\n", name, quantity.String())
}
describeStatus("State", state, out)
if status.LastTerminationState.Terminated != nil {
describeStatus("Last Termination State", status.LastTerminationState, out)
@ -1065,8 +1077,10 @@ func describeNode(node *api.Node, pods []*api.Pod, events *api.EventList) (strin
fmt.Fprintf(out, "Name:\t%s\n", node.Name)
fmt.Fprintf(out, "Labels:\t%s\n", labels.FormatLabels(node.Labels))
fmt.Fprintf(out, "CreationTimestamp:\t%s\n", node.CreationTimestamp.Time.Format(time.RFC1123Z))
fmt.Fprintf(out, "Phase:\t%v\n", node.Status.Phase)
if len(node.Status.Conditions) > 0 {
fmt.Fprint(out, "Conditions:\n Type\tStatus\tLastHeartbeatTime\tLastTransitionTime\tReason\tMessage\n")
fmt.Fprint(out, " ────\t──────\t─────────────────\t──────────────────\t──────\t───────\n")
for _, c := range node.Status.Conditions {
fmt.Fprintf(out, " %v \t%v \t%s \t%s \t%v \t%v\n",
c.Type,
@ -1089,18 +1103,10 @@ func describeNode(node *api.Node, pods []*api.Pod, events *api.EventList) (strin
}
}
runningPods := filterNonRunningPods(pods)
reqs, err := getPodsTotalRequests(runningPods)
if err != nil {
return err
}
fmt.Fprintf(out, "Allocated resources (total requests):\n")
for reqResource, reqValue := range reqs {
fmt.Fprintf(out, " %s:\t%s\n", reqResource, reqValue.String())
}
fmt.Fprintf(out, " pods:\t%d\n", len(runningPods))
fmt.Fprintf(out, "Version:\n")
fmt.Fprintf(out, "System Info:\n")
fmt.Fprintf(out, " Machine ID:\t%s\n", node.Status.NodeInfo.MachineID)
fmt.Fprintf(out, " System UUID:\t%s\n", node.Status.NodeInfo.SystemUUID)
fmt.Fprintf(out, " Boot ID:\t%s\n", node.Status.NodeInfo.BootID)
fmt.Fprintf(out, " Kernel Version:\t%s\n", node.Status.NodeInfo.KernelVersion)
fmt.Fprintf(out, " OS Image:\t%s\n", node.Status.NodeInfo.OsImage)
fmt.Fprintf(out, " Container Runtime Version:\t%s\n", node.Status.NodeInfo.ContainerRuntimeVersion)
@ -1113,34 +1119,8 @@ func describeNode(node *api.Node, pods []*api.Pod, events *api.EventList) (strin
if len(node.Spec.ExternalID) > 0 {
fmt.Fprintf(out, "ExternalID:\t%s\n", node.Spec.ExternalID)
}
fmt.Fprintf(out, "Pods:\t(%d in total)\n", len(pods))
fmt.Fprint(out, " Namespace\tName\t\tCPU(milliCPU)\t\tMemory(bytes)\n")
totalMilliCPU := int64(0)
totalMemory := int64(0)
fractionPodCPU := float64(0)
fractionPodMemory := float64(0)
fractionTotalCPU := float64(0)
fractionTotalMemory := float64(0)
for _, pod := range pods {
podTotalMilliCPU := int64(0)
podTotalMemory := int64(0)
describeNodeResource(pods, node, out)
for ix := range pod.Spec.Containers {
limits := pod.Spec.Containers[ix].Resources.Limits
podTotalMilliCPU += limits.Cpu().MilliValue()
podTotalMemory += limits.Memory().Value()
}
totalMilliCPU += podTotalMilliCPU
totalMemory += podTotalMemory
fractionPodCPU = float64(podTotalMilliCPU) / float64(node.Status.Capacity.Cpu().MilliValue()) * 100
fractionPodMemory = float64(podTotalMemory) / float64(node.Status.Capacity.Memory().Value()) * 100
fmt.Fprintf(out, " %s\t%s\t\t%d (%d%% of total)\t\t%d (%d%% of total)\n", pod.Namespace, pod.Name, podTotalMilliCPU, int64(fractionPodCPU), podTotalMemory, int64(fractionPodMemory))
}
fmt.Fprint(out, "TotalResourceLimits:\n")
fractionTotalCPU = float64(totalMilliCPU) / float64(node.Status.Capacity.Cpu().MilliValue()) * 100
fractionTotalMemory = float64(totalMemory) / float64(node.Status.Capacity.Memory().Value()) * 100
fmt.Fprintf(out, " CPU(milliCPU):\t\t%d (%d%% of total)\n", totalMilliCPU, int64(fractionTotalCPU))
fmt.Fprintf(out, " Memory(bytes):\t\t%d (%d%% of total)\n", totalMemory, int64(fractionTotalMemory))
if events != nil {
DescribeEvents(events, out)
}
@ -1197,7 +1177,55 @@ func (d *HorizontalPodAutoscalerDescriber) Describe(namespace, name string) (str
})
}
func filterNonRunningPods(pods []*api.Pod) []*api.Pod {
func describeNodeResource(pods []*api.Pod, node *api.Node, out io.Writer) {
nonTerminatedPods := filterTerminatedPods(pods)
fmt.Fprintf(out, "Non-terminated Pods:\t(%d in total)\n", len(nonTerminatedPods))
fmt.Fprint(out, " Namespace\tName\t\tCPU Requests\tMemory Requests\tCPU Limits\tMemory Limits\n")
fmt.Fprint(out, " ─────────\t────\t\t────────────\t───────────────\t──────────\t─────────────\n")
totalMilliCPUReq := int64(0)
totalMemoryReq := int64(0)
fractionPodCPUReq := float64(0)
fractionPodMemoryReq := float64(0)
fractionTotalCPUReq := float64(0)
fractionTotalMemoryReq := float64(0)
totalMilliCPULimit := int64(0)
totalMemoryLimit := int64(0)
fractionPodCPULimit := float64(0)
fractionPodMemoryLimit := float64(0)
for _, pod := range pods {
podTotalMilliCPUReq := int64(0)
podTotalMemoryReq := int64(0)
podTotalMilliCPULimit := int64(0)
podTotalMemoryLimit := int64(0)
for ix := range pod.Spec.Containers {
requests := pod.Spec.Containers[ix].Resources.Requests
podTotalMilliCPUReq += requests.Cpu().MilliValue()
podTotalMemoryReq += requests.Memory().Value()
limits := pod.Spec.Containers[ix].Resources.Limits
podTotalMilliCPULimit += limits.Cpu().MilliValue()
podTotalMemoryLimit += limits.Memory().Value()
}
totalMilliCPUReq += podTotalMilliCPUReq
totalMemoryReq += podTotalMemoryReq
totalMilliCPULimit += podTotalMilliCPULimit
totalMemoryLimit += podTotalMemoryLimit
fractionPodCPUReq = float64(podTotalMilliCPUReq) / float64(node.Status.Capacity.Cpu().MilliValue()) * 100
fractionPodMemoryReq = float64(podTotalMemoryReq) / float64(node.Status.Capacity.Memory().Value()) * 100
fractionPodCPULimit = float64(podTotalMilliCPULimit) / float64(node.Status.Capacity.Cpu().MilliValue()) * 100
fractionPodMemoryLimit = float64(podTotalMemoryLimit) / float64(node.Status.Capacity.Memory().Value()) * 100
fmt.Fprintf(out, " %s\t%s\t\t%dm (%d%%)\t%dKi (%d%%)\t%dm (%d%%)\t%dKi (%d%%)\n", pod.Namespace, pod.Name,
podTotalMilliCPUReq, int64(fractionPodCPUReq), podTotalMemoryReq/1000, int64(fractionPodMemoryReq), podTotalMilliCPULimit, int64(fractionPodCPULimit), podTotalMemoryLimit/1000, int64(fractionPodMemoryLimit))
}
fmt.Fprint(out, "Allocated resources:\n CPU Requests\tMemory Requests\tCPU Limits\tMemory Limits\n")
fmt.Fprint(out, " ────────────\t───────────────\t──────────\t─────────────\n")
fractionTotalCPUReq = float64(totalMilliCPUReq) / float64(node.Status.Capacity.Cpu().MilliValue()) * 100
fractionTotalMemoryReq = float64(totalMemoryReq) / float64(node.Status.Capacity.Memory().Value()) * 100
fmt.Fprintf(out, " %dm (%d%%)\t%dKi (%d%%)\t%dm\t%dKi\n", totalMilliCPUReq, int64(fractionTotalCPUReq), totalMemoryReq/1000, int64(fractionTotalMemoryReq), totalMilliCPULimit, totalMemoryLimit/1000)
}
func filterTerminatedPods(pods []*api.Pod) []*api.Pod {
if len(pods) == 0 {
return pods
}
@ -1250,6 +1278,7 @@ func DescribeEvents(el *api.EventList, w io.Writer) {
}
sort.Sort(SortableEvents(el.Items))
fmt.Fprint(w, "Events:\n FirstSeen\tLastSeen\tCount\tFrom\tSubobjectPath\tReason\tMessage\n")
fmt.Fprint(w, " ─────────\t────────\t─────\t────\t─────────────\t──────\t───────\n")
for _, e := range el.Items {
fmt.Fprintf(w, " %s\t%s\t%d\t%v\t%v\t%v\t%v\n",
translateTimestamp(e.FirstTimestamp),