func checkTimeSeries(t *testing.T, got *ts.TimeSeries, exp *TestSeries) {
	if got == nil {
		t.Errorf("FAIL(TimeSeries): can't be nil")
		return
	}
	if exp == nil {
		t.Errorf("FAIL(TimeSeries): can't be nil")
		return
	}
	checkKey(t, got.Key(), exp.Key)
	checkStart(t, got.Start(), exp.Start)
	checkEnd(t, got.End(), exp.End)
	checkStep(t, got.Step(), exp.Step)
	checkData(t, got.Data(), exp.Data)
}
func valueString(ts *ts.TimeSeries, start, end time.Time) (string, error) {
	s := bytes.NewBufferString("[ '")
	if _, err := s.WriteString(ts.Key()); err != nil {
		return "", err
	}
	if _, err := s.WriteString("', "); err != nil {
		return "", err
	}
	for cursor, step := start, ts.Step(); cursor.Before(end); cursor = cursor.Add(step) {
		v, _ := ts.GetAt(cursor)
		if _, err := s.WriteString(strconv.FormatFloat(v, 'E', 2, 64)); err != nil {
			return "", err
		}
		if err := s.WriteByte(','); err != nil {
			return "", err
		}
		if step == 0 {
			break
		}
	}
	if s.Len() > 0 {
		s.Truncate(s.Len() - 1)
	}
	if err := s.WriteByte(']'); err != nil {
		return "", err
	}
	return s.String(), nil
}
Beispiel #3
0
func (carbon *Carbon) Write(ts *ts.TimeSeries) {
	carbon.Init()

	var buffer bytes.Buffer

	it := ts.IteratorTimeValue()
	for t, v, ok := it.Next(); ok; t, v, ok = it.Next() {
		fmt.Fprintf(&buffer, "%s %f %d\n", ts.Key(), v, t.Unix())
	}

	go func() {
		carbon.feed <- buffer
	}()
}