예제 #1
0
func (v *value) updateJsonOrRpcMetric(
	s *session, metric *messages.Metric, encoding rpcEncoding) {
	t := v.Type()
	metric.Kind = t
	metric.Bits = v.Bits()
	switch t {
	case types.Dist:
		snapshot := v.AsDistribution().Snapshot()
		metric.Value = &messages.Distribution{
			Min:             snapshot.Min,
			Max:             snapshot.Max,
			Average:         snapshot.Average,
			Median:          snapshot.Median,
			Sum:             snapshot.Sum,
			Count:           snapshot.Count,
			Generation:      snapshot.Generation,
			IsNotCumulative: snapshot.IsNotCumulative,
			Ranges:          asRanges(snapshot.Breakdown)}
	default:
		metric.Value = v.AsInterface(s)
	}
	if encoding == jsonEncoding {
		metric.ConvertToJson()
	}
}
예제 #2
0
파일: metric.go 프로젝트: rgooch/tricorder
func (v *value) updateJsonOrRpcMetric(
	s *session, metric *messages.Metric, encoding rpcEncoding) {
	t := v.Type()
	metric.Kind = t
	metric.SubType = v.SubType()
	metric.Bits = v.Bits()
	metric.Unit = v.Unit()
	switch t {
	case types.Dist:
		dist := v.AsDistribution()
		snapshot := dist.Snapshot()
		metric.Value = &messages.Distribution{
			Min:             snapshot.Min,
			Max:             snapshot.Max,
			Average:         snapshot.Average,
			Median:          snapshot.Median,
			Sum:             snapshot.Sum,
			Count:           snapshot.Count,
			Generation:      snapshot.Generation,
			IsNotCumulative: snapshot.IsNotCumulative,
			Ranges:          asRanges(snapshot.Breakdown)}
		metric.GroupId = dist.GroupId()
		metric.TimeStamp = snapshot.TimeStamp
	case types.List:
		alist := v.AsList()
		metric.Value, metric.TimeStamp = alist.AsSlice()
		metric.GroupId = alist.GroupId()
	default:
		if s == nil {
			s = newSession()
			defer s.Close()
		}
		metric.Value = v.AsInterface(s)
		metric.GroupId = v.RegionId()
		metric.TimeStamp = v.TimeStamp(s)
	}
	if encoding == jsonEncoding {
		metric.ConvertToJson()
	}
}