ctr: fix potential panic in metric

Signed-off-by: Ace-Tang <aceapril@126.com>
This commit is contained in:
Ace-Tang 2018-10-22 11:39:33 +08:00
parent a4b6522e11
commit c3cac72b92

View File

@ -89,13 +89,19 @@ var metricsCommand = cli.Command{
fmt.Fprintf(w, "%s\t%s\t\n\n", metric.ID, metric.Timestamp) fmt.Fprintf(w, "%s\t%s\t\n\n", metric.ID, metric.Timestamp)
fmt.Fprintf(w, "METRIC\tVALUE\t\n") fmt.Fprintf(w, "METRIC\tVALUE\t\n")
fmt.Fprintf(w, "memory.usage_in_bytes\t%d\t\n", data.Memory.Usage.Usage) if data.Memory != nil {
fmt.Fprintf(w, "memory.limit_in_bytes\t%d\t\n", data.Memory.Usage.Limit) fmt.Fprintf(w, "memory.usage_in_bytes\t%d\t\n", data.Memory.Usage.Usage)
fmt.Fprintf(w, "memory.stat.cache\t%d\t\n", data.Memory.TotalCache) fmt.Fprintf(w, "memory.limit_in_bytes\t%d\t\n", data.Memory.Usage.Limit)
fmt.Fprintf(w, "cpuacct.usage\t%d\t\n", data.CPU.Usage.Total) fmt.Fprintf(w, "memory.stat.cache\t%d\t\n", data.Memory.TotalCache)
fmt.Fprintf(w, "cpuacct.usage_percpu\t%v\t\n", data.CPU.Usage.PerCPU) }
fmt.Fprintf(w, "pids.current\t%v\t\n", data.Pids.Current) if data.CPU != nil {
fmt.Fprintf(w, "pids.limit\t%v\t\n", data.Pids.Limit) fmt.Fprintf(w, "cpuacct.usage\t%d\t\n", data.CPU.Usage.Total)
fmt.Fprintf(w, "cpuacct.usage_percpu\t%v\t\n", data.CPU.Usage.PerCPU)
}
if data.Pids != nil {
fmt.Fprintf(w, "pids.current\t%v\t\n", data.Pids.Current)
fmt.Fprintf(w, "pids.limit\t%v\t\n", data.Pids.Limit)
}
return w.Flush() return w.Flush()
case formatJSON: case formatJSON:
marshaledJSON, err := json.MarshalIndent(data, "", " ") marshaledJSON, err := json.MarshalIndent(data, "", " ")