From ebabaa46f4d6c02b9547a56b68ec584f9766a67f Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Sun, 13 Jan 2013 19:56:48 +0100 Subject: [PATCH] Serialize matrices correctly. --- model/metric.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/model/metric.go b/model/metric.go index fdb2802b3..fcdf5dde0 100644 --- a/model/metric.go +++ b/model/metric.go @@ -15,6 +15,7 @@ package model import ( "time" + "fmt" ) // A Fingerprint is a simplified representation of an entity---e.g., a hash of @@ -45,6 +46,14 @@ type Metric map[LabelName]LabelValue // remedied down the road. type SampleValue float32 +func (v SampleValue) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf("\"%f\"", v)), nil +} + +func (s SamplePair) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf("{\"Value\": \"%f\", \"Timestamp\": %d}", s.Value, s.Timestamp.Unix())), nil +} + type Sample struct { Metric Metric Value SampleValue