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 } } } } } }
// 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 }
// 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 }
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 } } } } }
// 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 }) }