示例#1
0
文件: jsonrpc.go 项目: keep94/scotty
func (a *latestMetricsAppenderJSON) Append(r *store.Record) bool {
	// Skip inactive records
	if !r.Active {
		return true
	}
	jsonValue, jsonKind, jsonSubType := asJsonWithSubType(
		r.Value,
		r.Info.Kind(),
		r.Info.SubType(),
		r.Info.Unit())
	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:            jsonKind,
		SubType:         jsonSubType,
		Description:     r.Info.Description(),
		Bits:            r.Info.Bits(),
		Unit:            r.Info.Unit(),
		Value:           jsonValue,
		Timestamp:       duration.SinceEpochFloat(r.TimeStamp).String(),
		IsNotCumulative: r.Info.IsNotCumulative(),
		UpperLimits:     upperLimits,
	}
	*a.result = append(*a.result, aMetric)
	return true
}
示例#2
0
文件: jsonrpc.go 项目: keep94/scotty
func (a *endpointMetricsAppender) Append(r *store.Record) bool {
	if !store.GroupMetricByKey.Equal(r.Info, a.lastInfo) {
		jsonValue, jsonKind, jsonSubType := asJsonWithSubType(
			r.Value,
			r.Info.Kind(),
			r.Info.SubType(),
			r.Info.Unit())
		var upperLimits []float64
		if r.Info.Kind() == types.Dist {
			upperLimits = r.Info.Ranges().UpperLimits
		}
		a.lastMetric = &messages.EndpointMetric{
			Path:        r.Info.Path(),
			Kind:        jsonKind,
			SubType:     jsonSubType,
			Description: r.Info.Description(),
			Bits:        r.Info.Bits(),
			Unit:        r.Info.Unit(),
			Values: []*messages.TimestampedValue{{
				Timestamp: duration.SinceEpochFloat(
					r.TimeStamp).String(),
				Value:  jsonValue,
				Active: r.Active,
			}},
			IsNotCumulative: r.Info.IsNotCumulative(),
			UpperLimits:     upperLimits,
		}
		*a.endpointMetrics = append(*a.endpointMetrics, a.lastMetric)
	} else {
		jsonValue, _, _ := asJsonWithSubType(
			r.Value,
			r.Info.Kind(),
			r.Info.SubType(),
			r.Info.Unit())
		newTimestampedValue := &messages.TimestampedValue{
			Timestamp: duration.SinceEpochFloat(
				r.TimeStamp).String(),
			Value:  jsonValue,
			Active: r.Active,
		}
		a.lastMetric.Values = append(
			a.lastMetric.Values, newTimestampedValue)
	}
	a.lastInfo = r.Info
	return true
}