forked from open-falcon/falcon-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.go
168 lines (144 loc) · 4.34 KB
/
graph.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Copyright 2017 Xiaomi, Inc.
//
// 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 model
import (
"fmt"
"math"
MUtils "github.com/open-falcon/falcon-plus/common/utils"
)
// DsType 即RRD中的Datasource的类型:GAUGE|COUNTER|DERIVE
type GraphItem struct {
Endpoint string `json:"endpoint"`
Metric string `json:"metric"`
Tags map[string]string `json:"tags"`
Value float64 `json:"value"`
Timestamp int64 `json:"timestamp"`
DsType string `json:"dstype"`
Step int `json:"step"`
Heartbeat int `json:"heartbeat"`
Min string `json:"min"`
Max string `json:"max"`
}
func (this *GraphItem) String() string {
return fmt.Sprintf(
"<Endpoint:%s, Metric:%s, Tags:%v, Value:%v, TS:%d %v DsType:%s, Step:%d, Heartbeat:%d, Min:%s, Max:%s>",
this.Endpoint,
this.Metric,
this.Tags,
this.Value,
this.Timestamp,
MUtils.UnixTsFormat(this.Timestamp),
this.DsType,
this.Step,
this.Heartbeat,
this.Min,
this.Max,
)
}
func (this *GraphItem) PrimaryKey() string {
return MUtils.PK(this.Endpoint, this.Metric, this.Tags)
}
func (t *GraphItem) Checksum() string {
return MUtils.Checksum(t.Endpoint, t.Metric, t.Tags)
}
func (this *GraphItem) UUID() string {
return MUtils.UUID(this.Endpoint, this.Metric, this.Tags, this.DsType, this.Step)
}
type GraphDeleteParam struct {
Endpoint string `json:"endpoint"`
Metric string `json:"metric"`
Step int `json:"step"`
DsType string `json:"dstype"`
Tags string `json:"tags"`
}
type GraphDeleteResp struct {
}
// ConsolFun 是RRD中的概念,比如:MIN|MAX|AVERAGE
type GraphQueryParam struct {
Start int64 `json:"start"`
End int64 `json:"end"`
ConsolFun string `json:"consolFuc"`
Endpoint string `json:"endpoint"`
Counter string `json:"counter"`
Step int `json:"step"`
}
type GraphQueryResponse struct {
Endpoint string `json:"endpoint"`
Counter string `json:"counter"`
DsType string `json:"dstype"`
Step int `json:"step"`
Values []*RRDData `json:"Values"` //大写为了兼容已经再用这个api的用户
}
// 页面上已经可以看到DsType和Step了,直接带进查询条件,Graph更易处理
type GraphAccurateQueryParam struct {
Checksum string `json:"checksum"`
Start int64 `json:"start"`
End int64 `json:"end"`
ConsolFun string `json:"consolFuc"`
DsType string `json:"dsType"`
Step int `json:"step"`
}
type GraphAccurateQueryResponse struct {
Values []*RRDData `json:"values"`
}
type JsonFloat float64
func (v JsonFloat) MarshalJSON() ([]byte, error) {
f := float64(v)
if math.IsNaN(f) || math.IsInf(f, 0) {
return []byte("null"), nil
} else {
return []byte(fmt.Sprintf("%f", f)), nil
}
}
type RRDData struct {
Timestamp int64 `json:"timestamp"`
Value JsonFloat `json:"value"`
}
func NewRRDData(ts int64, val float64) *RRDData {
return &RRDData{Timestamp: ts, Value: JsonFloat(val)}
}
func (this *RRDData) String() string {
return fmt.Sprintf(
"<RRDData:Value:%v TS:%d %v>",
this.Value,
this.Timestamp,
MUtils.UnixTsFormat(this.Timestamp),
)
}
type GraphInfoParam struct {
Endpoint string `json:"endpoint"`
Counter string `json:"counter"`
}
type GraphInfoResp struct {
ConsolFun string `json:"consolFun"`
Step int `json:"step"`
Filename string `json:"filename"`
}
type GraphFullyInfo struct {
Endpoint string `json:"endpoint"`
Counter string `json:"counter"`
ConsolFun string `json:"consolFun"`
Step int `json:"step"`
Filename string `json:"filename"`
Addr string `json:"addr"`
}
type GraphLastParam struct {
Endpoint string `json:"endpoint"`
Counter string `json:"counter"`
}
type GraphLastResp struct {
Endpoint string `json:"endpoint"`
Counter string `json:"counter"`
Value *RRDData `json:"value"`
}