コード例 #1
0
ファイル: group_by.go プロジェクト: yuanwr/kapacitor
func setGroupOnPoint(p models.Point, allDimensions bool, dimensions []string) models.Point {
	if allDimensions {
		dimensions = models.SortedKeys(p.Tags)
	}
	p.Group = models.TagsToGroupID(dimensions, p.Tags)
	p.Dimensions = dimensions
	return p
}
コード例 #2
0
ファイル: group_by.go プロジェクト: wutaizeng/kapacitor
func setGroupOnPoint(p models.Point, allDimensions bool, dimensions models.Dimensions) models.Point {
	if allDimensions {
		dimensions.TagNames = models.SortedKeys(p.Tags)
	}
	p.Group = models.ToGroupID(p.Name, p.Tags, dimensions)
	p.Dimensions = dimensions
	return p
}
コード例 #3
0
ファイル: stats.go プロジェクト: karlitxo/kapacitor
func (s *StatsNode) runStats([]byte) error {
	ticker := time.NewTicker(s.s.Interval)
	defer ticker.Stop()
	point := models.Point{
		Name: "stats",
		Tags: map[string]string{"node": s.en.Name()},
	}
	for {
		select {
		case <-s.closing:
			return nil
		case now := <-ticker.C:
			point.Time = now.UTC()
			stats := s.en.nodeStatsByGroup()
			for group, stat := range stats {
				point.Fields = stat.Fields
				point.Group = group
				point.Dimensions = stat.Dimensions
				point.Tags = stat.Tags
				for _, out := range s.outs {
					err := out.CollectPoint(point)
					if err != nil {
						return err
					}
				}
			}
		}
	}
}
コード例 #4
0
ファイル: stats.go プロジェクト: wutaizeng/kapacitor
// Emit a set of stats data points.
func (s *StatsNode) emit(now time.Time) error {
	s.timer.Start()
	point := models.Point{
		Name: "stats",
		Tags: map[string]string{"node": s.en.Name()},
		Time: now.UTC(),
	}
	if s.s.AlignFlag {
		point.Time = point.Time.Round(s.s.Interval)
	}
	stats := s.en.nodeStatsByGroup()
	for group, stat := range stats {
		point.Fields = stat.Fields
		point.Group = group
		point.Dimensions = stat.Dimensions
		point.Tags = stat.Tags
		s.timer.Pause()
		for _, out := range s.outs {
			err := out.CollectPoint(point)
			if err != nil {
				return err
			}
		}
		s.timer.Resume()
	}
	s.timer.Stop()
	return nil
}
コード例 #5
0
ファイル: functions.go プロジェクト: md14454/kapacitor
// take the result of a reduce operation and convert it to a point
func reduceResultToPoint(field string, v interface{}, tmax time.Time, usePointTimes bool) models.Point {
	if pp, ok := v.(tsdb.PositionPoint); ok {
		p := models.Point{}
		if usePointTimes {
			p.Time = time.Unix(pp.Time, 0).UTC()
		} else {
			p.Time = tmax
		}
		p.Fields = models.Fields{field: pp.Value}
		p.Tags = pp.Tags
		return p
	}
	p := models.Point{}
	p.Fields = models.Fields{field: v}
	p.Time = tmax
	return p
}
コード例 #6
0
ファイル: stats.go プロジェクト: sstarcher/kapacitor
func (s *StatsNode) runStats([]byte) error {
	ticker := time.NewTicker(s.s.Interval)
	defer ticker.Stop()
	point := models.Point{
		Name: "stats",
		Tags: map[string]string{"node": s.en.Name()},
	}
	for {
		select {
		case <-s.closing:
			return nil
		case now := <-ticker.C:
			point.Time = now
			count := s.en.collectedCount()
			point.Fields = models.Fields{"collected": count}
			for _, out := range s.outs {
				err := out.CollectPoint(point)
				if err != nil {
					return err
				}
			}
		}
	}
}
コード例 #7
0
ファイル: replay.go プロジェクト: md14454/kapacitor
func WritePointForRecording(w io.Writer, p models.Point, precision string) error {
	fmt.Fprintf(w, "%s\n%s\n", p.Database, p.RetentionPolicy)
	w.Write(p.Bytes(precision))
	w.Write([]byte("\n"))
	return nil
}
コード例 #8
0
ファイル: combine.go プロジェクト: wutaizeng/kapacitor
// Combine a set of points into all their combinations.
func (n *CombineNode) combineBuffer(buf *buffer) error {
	if len(buf.Points) == 0 {
		return nil
	}
	l := len(n.expressions)
	expressions, ok := n.expressionsByGroup[buf.Group]
	if !ok {
		expressions = make([]stateful.Expression, l)
		for i, expr := range n.expressions {
			expressions[i] = expr.CopyReset()
		}
		n.expressionsByGroup[buf.Group] = expressions
	}

	// Compute matching result for all points
	matches := make([]map[int]bool, l)
	for i := 0; i < l; i++ {
		matches[i] = make(map[int]bool, len(buf.Points))
	}
	for idx, p := range buf.Points {
		for i := range expressions {
			matched, err := EvalPredicate(expressions[i], n.scopePools[i], p.Time, p.Fields, p.Tags)
			if err != nil {
				n.logger.Println("E! evaluating lambda expression:", err)
			}
			matches[i][idx] = matched
		}
	}

	p := models.Point{
		Name:       buf.Name,
		Group:      buf.Group,
		Dimensions: buf.Dimensions,
	}
	dimensions := p.Dimensions.ToSet()
	set := make([]rawPoint, l)
	return n.combination.Do(len(buf.Points), l, func(indices []int) error {
		valid := true
		for s := 0; s < l; s++ {
			found := false
			for i := range indices {
				if matches[s][indices[i]] {
					set[s] = buf.Points[indices[i]]
					indices = append(indices[0:i], indices[i+1:]...)
					found = true
					break
				}
			}
			if !found {
				valid = false
				break
			}
		}
		if valid {
			rp := n.merge(set, dimensions)

			p.Time = rp.Time.Round(n.c.Tolerance)
			p.Fields = rp.Fields
			p.Tags = rp.Tags

			n.timer.Pause()
			for _, out := range n.outs {
				err := out.CollectPoint(p)
				if err != nil {
					return err
				}
			}
			n.timer.Resume()
		}
		return nil
	})
}