diff --git a/api.go b/api.go index 8d97c0e..43b9bb9 100644 --- a/api.go +++ b/api.go @@ -183,7 +183,7 @@ type ApiQueryRequest struct { From int64 `json:"from"` To int64 `json:"to"` WithStats bool `json:"with-stats"` - WithUnit bool `json:"with-unit"` + WithUnit bool `json:"with-unit,omitempty"` WithData bool `json:"with-data"` WithPadding bool `json:"with-padding"` Queries []ApiQuery `json:"queries"` @@ -303,7 +303,7 @@ func handleQuery(rw http.ResponseWriter, r *http.Request) { if req.WithPadding { data.PadDataWithNull(req.From, req.To, query.Metric) } - if req.WithUnit { + if req.WithUnit && len(unit) > 0 { data.Unit = unit } if !req.WithData { diff --git a/archive.go b/archive.go index c7d84e9..ac95104 100644 --- a/archive.go +++ b/archive.go @@ -24,7 +24,7 @@ import ( type CheckpointMetrics struct { Frequency int64 `json:"frequency"` Start int64 `json:"start"` - Unit string `json:"unit"` + Unit string `json:"unit,omitempty"` Data []Float `json:"data"` } @@ -312,7 +312,7 @@ func (l *level) loadFile(cf *CheckpointFile, m *MemoryStore) error { frequency: metric.Frequency, start: metric.Start, data: metric.Data[0:n:n], // Space is wasted here :( - unit: "", + unit: metric.Unit, prev: nil, next: nil, archived: true, diff --git a/debug.go b/debug.go index 88af59f..567943d 100644 --- a/debug.go +++ b/debug.go @@ -21,6 +21,9 @@ func (b *buffer) debugDump(buf []byte) []byte { if b.archived { buf = append(buf, `,"saved":true`...) } + if b.unit != "" { + buf = append(buf, fmt.Sprintf(`,"unit":"%s"`, b.unit)...) + } if b.next != nil { buf = append(buf, `},`...) } else {