github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/ces/v1/metricdata/create_metric_data.go (about) 1 package metricdata 2 3 import golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 4 5 type MetricDataItem struct { 6 // Specifies the metric data. 7 Metric MetricInfo `json:"metric" required:"true"` 8 // Specifies the data validity period. 9 // The unit is second. The value range is 0–604,800 seconds. 10 // If the validity period expires, the data will be automatically deleted. 11 Ttl int `json:"ttl" required:"true"` 12 // Specifies when the data was collected. 13 // The time is UNIX timestamp (ms) format. 14 CollectTime int64 `json:"collect_time" required:"true"` 15 // Specifies the monitoring metric data to be added. 16 // The value can be an integer or a floating point number. 17 Value float64 `json:"value" required:"true"` 18 // Specifies the data unit. 19 // Enter a maximum of 32 characters. 20 Unit string `json:"unit,omitempty"` 21 // Specifies the enumerated type. 22 // Possible values: 23 // int 24 // float 25 Type string `json:"type,omitempty"` 26 } 27 28 type MetricInfo struct { 29 // Specifies the metric dimension. A maximum of three dimensions are supported. 30 Dimensions []MetricsDimension `json:"dimensions" required:"true"` 31 // Specifies the metric ID. For example, if the monitoring metric of an ECS is CPU usage, metric_name is cpu_util. 32 MetricName string `json:"metric_name" required:"true"` 33 // Query the namespace of a service. 34 Namespace string `json:"namespace" required:"true"` 35 } 36 37 type MetricsDimension struct { 38 // Specifies the dimension. For example, the ECS dimension is instance_id. 39 // For details about the dimension of each service, see the key column in Services Interconnected with Cloud Eye. 40 // Start with a letter. Enter 1 to 32 characters. 41 // Only letters, digits, underscores (_), and hyphens (-) are allowed. 42 Name string `json:"name,omitempty"` 43 // Specifies the dimension value, for example, an ECS ID. 44 // Start with a letter or a digit. Enter 1 to 256 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed. 45 Value string `json:"value,omitempty"` 46 } 47 48 func CreateMetricData(client *golangsdk.ServiceClient, items []MetricDataItem) error { 49 b := make([]map[string]interface{}, len(items)) 50 51 for i, opt := range items { 52 opt, err := golangsdk.BuildRequestBody(opt, "") 53 if err != nil { 54 return err 55 } 56 b[i] = opt 57 } 58 59 // POST /V1.0/{project_id}/metric-data 60 _, err := client.Post(client.ServiceURL("metric-data"), &b, nil, nil) 61 return err 62 }