/
results.go
92 lines (75 loc) · 2.31 KB
/
results.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
package metricdata
import (
"github.com/gophercloud/gophercloud"
)
type MetricData struct {
// Specifies the namespace in service.
Namespace string `json:"namespace"`
// The value can be a string of 1 to 64 characters
// and must start with a letter and contain only uppercase
// letters, lowercase letters, digits, and underscores.
MetricName string `json:"metric_name"`
//Specifies the list of the metric dimensions.
Dimensions []map[string]interface{} `json:"dimensions"`
// Specifies the metric data list.
Datapoints []map[string]interface{} `json:"datapoints"`
// Specifies the metric unit.
Unit string `json:"unit"`
}
type MetricDatasResult struct {
gophercloud.Result
}
// ExtractMetricDatas is a function that accepts a result and extracts metric datas.
func (r MetricDatasResult) ExtractMetricDatas() ([]MetricData, error) {
var s struct {
// Specifies the metric data.
MetricDatas []MetricData `json:"metrics"`
}
err := r.ExtractInto(&s)
return s.MetricDatas, err
}
type Datapoint struct {
// 指标值,该字段名称与请求参数中filter使用的查询值相同。
Average float64 `json:"average"`
// 指标采集时间。
Timestamp int `json:"timestamp"`
// 指标单位
Unit string `json:"unit,omitempty"`
}
type EventDataInfo struct {
// 事件类型,例如instance_host_info。
Type string `json:"type"`
// 事件上报时间。
Timestamp int `json:"timestamp"`
// 主机配置信息。
Value string `json:"value"`
}
// This is a auto create Response Object
type EventData struct {
Datapoints []EventDataInfo `json:"datapoints"`
}
type Metricdata struct {
// 指标数据列表。由于查询数据时,云监控会根据所选择的聚合粒度向前取整from参数,所以datapoints中包含的数据点有可能会多于预期。
Datapoints []Datapoint `json:"datapoints"`
// 指标名称,例如弹性云服务器监控指标中的cpu_util。
MetricName string `json:"metric_name"`
}
type AddMetricDataResult struct {
gophercloud.ErrResult
}
type GetEventDataResult struct {
gophercloud.Result
}
type GetResult struct {
gophercloud.Result
}
func (r GetEventDataResult) Extract() (*EventData, error) {
var s *EventData
err := r.ExtractInto(&s)
return s, err
}
func (r GetResult) Extract() (*Metricdata, error) {
var s *Metricdata
err := r.ExtractInto(&s)
return s, err
}