Merge pull request #2740 from Ace-Tang/ctr_metric
ctr: fix potential panic in metric
This commit is contained in:
commit
52893fbb05
@ -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")
|
||||||
|
if data.Memory != nil {
|
||||||
fmt.Fprintf(w, "memory.usage_in_bytes\t%d\t\n", data.Memory.Usage.Usage)
|
fmt.Fprintf(w, "memory.usage_in_bytes\t%d\t\n", data.Memory.Usage.Usage)
|
||||||
fmt.Fprintf(w, "memory.limit_in_bytes\t%d\t\n", data.Memory.Usage.Limit)
|
fmt.Fprintf(w, "memory.limit_in_bytes\t%d\t\n", data.Memory.Usage.Limit)
|
||||||
fmt.Fprintf(w, "memory.stat.cache\t%d\t\n", data.Memory.TotalCache)
|
fmt.Fprintf(w, "memory.stat.cache\t%d\t\n", data.Memory.TotalCache)
|
||||||
|
}
|
||||||
|
if data.CPU != nil {
|
||||||
fmt.Fprintf(w, "cpuacct.usage\t%d\t\n", data.CPU.Usage.Total)
|
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)
|
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.current\t%v\t\n", data.Pids.Current)
|
||||||
fmt.Fprintf(w, "pids.limit\t%v\t\n", data.Pids.Limit)
|
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, "", " ")
|
||||||
|
Loading…
Reference in New Issue
Block a user