-
Notifications
You must be signed in to change notification settings - Fork 3
/
storage.go
71 lines (64 loc) · 2.45 KB
/
storage.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
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2016,2017,2018 Yaacov Zamir <[email protected]>
// and other contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package storage interface for metric data storage
package storage
import (
"net/url"
)
// Tenant just the tenant name
type Tenant struct {
ID string `json:"id"`
}
// Item one metric item
type Item struct {
ID string `json:"id" bson:"_id"`
Type string `json:"type" bson:"type"`
Tags map[string]string `json:"tags" bson:"tags"`
LastValues []DataItem `json:"data,omitempty" bson:"data,omitempty"`
}
// DataItem one metric data point
type DataItem struct {
Timestamp int64 `json:"timestamp" bson:"timestamp"`
Value float64 `json:"value" bson:"value"`
}
// StatItem one statistics data point
type StatItem struct {
Start int64 `json:"start"`
End int64 `json:"end"`
Empty bool `json:"empty"`
Samples int64 `json:"samples,omitempty"`
Min float64 `json:"min,omitempty"`
Max float64 `json:"max,omitempty"`
First float64 `json:"first,omitempty"`
Last float64 `json:"last,omitempty"`
Avg float64 `json:"avg,omitempty"`
Median float64 `json:"median,omitempty"`
Std float64 `json:"std,omitempty"`
Sum float64 `json:"sum,omitempty"`
}
// Storage metric data interface
type Storage interface {
Name() string
Help() string
Open(options url.Values)
GetTenants() ([]Tenant, error)
GetItemList(tenant string, tags map[string]string) ([]Item, error)
GetRawData(tenant string, id string, end int64, start int64, limit int64, order string) ([]DataItem, error)
GetStatData(tenant string, id string, end int64, start int64, limit int64, order string, bucketDuration int64) ([]StatItem, error)
PostRawData(tenant string, id string, t int64, v float64) error
PutTags(tenant string, id string, tags map[string]string) error
DeleteData(tenant string, id string, end int64, start int64) error
DeleteTags(tenant string, id string, tags []string) error
}