/
models.go
59 lines (43 loc) · 991 Bytes
/
models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package timeseries
import (
"encoding/json"
"time"
"github.com/alexanderzobnin/grafana-zabbix/pkg/zabbix"
)
type TimePoint struct {
Time time.Time
Value *float64
}
func (p *TimePoint) UnmarshalJSON(data []byte) error {
point := &struct {
Time int64
Value *float64
}{}
if err := json.Unmarshal(data, &point); err != nil {
return err
}
p.Value = point.Value
p.Time = time.Unix(point.Time, 0)
return nil
}
type TimeSeries []TimePoint
func NewTimeSeries() TimeSeries {
return make(TimeSeries, 0)
}
func (ts *TimeSeries) Len() int {
return len(*ts)
}
type TimeSeriesData struct {
TS TimeSeries
Meta TimeSeriesMeta
}
type TimeSeriesMeta struct {
Name string
Item *zabbix.Item
// Item update interval. nil means not supported intervals (flexible, schedule, etc)
Interval *time.Duration
// AggValue is using for sorting purposes
AggValue *float64
}
type AggFunc = func(points []TimePoint) *float64
type TransformFunc = func(point TimePoint) TimePoint