示例#1
0
// ToWire converts the state.MetricBatch into a type
// that can be sent over the wire to the collector.
func ToWire(mb *state.MetricBatch) *MetricBatch {
	metrics := make([]Metric, len(mb.Metrics()))
	for i, m := range mb.Metrics() {
		metrics[i] = Metric{
			Key:   m.Key,
			Value: m.Value,
			Time:  m.Time.UTC(),
		}
	}
	return &MetricBatch{
		UUID:        mb.UUID(),
		EnvUUID:     mb.EnvUUID(),
		UnitName:    mb.Unit(),
		CharmUrl:    mb.CharmURL(),
		Created:     mb.Created().UTC(),
		Metrics:     metrics,
		Credentials: mb.Credentials(),
	}
}