Merge pull request #169 from rjnagal/master
Improve influxdb backend - use container alias if available and store network stats.
This commit is contained in:
commit
949a65de90
@ -62,6 +62,14 @@ const (
|
||||
colCpuInstantUsage string = "cpu_instant_usage"
|
||||
// Optional: Instant per core usage
|
||||
colPerCoreInstantUsagePrefix string = "per_core_instant_usage_core_"
|
||||
// Cumulative count of bytes received.
|
||||
colRxBytes string = "rx_bytes"
|
||||
// Cumulative count of receive errors encountered.
|
||||
colRxErrors string = "rx_errors"
|
||||
// Cumulative count of bytes transmitted.
|
||||
colTxBytes string = "tx_bytes"
|
||||
// Cumulative count of transmit errors encountered.
|
||||
colTxErrors string = "tx_errors"
|
||||
)
|
||||
|
||||
func (self *influxdbStorage) containerStatsToValues(
|
||||
@ -79,7 +87,11 @@ func (self *influxdbStorage) containerStatsToValues(
|
||||
|
||||
// Container name
|
||||
columns = append(columns, colContainerName)
|
||||
values = append(values, ref.Name)
|
||||
if len(ref.Aliases) > 0 {
|
||||
values = append(values, ref.Aliases[0])
|
||||
} else {
|
||||
values = append(values, ref.Name)
|
||||
}
|
||||
|
||||
// Cumulative Cpu Usage
|
||||
columns = append(columns, colCpuCumulativeUsage)
|
||||
@ -117,6 +129,21 @@ func (self *influxdbStorage) containerStatsToValues(
|
||||
columns = append(columns, colMemoryHierarchicalPgmajfault)
|
||||
values = append(values, stats.Memory.HierarchicalData.Pgmajfault)
|
||||
|
||||
// Optional: Network stats.
|
||||
if stats.Network != nil {
|
||||
columns = append(columns, colRxBytes)
|
||||
values = append(values, stats.Network.RxBytes)
|
||||
|
||||
columns = append(columns, colRxErrors)
|
||||
values = append(values, stats.Network.RxErrors)
|
||||
|
||||
columns = append(columns, colTxBytes)
|
||||
values = append(values, stats.Network.TxBytes)
|
||||
|
||||
columns = append(columns, colTxErrors)
|
||||
values = append(values, stats.Network.TxErrors)
|
||||
}
|
||||
|
||||
// per cpu cumulative usage
|
||||
for i, u := range stats.Cpu.Usage.PerCpu {
|
||||
columns = append(columns, fmt.Sprintf("%v%v", colPerCoreCumulativeUsagePrefix, i))
|
||||
@ -127,6 +154,7 @@ func (self *influxdbStorage) containerStatsToValues(
|
||||
if err != nil || sample == nil {
|
||||
return columns, values
|
||||
}
|
||||
// DO NOT ADD ANY STATS BELOW THAT ARE NOT PART OF SAMPLING
|
||||
|
||||
// Optional: sample duration. Unit: Nanosecond.
|
||||
columns = append(columns, colSampleDuration)
|
||||
@ -180,8 +208,9 @@ func convertToUint64(v interface{}) (uint64, error) {
|
||||
|
||||
func (self *influxdbStorage) valuesToContainerStats(columns []string, values []interface{}) (*info.ContainerStats, error) {
|
||||
stats := &info.ContainerStats{
|
||||
Cpu: &info.CpuStats{},
|
||||
Memory: &info.MemoryStats{},
|
||||
Cpu: &info.CpuStats{},
|
||||
Memory: &info.MemoryStats{},
|
||||
Network: &info.NetworkStats{},
|
||||
}
|
||||
perCoreUsage := make(map[int]uint64, 32)
|
||||
var err error
|
||||
@ -227,6 +256,14 @@ func (self *influxdbStorage) valuesToContainerStats(columns []string, values []i
|
||||
// hierarchical major page fault
|
||||
case col == colMemoryHierarchicalPgmajfault:
|
||||
stats.Memory.HierarchicalData.Pgmajfault, err = convertToUint64(v)
|
||||
case col == colRxBytes:
|
||||
stats.Network.RxBytes, err = convertToUint64(v)
|
||||
case col == colRxErrors:
|
||||
stats.Network.RxErrors, err = convertToUint64(v)
|
||||
case col == colTxBytes:
|
||||
stats.Network.TxBytes, err = convertToUint64(v)
|
||||
case col == colTxErrors:
|
||||
stats.Network.TxErrors, err = convertToUint64(v)
|
||||
case strings.HasPrefix(col, colPerCoreCumulativeUsagePrefix):
|
||||
idxStr := col[len(colPerCoreCumulativeUsagePrefix):]
|
||||
idx, err := strconv.Atoi(idxStr)
|
||||
@ -310,7 +347,6 @@ func (self *influxdbStorage) AddStats(ref info.ContainerReference, stats *info.C
|
||||
return nil
|
||||
}
|
||||
series.Columns, series.Points[0] = self.containerStatsToValues(ref, stats)
|
||||
|
||||
self.prevStats = stats.Copy(self.prevStats)
|
||||
err := self.client.WriteSeries([]*influxdb.Series{series})
|
||||
if err != nil {
|
||||
|
@ -53,6 +53,11 @@ func buildTrace(cpu, mem []uint64, duration time.Duration) []*info.ContainerStat
|
||||
|
||||
stats.Memory.Usage = mem[i]
|
||||
|
||||
stats.Network = new(info.NetworkStats)
|
||||
stats.Network.RxBytes = uint64(rand.Intn(10000))
|
||||
stats.Network.RxErrors = uint64(rand.Intn(1000))
|
||||
stats.Network.TxBytes = uint64(rand.Intn(100000))
|
||||
stats.Network.TxErrors = uint64(rand.Intn(1000))
|
||||
ret[i] = stats
|
||||
}
|
||||
return ret
|
||||
@ -98,6 +103,9 @@ func DefaultStatsEq(a, b *info.ContainerStats) bool {
|
||||
if !reflect.DeepEqual(a.Memory, b.Memory) {
|
||||
return false
|
||||
}
|
||||
if !reflect.DeepEqual(a.Network, b.Network) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@ -434,7 +442,7 @@ func StorageDriverTestRetrieveAllRecentStats(driver TestStorageDriver, t *testin
|
||||
t.Fatal("should at least store one stats")
|
||||
}
|
||||
if len(recentStats) > N {
|
||||
t.Fatalf("returned %v stats, not 100.", len(recentStats))
|
||||
t.Fatalf("returned %v stats, not %d.", len(recentStats), N)
|
||||
}
|
||||
|
||||
actualRecentStats := trace[len(trace)-len(recentStats):]
|
||||
|
Loading…
Reference in New Issue
Block a user