Documentation ¶
Overview ¶
Package metrics provides the ability to retrieve metrics through the Gnocchi API.
Example of Listing metrics
listOpts := metrics.ListOpts{ Limit: 25, } allPages, err := metrics.List(gnocchiClient, listOpts).AllPages() if err != nil { panic(err) } allMetrics, err := metrics.ExtractMetrics(allPages) if err != nil { panic(err) } for _, metric := range allMetrics { fmt.Printf("%+v\n", metric) }
Example of Getting a metric
metricID = "9e5a6441-1044-4181-b66e-34e180753040" metric, err := metrics.Get(gnocchiClient, metricID).Extract() if err != nil { panic(err) }
Example of Creating a metric and link it to an existing archive policy
createOpts := metrics.CreateOpts{ ArchivePolicyName: "low", Name: "network.incoming.packets.rate", Unit: "packet/s", } metric, err := metrics.Create(gnocchiClient, createOpts).Extract() if err != nil { panic(err) }
Example of Creating a metric without an archive policy, assuming that Gnocchi has the needed archive policy rule and can assign the policy automatically
createOpts := metrics.CreateOpts{ ResourceID: "1f3a0724-1807-4bd1-81f9-ee18c8ff6ccc", Name: "memory.usage", Unit: "MB", } metric, err := metrics.Create(gnocchiClient, createOpts).Extract() if err != nil { panic(err) }
Example of Deleting a Gnocchi metric
metricID := "01b2953e-de74-448a-a305-c84440697933" err := metrics.Delete(gnocchiClient, metricID).ExtractErr() if err != nil { panic(err) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func List ¶
func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
List returns a Pager which allows you to iterate over a collection of metrics. It accepts a ListOpts struct, which allows you to limit and sort the returned collection for a greater efficiency.
Types ¶
type CreateOpts ¶
type CreateOpts struct { // ArchivePolicyName is a name of the Gnocchi archive policy that describes // the aggregate storage policy of a metric. // You can omit it in the request if your Gnocchi installation has the needed // archive policy rule to assign an archive policy by a metric's name. ArchivePolicyName string `json:"archive_policy_name,omitempty"` // Name is a human-readable name for the Gnocchi metric. // You must provide it if you are also providing a ResourceID in the request. Name string `json:"name,omitempty"` // ResourceID identifies the associated Gnocchi resource of the metric. ResourceID string `json:"resource_id,omitempty"` // Unit is a unit of measurement for measures of that Gnocchi metric. Unit string `json:"unit,omitempty"` }
CreateOpts specifies parameters of a new Gnocchi metric.
func (CreateOpts) ToMetricCreateMap ¶
func (opts CreateOpts) ToMetricCreateMap() (map[string]interface{}, error)
ToMetricCreateMap constructs a request body from CreateOpts.
type CreateOptsBuilder ¶
CreateOptsBuilder allows to add additional parameters to the Create request.
type CreateResult ¶
type CreateResult struct {
// contains filtered or unexported fields
}
CreateResult represents the result of a create operation. Call its Extract method to interpret it as a Gnocchi metric.
func Create ¶
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)
Create requests the creation of a new Gnocchi metric on the server.
type DeleteResult ¶
type DeleteResult struct {
gophercloud.ErrResult
}
DeleteResult represents the result of a delete operation. Call its ExtractErr method to determine if the request succeeded or failed.
func Delete ¶
func Delete(c *gophercloud.ServiceClient, metricID string) (r DeleteResult)
Delete accepts a unique ID and deletes the Gnocchi metric associated with it.
type GetResult ¶
type GetResult struct {
// contains filtered or unexported fields
}
GetResult represents the result of a get operation. Call its Extract method to interpret it as a metric.
func Get ¶
func Get(c *gophercloud.ServiceClient, metricID string) (r GetResult)
Get retrieves a specific Gnocchi metric based on its id.
type ListOpts ¶
type ListOpts struct { // Limit allows to limits count of metrics in the response. Limit int `q:"limit"` // Marker is used for pagination. Marker string `q:"marker"` // SortKey allows to sort metrics in the response by key. SortKey string `q:"sort_key"` // SortDir allows to set the direction of sorting. // Can be `asc` or `desc`. SortDir string `q:"sort_dir"` // Creator shows who created the metric. // Usually it contains concatenated string with values from // "created_by_user_id" and "created_by_project_id" fields. Creator string `json:"creator"` // ProjectID is the Identity project of the metric. ProjectID string `json:"project_id"` // UserID is the Identity user of the metric. UserID string `json:"user_id"` }
ListOpts allows the limiting and sorting of paginated collections through the Gnocchi API.
func (ListOpts) ToMetricListQuery ¶
ToMetricListQuery formats a ListOpts into a query string.
type ListOptsBuilder ¶
ListOptsBuilder allows extensions to add additional parameters to the List request.
type Metric ¶
type Metric struct { // ArchivePolicy is a Gnocchi archive policy that describes the aggregate // storage policy of a metric. ArchivePolicy archivepolicies.ArchivePolicy `json:"archive_policy"` // ArchivePolicyName is a name of the Gnocchi archive policy that describes // the aggregate storage policy of a metric. // Usually that field is not empty if a Metric struct is a result // from a create request. ArchivePolicyName string `json:"archive_policy_name"` // CreatedByProjectID contains the id of the Identity project that // was used for a metric creation. CreatedByProjectID string `json:"created_by_project_id"` // CreatedByUserID contains the id of the Identity user // that created the Gnocchi metric. CreatedByUserID string `json:"created_by_user_id"` // Creator shows who created the metric. // Usually it contains concatenated string with values from // "created_by_user_id" and "created_by_project_id" fields. Creator string `json:"creator"` // ID uniquely identifies the Gnocchi metric. ID string `json:"id"` // Name is a human-readable name for the Gnocchi metric. Name string `json:"name"` // ResourceID identifies the associated Gnocchi resource of the metric. ResourceID string `json:"resource_id"` // Resource is a Gnocchi resource representation. Resource resources.Resource `json:"resource"` // Unit is a unit of measurement for measures of that Gnocchi metric. Unit string `json:"unit"` }
Metric is an entity storing aggregates identified by an UUID. It can be attached to a resource using a name. How a metric stores its aggregates is defined by the archive policy it is associated to.
func ExtractMetrics ¶
func ExtractMetrics(r pagination.Page) ([]Metric, error)
ExtractMetrics interprets the results of a single page from a List() call, producing a slice of Metric structs.
type MetricPage ¶
type MetricPage struct {
pagination.MarkerPageBase
}
MetricPage is the page returned by a pager when traversing over a collection of metrics.
func (MetricPage) IsEmpty ¶
func (r MetricPage) IsEmpty() (bool, error)
IsEmpty checks whether a MetricPage struct is empty.
func (MetricPage) LastMarker ¶
func (r MetricPage) LastMarker() (string, error)
LastMarker returns the last metric ID in a ListResult.