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

     1  package metrics
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/pagination"
     6  )
     7  
     8  type ListMetricsRequest struct {
     9  	// Specifies the dimension. For example, the ECS dimension is instance_id.
    10  	// For details about each service dimension, see Services Interconnected with Cloud Eye.
    11  	// A maximum of three dimensions are supported,
    12  	// and the dimensions are numbered from 0 in dim.{i}=key,value format.
    13  	// The key cannot exceed 32 characters and the value cannot exceed 256 characters.
    14  	// Single dimension: dim.0=instance_id,6f3c6f91-4b24-4e1b-b7d1-a94ac1cb011d
    15  	// Multiple dimensions: dim.0=key,value&dim.1=key,value。
    16  	Dim string `q:"dim,omitempty"`
    17  	// The value ranges from 1 to 1000, and is 1000 by default.
    18  	// This parameter is used to limit the number of query results.
    19  	Limit *int `q:"limit,omitempty"`
    20  	// Specifies the metric ID. For example, if the monitoring metric of an ECS is CPU usage, metric_name is cpu_util.
    21  	MetricName string `q:"metric_name,omitempty"`
    22  	// Query the namespace of a service.
    23  	Namespace string `q:"namespace,omitempty"`
    24  	// Specifies the result sorting method, which is sorted by timestamp.
    25  	// The default value is desc.
    26  	// asc: The query results are displayed in the ascending order.
    27  	// desc: The query results are displayed in the descending order.
    28  	Order string `q:"order,omitempty"`
    29  	// Specifies the paging start value.
    30  	// The format is namespace.metric_name.key:value.
    31  	Start string `q:"start,omitempty"`
    32  }
    33  
    34  type ListMetricsBuilder interface {
    35  	ToMetricsListMap() (string, error)
    36  }
    37  
    38  func (opts ListMetricsRequest) ToMetricsListMap() (string, error) {
    39  	s, err := golangsdk.BuildQueryString(&opts)
    40  	if err != nil {
    41  		return "", err
    42  	}
    43  	return s.String(), err
    44  }
    45  
    46  func ListMetrics(client *golangsdk.ServiceClient, opts ListMetricsBuilder) pagination.Pager {
    47  	url := metricsURL(client)
    48  	if opts != nil {
    49  		query, err := opts.ToMetricsListMap()
    50  		if err != nil {
    51  			return pagination.Pager{Err: err}
    52  		}
    53  		url += query
    54  	}
    55  
    56  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
    57  		return MetricsPage{pagination.LinkedPageBase{PageResult: r}}
    58  	})
    59  }