Ejemplo n.º 1
0
func (self *influxdbStorage) AddStats(ref info.ContainerReference, stats *info.ContainerStats) error {
	if stats == nil || stats.Cpu == nil || stats.Memory == nil {
		return nil
	}
	// AddStats will be invoked simultaneously from multiple threads and only one of them will perform a write.
	var seriesToFlush []*influxdb.Series
	func() {
		self.lock.Lock()
		defer self.lock.Unlock()
		series := self.newSeries(self.containerStatsToValues(ref, stats))
		self.series = append(self.series, series)
		self.prevStats = stats.Copy(self.prevStats)
		if self.readyToFlush() {
			seriesToFlush = self.series
			self.series = make([]*influxdb.Series, 0)
			self.lastWrite = time.Now()
		}
	}()
	if len(seriesToFlush) > 0 {
		err := self.client.WriteSeries(seriesToFlush)
		if err != nil {
			return fmt.Errorf("failed to write stats to influxDb - %s", err)
		}
	}

	return nil
}
Ejemplo n.º 2
0
func (self *containerStorage) updatePrevStats(stats *info.ContainerStats) {
	if stats == nil || stats.Cpu == nil || stats.Memory == nil {
		// discard incomplete stats
		self.prevStats = nil
		return
	}
	self.prevStats = stats.Copy(self.prevStats)
}
Ejemplo n.º 3
0
func (self *bigqueryStorage) AddStats(ref info.ContainerReference, stats *info.ContainerStats) error {
	if stats == nil || stats.Cpu == nil || stats.Memory == nil {
		return nil
	}

	row := self.containerStatsToValues(ref, stats)
	self.prevStats = stats.Copy(self.prevStats)

	err := self.client.InsertRow(row)
	if err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 4
0
func (self *influxdbStorage) AddStats(ref info.ContainerReference, stats *info.ContainerStats) error {
	series := &influxdb.Series{
		Name: self.tableName,
		// There's only one point for each stats
		Points: make([][]interface{}, 1),
	}
	if stats == nil || stats.Cpu == nil || stats.Memory == nil {
		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 {
		return err
	}
	return nil
}