-
Notifications
You must be signed in to change notification settings - Fork 77
/
models.go
156 lines (131 loc) · 4.02 KB
/
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
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
package funcs
import "fmt"
type PrometheusResponse struct {
Status string `json:"status"`
Data PrometheusData `json:"data"`
}
type PrometheusData struct {
Result []PrometheusResult `json:"result"`
ResultType string `json:"resultType"`
}
type PrometheusResult struct {
Metric map[string]string `json:"metric"`
Values [][]interface{} `json:"values"`
}
type PrometheusQueryObj struct {
Start int64 `json:"start"`
End int64 `json:"end"`
Metric DefaultSortList `json:"metric"`
Values [][]float64 `json:"values"`
}
type PrometheusQueryParam struct {
Start int64 `json:"start"`
End int64 `json:"end"`
PromQl string `json:"prom_ql"`
Data []*PrometheusQueryObj `json:"data"`
}
type ArchiveTable struct {
Endpoint string `json:"endpoint"`
Metric string `json:"metric"`
Tags string `json:"tags"`
UnixTime int64 `json:"unix_time"`
Avg float64 `json:"avg"`
Min float64 `json:"min"`
Max float64 `json:"max"`
P95 float64 `json:"p_95"`
Sum float64 `json:"sum"`
CreateTime string `json:"create_time"`
}
type ArchiveCountQueryObj struct {
Endpoint string `json:"endpoint"`
Metric string `json:"metric"`
}
type PrometheusArchiveTables struct {
TableName string `xorm:"TABLE_NAME"`
}
type MonitorEndpointTable struct {
Guid string `json:"guid"`
ExportType string `json:"export_type"`
Step int `json:"step"`
Address string `json:"address"`
}
type MonitorPromMetricTable struct {
Metric string `json:"metric"`
MetricType string `json:"metric_type"`
PromQl string `json:"prom_ql"`
}
type MonitorMetricTable struct {
Guid string `json:"guid" xorm:"guid"`
Metric string `json:"metric" xorm:"metric"`
MonitorType string `json:"monitor_type" xorm:"monitor_type"`
PromExpr string `json:"prom_expr" xorm:"prom_expr"`
TagOwner string `json:"tag_owner" xorm:"tag_owner"`
ServiceGroup string `json:"service_group" xorm:"service_group"`
Workspace string `json:"workspace" xorm:"workspace"`
UpdateTime string `json:"update_time" xorm:"update_time"`
}
type MonitorArchiveObj struct {
Endpoint string `json:"endpoint"`
Metrics []*MonitorPromMetricTable `json:"metrics"`
}
type ArchiveActionParamObj struct {
Endpoint string `json:"endpoint"`
Metric string `json:"metric"`
PromQl string `json:"prom_ql"`
TableName string `json:"table_name"`
Start int64 `json:"start"`
End int64 `json:"end"`
}
type ArchiveActionList []*ArchiveActionParamObj
type DefaultSortObj struct {
Key string
Value string
}
type DefaultSortList []*DefaultSortObj
func (s DefaultSortList) Len() int {
return len(s)
}
func (s DefaultSortList) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s DefaultSortList) Less(i, j int) bool {
return s[i].Key < s[j].Key
}
func (s DefaultSortList) ToTagString() string {
var output string
for i, v := range s {
output += fmt.Sprintf("%s=\"%s\"", v.Key, v.Value)
if i < len(s)-1 {
output += ","
}
}
return output
}
type HttpRespJson struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}
type ArchiveFiveRowObj struct {
Endpoint string `json:"endpoint"`
Metric string `json:"metric"`
Tags string `json:"tags"`
UnixTime int64 `json:"unix_time"`
Avg []float64 `json:"avg"`
Min []float64 `json:"min"`
Max []float64 `json:"max"`
P95 []float64 `json:"p_95"`
Sum []float64 `json:"sum"`
}
func (a ArchiveFiveRowObj) CalcArchiveTable() ArchiveTable {
tmpAvg, _, _, _, _ := calcData(a.Avg)
_, tmpMin, _, _, _ := calcData(a.Min)
_, _, tmpMax, _, _ := calcData(a.Max)
_, _, _, tmpP95, _ := calcData(a.P95)
_, _, _, _, tmpSum := calcData(a.Sum)
return ArchiveTable{Endpoint: a.Endpoint, Metric: a.Metric, Tags: a.Tags, UnixTime: a.UnixTime, Avg: tmpAvg, Min: tmpMin, Max: tmpMax, P95: tmpP95, Sum: tmpSum}
}
type JobRecordTable struct {
Id int `json:"id"`
HostIp string `json:"host_ip"`
}