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

     1  package metricdata
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     6  )
     7  
     8  type ShowMetricDataOpts struct {
     9  	// Specifies the namespace of a service.
    10  	Namespace string `q:"namespace"`
    11  	// Specifies the metric name.
    12  	MetricName string `q:"metric_name"`
    13  	// Currently, a maximum of three metric dimensions are supported,
    14  	// and the dimensions are numbered from 0 in the dim.{i}=key,value format.
    15  	// The key cannot exceed 32 characters and the value cannot exceed 256 characters.
    16  	// The following dimensions are only examples.
    17  	// For details about whether multiple dimensions are supported,
    18  	// see the dimension description in the monitoring indicator description of each service.
    19  	// Single dimension: dim.0=instance_id,i-12345
    20  	// Multiple dimensions: dim.0=instance_id,i-12345&dim.1=instance_name,i-1234
    21  	Dim0 string `q:"dim.0"`
    22  	Dim1 string `q:"dim.1"`
    23  	Dim2 string `q:"dim.2"`
    24  	// Specifies the data rollup method. The following methods are supported:
    25  	//
    26  	// average: Cloud Eye calculates the average value of metric data within a rollup period.
    27  	// max: Cloud Eye calculates the maximum value of metric data within a rollup period.
    28  	// min: Cloud Eye calculates the minimum value of metric data within a rollup period.
    29  	// sum: Cloud Eye calculates the sum of metric data within a rollup period.
    30  	// variance: Cloud Eye calculates the variance value of metric data within a rollup period.
    31  	Filter string `q:"filter"`
    32  	// Specifies how often Cloud Eye aggregates data.
    33  	//
    34  	// Possible values are:
    35  	// 1: Cloud Eye performs no aggregation and displays raw data.
    36  	// 300: Cloud Eye aggregates data every 5 minutes.
    37  	// 1200: Cloud Eye aggregates data every 20 minutes.
    38  	// 3600: Cloud Eye aggregates data every 1 hour.
    39  	// 14400: Cloud Eye aggregates data every 4 hours.
    40  	// 86400: Cloud Eye aggregates data every 24 hours.
    41  	Period int `q:"period"`
    42  	// Specifies the start time of the query.
    43  	// The value is a UNIX timestamp and the unit is ms.
    44  	// Set the value of from to at least one period earlier than the current time.
    45  	// Rollup aggregates the raw data generated within a period to the start time of the period.
    46  	// Therefore, if values of from and to are within a period,
    47  	// the query result will be empty due to the rollup failure.
    48  	// Take the 5-minute period as an example. If it is 10:35 now,
    49  	// the raw data generated between 10:30 and 10:35 will be aggregated to 10:30.
    50  	// Therefore, in this example, if the value of period is 5 minutes,
    51  	// the value of from should be 10:30 or earlier.
    52  	From string `q:"from"`
    53  	// Specifies the end time of the query.
    54  	To string `q:"to"`
    55  }
    56  
    57  func ShowMetricData(client *golangsdk.ServiceClient, opts ShowMetricDataOpts) (*MetricData, error) {
    58  	url, err := golangsdk.NewURLBuilder().WithEndpoints("metric-data").WithQueryParams(&opts).Build()
    59  	if err != nil {
    60  		return nil, err
    61  	}
    62  
    63  	// GET /V1.0/{project_id}/metric-data
    64  	raw, err := client.Get(client.ServiceURL(url.String()), nil, nil)
    65  	if err != nil {
    66  		return nil, err
    67  	}
    68  
    69  	var res MetricData
    70  	err = extract.Into(raw.Body, &res)
    71  
    72  	return &res, err
    73  }
    74  
    75  type MetricData struct {
    76  	// Specifies the metric data list. For details, see Table 4.
    77  	// Since Cloud Eye rounds up the value of from based on the level of granularity for data query,
    78  	// datapoints may contain more data points than expected.
    79  	Datapoints []Datapoint `json:"datapoints"`
    80  	// Specifies the metric ID. For example, if the monitoring metric of an ECS is CPU usage, metric_name is cpu_util.
    81  	MetricName string `json:"metric_name"`
    82  }
    83  
    84  type Datapoint struct {
    85  	// Specifies the maximum value of metric data within a rollup period.
    86  	Max float64 `json:"max,omitempty"`
    87  	// Specifies the minimum value of metric data within a rollup period.
    88  	Min float64 `json:"min,omitempty"`
    89  	// Specifies the average value of metric data within a rollup period.
    90  	Average float64 `json:"average,omitempty"`
    91  	// Specifies the sum of metric data within a rollup period.
    92  	Sum float64 `json:"sum,omitempty"`
    93  	// Specifies the variance of metric data within a rollup period.
    94  	Variance float64 `json:"variance,omitempty"`
    95  	// Specifies when the metric is collected. It is a UNIX timestamp in milliseconds.
    96  	Timestamp int64 `json:"timestamp"`
    97  	// Specifies the metric unit.
    98  	Unit string `json:"unit,omitempty"`
    99  }