Esempio n. 1
0
func (c *Consumer) write(
	n store.NamedIterator, hostName, appName string) error {
	var r store.Record
	c.toBeCommitted = append(c.toBeCommitted, n)
	for n.Next(&r) {
		c.buffer[c.idx] = Record{
			HostName:  hostName,
			Tags:      TagGroup{TagAppName: appName},
			Path:      r.Info.Path(),
			Kind:      r.Info.Kind(),
			SubType:   r.Info.SubType(),
			Unit:      r.Info.Unit(),
			Value:     r.Value,
			Timestamp: duration.FloatToTime(r.TimeStamp),
		}
		c.idx++
		if c.idx == len(c.buffer) {
			err := c.flush()
			if err != nil {
				return err
			}
			c.toBeCommitted = append(c.toBeCommitted, n)
		}
	}
	return nil
}
Esempio n. 2
0
// FromFloat converts a float64 to a value according to this type
// FromFloat panics if this type doesn't support conversion from float64
func (t Type) FromFloat(value float64) interface{} {
	switch t {
	case Int8:
		return int8(round(value))
	case Int16:
		return int16(round(value))
	case Int32:
		return int32(round(value))
	case Int64:
		return int64(round(value))
	case Uint8:
		return uint8(round(value))
	case Uint16:
		return uint16(round(value))
	case Uint32:
		return uint32(round(value))
	case Uint64:
		return uint64(round(value))
	case Float32:
		return float32(value)
	case Float64:
		return value
	case GoTime:
		return duration.FloatToTime(value)
	case GoDuration:
		return duration.FromFloat(value)
	default:
		panic("Type doesn't support converstion from a float")
	}
}
Esempio n. 3
0
func (a *latestMetricsAppender) Append(r *store.Record) bool {
	// Skip inactive records
	if !r.Active {
		return true
	}
	var upperLimits []float64
	if r.Info.Kind() == types.Dist {
		upperLimits = r.Info.Ranges().UpperLimits
	}
	aMetric := &messages.LatestMetric{
		HostName:        a.hostName,
		AppName:         a.appName,
		Path:            r.Info.Path(),
		Kind:            r.Info.Kind(),
		SubType:         r.Info.SubType(),
		Description:     r.Info.Description(),
		Bits:            r.Info.Bits(),
		Unit:            r.Info.Unit(),
		Value:           fixForGoRPC(r.Value, r.Info.Kind()),
		Timestamp:       duration.FloatToTime(r.TimeStamp),
		IsNotCumulative: r.Info.IsNotCumulative(),
		UpperLimits:     upperLimits,
	}
	*a.result = append(*a.result, aMetric)
	return true
}
Esempio n. 4
0
func addValues(
	t *testing.T,
	aStore *store.Store,
	endpointId interface{},
	path string,
	data ...float64) {
	if len(data)%2 != 0 {
		t.Fatal("Timestamp value pairs expected")
	}
	aMetric := metrics.SimpleList{
		{
			Path:        path,
			Description: "A description",
		},
	}
	dataLen := len(data)
	for i := 0; i < dataLen; i += 2 {
		aMetric[0].TimeStamp = duration.FloatToTime(data[i])
		aMetric[0].Value = data[i+1]
		if _, err := aStore.AddBatch(endpointId, 1000.0, aMetric); err != nil {
			t.Fatal(err)
		}
	}
}
Esempio n. 5
0
func (s *storePrimitiveMetricsType) TimeSpan() time.Duration {
	return time.Since(duration.FloatToTime(s.LatestEvictedTimeStamp))
}