func (r *replayStreamSource) replayStream(stream StreamCollector, recTime bool, precision string) { defer stream.Close() defer r.data.Close() start := time.Time{} var diff time.Duration zero := r.clck.Zero() for r.in.Scan() { db := r.in.Text() if !r.in.Scan() { r.err <- fmt.Errorf("invalid replay file format, expected another line") return } rp := r.in.Text() if !r.in.Scan() { r.err <- fmt.Errorf("invalid replay file format, expected another line") return } points, err := dbmodels.ParsePointsWithPrecision( r.in.Bytes(), zero, precision, ) if err != nil { r.err <- err return } if start.IsZero() { start = points[0].Time() diff = zero.Sub(start) } var t time.Time waitTime := points[0].Time().Add(diff).UTC() if !recTime { t = waitTime } else { t = points[0].Time().UTC() } mp := points[0] p := models.Point{ Database: db, RetentionPolicy: rp, Name: mp.Name(), Group: models.NilGroup, Tags: models.Tags(mp.Tags()), Fields: models.Fields(mp.Fields()), Time: t, } r.clck.Until(waitTime) err = stream.CollectPoint(p) if err != nil { r.err <- err return } } r.err <- r.in.Err() }
func (s *Service) reportStats() { now := time.Now().UTC() data, err := kapacitor.GetStatsData() if err != nil { s.logger.Println("E! error getting stats data:", err) return } for _, stat := range data { p := models.Point{ Database: s.db, RetentionPolicy: s.rp, Name: stat.Name, Group: models.NilGroup, Tags: models.Tags(stat.Tags), Time: now, Fields: models.Fields(stat.Values), } s.stream.CollectPoint(p) } }
func (tm *TaskMaster) WritePoints(pts *cluster.WritePointsRequest) error { if tm.closed { return ErrTaskMasterClosed } for _, mp := range pts.Points { p := models.Point{ Database: pts.Database, RetentionPolicy: pts.RetentionPolicy, Name: mp.Name(), Group: models.NilGroup, Tags: models.Tags(mp.Tags()), Fields: models.Fields(mp.Fields()), Time: mp.Time(), } err := tm.writePointsIn.CollectPoint(p) if err != nil { return err } } return nil }
func (tm *TaskMaster) WritePoints(database, retentionPolicy string, consistencyLevel imodels.ConsistencyLevel, points []imodels.Point) error { if tm.closed { return ErrTaskMasterClosed } for _, mp := range points { p := models.Point{ Database: database, RetentionPolicy: retentionPolicy, Name: mp.Name(), Group: models.NilGroup, Tags: models.Tags(mp.Tags()), Fields: models.Fields(mp.Fields()), Time: mp.Time(), } err := tm.writePointsIn.CollectPoint(p) if err != nil { return err } } return nil }
func readPointsFromIO(data io.ReadCloser, points chan<- models.Point, precision string) error { defer data.Close() defer close(points) now := time.Time{} in := bufio.NewScanner(data) for in.Scan() { db := in.Text() if !in.Scan() { return fmt.Errorf("invalid replay file format, expected another line") } rp := in.Text() if !in.Scan() { return fmt.Errorf("invalid replay file format, expected another line") } mps, err := dbmodels.ParsePointsWithPrecision( in.Bytes(), now, precision, ) if err != nil { return err } mp := mps[0] p := models.Point{ Database: db, RetentionPolicy: rp, Name: mp.Name(), Group: models.NilGroup, Tags: models.Tags(mp.Tags().Map()), Fields: models.Fields(mp.Fields()), Time: mp.Time().UTC(), } points <- p } return nil }