check if the stats is valid

This commit is contained in:
Nan Deng 2014-07-02 14:57:23 -07:00
parent 795b451288
commit 92c34ae490

View File

@ -54,8 +54,8 @@ func (self *influxdbStorage) containerStatsToValues(
columns = append(columns, "cpu_cumulative_usage") columns = append(columns, "cpu_cumulative_usage")
values = append(values, stats.Cpu.Usage.Total) values = append(values, stats.Cpu.Usage.Total)
// Cumulative Cpu Usage in kernel mode // Cumulative Cpu Usage in system mode
columns = append(columns, "cpu_cumulative_usage_kernel") columns = append(columns, "cpu_cumulative_usage_system")
values = append(values, stats.Cpu.Usage.System) values = append(values, stats.Cpu.Usage.System)
// Cumulative Cpu Usage in user mode // Cumulative Cpu Usage in user mode
@ -168,8 +168,8 @@ func (self *influxdbStorage) valuesToContainerStats(columns []string, values []i
// Cumulative Cpu Usage // Cumulative Cpu Usage
case "cpu_cumulative_usage": case "cpu_cumulative_usage":
stats.Cpu.Usage.Total, err = convertToUint64(v) stats.Cpu.Usage.Total, err = convertToUint64(v)
// Cumulative Cpu Usage in kernel mode // Cumulative Cpu used by the system
case "cpu_cumulative_usage_kernel": case "cpu_cumulative_usage_system":
stats.Cpu.Usage.System, err = convertToUint64(v) stats.Cpu.Usage.System, err = convertToUint64(v)
// Cumulative Cpu Usage in user mode // Cumulative Cpu Usage in user mode
case "cpu_cumulative_usage_user": case "cpu_cumulative_usage_user":
@ -274,6 +274,9 @@ func (self *influxdbStorage) AddStats(ref info.ContainerReference, stats *info.C
// There's only one point for each stats // There's only one point for each stats
Points: make([][]interface{}, 1), Points: make([][]interface{}, 1),
} }
if stats == nil || stats.Cpu == nil || stats.Memory == nil {
return nil
}
series.Columns, series.Points[0] = self.containerStatsToValues(ref, stats) series.Columns, series.Points[0] = self.containerStatsToValues(ref, stats)
self.prevStats = stats.Copy(self.prevStats) self.prevStats = stats.Copy(self.prevStats)