mirror of
https://github.com/ClusterCockpit/cc-metric-store.git
synced 2025-02-28 12:07:08 +01:00
Add request flag WithUnit and return the metric unit if requested
This commit is contained in:
parent
051cba4666
commit
7c891e1593
9
api.go
9
api.go
@ -30,6 +30,7 @@ type ApiMetricData struct {
|
||||
Avg Float `json:"avg"`
|
||||
Min Float `json:"min"`
|
||||
Max Float `json:"max"`
|
||||
Unit string `json:"unit,omitempty"`
|
||||
}
|
||||
|
||||
// TODO: Optimize this, just like the stats endpoint!
|
||||
@ -182,6 +183,7 @@ type ApiQueryRequest struct {
|
||||
From int64 `json:"from"`
|
||||
To int64 `json:"to"`
|
||||
WithStats bool `json:"with-stats"`
|
||||
WithUnit bool `json:"with-unit"`
|
||||
WithData bool `json:"with-data"`
|
||||
WithPadding bool `json:"with-padding"`
|
||||
Queries []ApiQuery `json:"queries"`
|
||||
@ -281,7 +283,9 @@ func handleQuery(rw http.ResponseWriter, r *http.Request) {
|
||||
res := make([]ApiMetricData, 0, len(sels))
|
||||
for _, sel := range sels {
|
||||
data := ApiMetricData{}
|
||||
data.Data, data.From, data.To, err = memoryStore.Read(sel, query.Metric, req.From, req.To)
|
||||
data.Unit = ""
|
||||
unit := ""
|
||||
data.Data, data.From, data.To, unit, err = memoryStore.Read(sel, query.Metric, req.From, req.To)
|
||||
// log.Printf("data: %#v, %#v, %#v, %#v", data.Data, data.From, data.To, err)
|
||||
if err != nil {
|
||||
msg := err.Error()
|
||||
@ -299,6 +303,9 @@ func handleQuery(rw http.ResponseWriter, r *http.Request) {
|
||||
if req.WithPadding {
|
||||
data.PadDataWithNull(req.From, req.To, query.Metric)
|
||||
}
|
||||
if req.WithUnit {
|
||||
data.Unit = unit
|
||||
}
|
||||
if !req.WithData {
|
||||
data.Data = nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user