mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
28 lines
621 B
Go
28 lines
621 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
|
||
|
"sort"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func newTimeSeries(value float64, labels map[string]string, timestamp time.Time) prompbmarshal.TimeSeries {
|
||
|
ts := prompbmarshal.TimeSeries{}
|
||
|
ts.Samples = append(ts.Samples, prompbmarshal.Sample{
|
||
|
Value: value,
|
||
|
Timestamp: timestamp.UnixNano() / 1e6,
|
||
|
})
|
||
|
keys := make([]string, 0, len(labels))
|
||
|
for k := range labels {
|
||
|
keys = append(keys, k)
|
||
|
}
|
||
|
sort.Strings(keys)
|
||
|
for _, key := range keys {
|
||
|
ts.Labels = append(ts.Labels, prompbmarshal.Label{
|
||
|
Name: key,
|
||
|
Value: labels[key],
|
||
|
})
|
||
|
}
|
||
|
return ts
|
||
|
}
|