github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/ces/v1/metricdata/batch_list_metric_data.go (about)

     1  package metricdata
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  type BatchListMetricDataOpts struct {
    10  	// Specifies the metric data. The maximum length of the array is 10.
    11  	Metrics []Metric `json:"metrics" required:"true"`
    12  	// Specifies the start time of the query.
    13  	// The value is a UNIX timestamp and the unit is ms.
    14  	// Set the value of from to at least one period earlier than the current time.
    15  	// Rollup aggregates the raw data generated within a period to the start time of the period.
    16  	// Therefore, if values of from and to are within a period,
    17  	// the query result will be empty due to the rollup failure.
    18  	// You are advised to set from to be at least one period earlier than the current time.
    19  	// Take the 5-minute period as an example. If it is 10:35 now,
    20  	// the raw data generated between 10:30 and 10:35 will be aggregated to 10:30.
    21  	// Therefore, in this example, if the value of period is 5 minutes,
    22  	// the value of from should be 10:30 or earlier.
    23  	From int64 `json:"from" required:"true"`
    24  	// Specifies the end time of the query.
    25  	// The value is a UNIX timestamp and the unit is ms.
    26  	// The value of parameter from must be earlier than that of parameter to.
    27  	To int64 `json:"to" required:"true"`
    28  	// Specifies how often Cloud Eye aggregates data.
    29  	//
    30  	// Possible values are:
    31  	// 1: Cloud Eye performs no aggregation and displays raw data.
    32  	// 300: Cloud Eye aggregates data every 5 minutes.
    33  	// 1200: Cloud Eye aggregates data every 20 minutes.
    34  	// 3600: Cloud Eye aggregates data every 1 hour.
    35  	// 14400: Cloud Eye aggregates data every 4 hours.
    36  	// 86400: Cloud Eye aggregates data every 24 hours.
    37  	Period string `json:"period" required:"true"`
    38  	// Specifies the data rollup method. The following methods are supported:
    39  	//
    40  	// average: Cloud Eye calculates the average value of metric data within a rollup period.
    41  	// max: Cloud Eye calculates the maximum value of metric data within a rollup period.
    42  	// min: Cloud Eye calculates the minimum value of metric data within a rollup period.
    43  	// sum: Cloud Eye calculates the sum of metric data within a rollup period.
    44  	// variance: Cloud Eye calculates the variance value of metric data within a rollup period.
    45  	// The value of filter does not affect the query result of raw data. (The period is 1.)
    46  	Filter string `json:"filter" required:"true"`
    47  }
    48  
    49  type Metric struct {
    50  	// Specifies the metric namespace. Its value must be in the service.item format and can contain 3 to 32 characters.
    51  	// service and item each must be a string that starts with a letter and contains only letters, digits, and underscores (_).
    52  	Namespace string `json:"namespace" required:"true"`
    53  
    54  	// Specifies the metric name. Start with a letter.
    55  	// Enter 1 to 64 characters. Only letters, digits, and underscores (_) are allowed.
    56  	MetricName string `json:"metric_name" required:"true"`
    57  
    58  	// Specifies the list of the metric dimensions.
    59  	Dimensions []MetricsDimension `json:"dimensions" required:"true"`
    60  }
    61  
    62  func BatchListMetricData(client *golangsdk.ServiceClient, opts BatchListMetricDataOpts) ([]BatchMetricData, error) {
    63  	b, err := build.RequestBody(opts, "")
    64  	if err != nil {
    65  		return nil, err
    66  	}
    67  
    68  	// POST /V1.0/{project_id}/batch-query-metric-data
    69  	raw, err := client.Post(client.ServiceURL("batch-query-metric-data"), b, nil, &golangsdk.RequestOpts{
    70  		OkCodes: []int{200},
    71  	})
    72  	if err != nil {
    73  		return nil, err
    74  	}
    75  
    76  	var res []BatchMetricData
    77  	err = extract.IntoSlicePtr(raw.Body, &res, "metrics")
    78  
    79  	return res, err
    80  }
    81  
    82  type BatchMetricData struct {
    83  	// Specifies the metric namespace.
    84  	// The value must be in the service.item format and can contain 3 to 32 characters.
    85  	Namespace string `json:"namespace"`
    86  	// Specifies the metric name. Start with a letter. Enter 1 to 64 characters.
    87  	MetricName string `json:"metric_name"`
    88  	// Specifies the list of metric dimensions.
    89  	Dimensions []MetricsDimension `json:"dimensions"`
    90  	// Specifies the metric data list.
    91  	// Since Cloud Eye rounds up the value of from based on the level of granularity for data query,
    92  	// datapoints may contain more data points than expected.
    93  	Datapoints []DatapointForBatchMetric `json:"datapoints"`
    94  	// Specifies the metric unit.
    95  	Unit string `json:"unit"`
    96  }
    97  
    98  type DatapointForBatchMetric struct {
    99  	// Specifies the maximum value of metric data within a rollup period.
   100  	Max float64 `json:"max"`
   101  	// Specifies the minimum value of metric data within a rollup period.
   102  	Min float64 `json:"min"`
   103  	// Specifies the average value of metric data within a rollup period.
   104  	Average float64 `json:"average"`
   105  	// Specifies the sum of metric data within a rollup period.
   106  	Sum float64 `json:"sum"`
   107  	// Specifies the variance of metric data within a rollup period.
   108  	Variance float64 `json:"variance"`
   109  	// Specifies when the metric is collected. It is a UNIX timestamp in milliseconds.
   110  	Timestamp int64 `json:"timestamp"`
   111  }