Documentation ¶
Overview ¶
Package measures provides the ability to retrieve measures through the Gnocchi API.
Example of Listing measures of a known metric
startTime := time.Date(2018, 1, 4, 10, 0, 0, 0, time.UTC) metricID := "9e5a6441-1044-4181-b66e-34e180753040" listOpts := measures.ListOpts{ Resample: "2h", Granularity: "1h", Start: &startTime, } allPages, err := measures.List(gnocchiClient, metricID, listOpts).AllPages() if err != nil { panic(err) } allMeasures, err := measures.ExtractMeasures(allPages) if err != nil { panic(err) } for _, measure := range allMeasures { fmt.Printf("%+v\n", measure) }
Example of Creating measures inside a single metric
createOpts := measures.CreateOpts{ Measures: []measures.MeasureOpts{ { Timestamp: time.Date(2018, 1, 18, 12, 31, 0, 0, time.UTC), Value: 101.2, }, { Timestamp: time.Date(2018, 1, 18, 14, 32, 0, 0, time.UTC), Value: 102, }, }, } metricID := "9e5a6441-1044-4181-b66e-34e180753040" if err := measures.Create(gnocchiClient, metricID, createOpts).ExtractErr(); err != nil { panic(err) }
Example of Creating measures inside different metrics via metric ID references in a single request
currentTimestamp := time.Now().UTC() pastHourTimestamp := currentTimestamp.Add(-1 * time.Hour) createOpts := measures.BatchCreateMetricsOpts{ { ID: "777a01d6-4694-49cb-b86a-5ba9fd4e609e", Measures: []measures.MeasureOpts{ { Timestamp: ¤tTimestamp, Value: 200, }, { Timestamp: &pastHourTimestamp, Value: 300, }, }, }, { ID: "6dbc97c5-bfdf-47a2-b184-02e7fa348d21", Measures: []measures.MeasureOpts{ { Timestamp: ¤tTimestamp, Value: 111, }, { Timestamp: &pastHourTimestamp, Value: 222, }, }, }, } if err := measures.BatchCreateMetrics(gnocchiClient, createOpts).ExtractErr(); err != nil { panic(err) }
Example of Creating measures inside different metrics via metric names and resource IDs references of that metrics in a single request
currentTimestamp := time.Now().UTC() pastHourTimestamp := currentTimestamp.Add(-1 * time.Hour) createOpts := measures.BatchCreateResourcesMetricsOpts{ CreateMetrics: true, BatchResourcesMetrics: []measures.BatchResourcesMetricsOpts{ { ResourceID: "75274f99-faf6-4112-a6d5-2794cb07c789", ResourcesMetrics: []measures.ResourcesMetricsOpts{ { MetricName: "network.incoming.bytes.rate", ArchivePolicyName: "high", Unit: "B/s", Measures: []measures.MeasureOpts{ { Timestamp: ¤tTimestamp, Value: 1562.82, }, { Timestamp: &pastHourTimestamp, Value: 768.1, }, }, }, { MetricName: "network.outgoing.bytes.rate", ArchivePolicyName: "high", Unit: "B/s", Measures: []measures.MeasureOpts{ { Timestamp: ¤tTimestamp, Value: 273, }, { Timestamp: &pastHourTimestamp, Value: 3141.14, }, }, }, }, }, { ResourceID: "23d5d3f7-9dfa-4f73-b72b-8b0b0063ec55", ResourcesMetrics: []measures.ResourcesMetricsOpts{ { MetricName: "disk.write.bytes.rate", ArchivePolicyName: "low", Unit: "B/s", Measures: []measures.MeasureOpts{ { Timestamp: ¤tTimestamp, Value: 1237, }, { Timestamp: &pastHourTimestamp, Value: 132.12, }, }, }, }, }, }, } if err := measures.BatchCreateResourcesMetrics(gnocchiClient, createOpts).ExtractErr(); err != nil { panic(err) }
Index ¶
- func List(c *gophercloud.ServiceClient, metricID string, opts ListOptsBuilder) pagination.Pager
- type BatchCreateMetricsOpts
- type BatchCreateMetricsOptsBuilder
- type BatchCreateMetricsResult
- type BatchCreateResourcesMetricsOpts
- type BatchCreateResourcesMetricsOptsBuilder
- type BatchCreateResourcesMetricsResult
- type BatchResourcesMetricsOpts
- type CreateOpts
- type CreateOptsBuilder
- type CreateResult
- type ListOpts
- type ListOptsBuilder
- type Measure
- type MeasureOpts
- type MeasurePage
- type MetricOpts
- type ResourcesMetricsOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func List ¶
func List(c *gophercloud.ServiceClient, metricID string, opts ListOptsBuilder) pagination.Pager
List returns a Pager which allows you to iterate over a collection of measures. It accepts a ListOpts struct, which allows you to provide options to a Gnocchi measures List request.
Types ¶
type BatchCreateMetricsOpts ¶
type BatchCreateMetricsOpts []MetricOpts
BatchCreateMetricsOpts specifies a parameters for creating measures for different metrics in a single request.
func (BatchCreateMetricsOpts) ToMeasuresBatchCreateMetricsMap ¶
func (opts BatchCreateMetricsOpts) ToMeasuresBatchCreateMetricsMap() (map[string]interface{}, error)
ToMeasuresBatchCreateMetricsMap constructs a request body from BatchCreateMetricsOpts.
type BatchCreateMetricsOptsBuilder ¶
type BatchCreateMetricsOptsBuilder interface {
ToMeasuresBatchCreateMetricsMap() (map[string]interface{}, error)
}
BatchCreateMetricsOptsBuilder is needed to add measures to the BatchCreateMetrics request.
type BatchCreateMetricsResult ¶
type BatchCreateMetricsResult struct {
gophercloud.ErrResult
}
BatchCreateMetricsResult represents the result of a batch create metrics operation. Call its ExtractErr method to determine if the request succeeded or failed.
func BatchCreateMetrics ¶
func BatchCreateMetrics(client *gophercloud.ServiceClient, opts BatchCreateMetricsOpts) (r BatchCreateMetricsResult)
BatchCreateMetrics requests the creation of a new measures for different metrics.
type BatchCreateResourcesMetricsOpts ¶
type BatchCreateResourcesMetricsOpts struct { // CreateMetrics allows request to create metrics that don't exist yet. CreateMetrics bool `q:"create_metrics"` // BatchResourcesMetrics is a map of resource IDs, metrics names and corresponding measures that needs to be created. BatchResourcesMetrics []BatchResourcesMetricsOpts }
BatchCreateResourcesMetricsOpts specifies a parameters for creating measures inside metrics via resource IDs and metric names.
func (BatchCreateResourcesMetricsOpts) ToMeasuresBatchCreateResourcesMetricsMap ¶
func (opts BatchCreateResourcesMetricsOpts) ToMeasuresBatchCreateResourcesMetricsMap() (map[string]interface{}, error)
ToMeasuresBatchCreateResourcesMetricsMap constructs a request body from the BatchCreateResourcesMetricsOpts.
func (BatchCreateResourcesMetricsOpts) ToMeasuresBatchCreateResourcesMetricsQuery ¶
func (opts BatchCreateResourcesMetricsOpts) ToMeasuresBatchCreateResourcesMetricsQuery() (string, error)
ToMeasuresBatchCreateResourcesMetricsQuery formats the BatchCreateResourcesMetricsOpts into a query string.
type BatchCreateResourcesMetricsOptsBuilder ¶
type BatchCreateResourcesMetricsOptsBuilder interface { // ToMeasuresBatchCreateResourcesMetricsMap builds a request body. ToMeasuresBatchCreateResourcesMetricsMap() (map[string]interface{}, error) // ToMeasuresBatchCreateResourcesMetricsQuery builds a query string. ToMeasuresBatchCreateResourcesMetricsQuery() (string, error) }
BatchCreateResourcesMetricsOptsBuilder is needed to add measures to the BatchCreateResourcesMetrics request.
type BatchCreateResourcesMetricsResult ¶
type BatchCreateResourcesMetricsResult struct {
gophercloud.ErrResult
}
BatchCreateResourcesMetricsResult represents the result of a batch create via resource IDs operation. Call its ExtractErr method to determine if the request succeeded or failed.
func BatchCreateResourcesMetrics ¶
func BatchCreateResourcesMetrics(client *gophercloud.ServiceClient, opts BatchCreateResourcesMetricsOptsBuilder) (r BatchCreateResourcesMetricsResult)
BatchCreateResourcesMetrics requests the creation of new measures inside metrics via resource IDs and metric names.
type BatchResourcesMetricsOpts ¶
type BatchResourcesMetricsOpts struct { // ResourceID uniquely identifies the Gnocchi resource. ResourceID string // ResourcesMetrics specifies metrics whose measures will be updated. ResourcesMetrics []ResourcesMetricsOpts }
BatchResourcesMetricsOpts represents parameters of a single resource of the BatchCreateResourcesMetrics request.
func (BatchResourcesMetricsOpts) ToMap ¶
func (opts BatchResourcesMetricsOpts) ToMap() (map[string]interface{}, error)
ToMap is a helper function to convert individual BatchResourcesMetricsOpts structure into a sub-map.
type CreateOpts ¶
type CreateOpts struct { // Measures is a set of measures for a single metric that needs to be created. Measures []MeasureOpts }
CreateOpts specifies a parameters for creating measures for a single metric.
func (CreateOpts) ToMeasureCreateMap ¶
func (opts CreateOpts) ToMeasureCreateMap() (map[string]interface{}, error)
ToMeasureCreateMap constructs a request body from CreateOpts.
type CreateOptsBuilder ¶
CreateOptsBuilder is needed to add measures to the Create request.
type CreateResult ¶
type CreateResult struct {
gophercloud.ErrResult
}
CreateResult represents the result of a create operation. Call its ExtractErr method to determine if the request succeeded or failed.
func Create ¶
func Create(client *gophercloud.ServiceClient, metricID string, opts CreateOptsBuilder) (r CreateResult)
Create requests the creation of a new measures in the single Gnocchi metric.
type ListOpts ¶
type ListOpts struct { // Refresh can be used to force any unprocessed measures to be handled in the Gnocchi // to ensure that List request returns all aggregates. Refresh bool `q:"refresh"` // Start is a start of time time range for the measures. Start *time.Time // Stop is a stop of time time range for the measures. Stop *time.Time // Aggregation is a needed aggregation method for returned measures. // Gnocchi returns "mean" by default. Aggregation string `q:"aggregation"` // Granularity is a needed time between two series of measures to retreive. // Gnocchi will response with all granularities for available measures by default. Granularity string `q:"granularity"` // Resample allows to select different granularity instead of those that were defined in the // archive policy. Resample string `q:"resample"` }
ListOpts allows to provide additional options to the Gnocchi measures List request.
func (ListOpts) ToMeasureListQuery ¶
ToMeasureListQuery formats a ListOpts into a query string.
type ListOptsBuilder ¶
ListOptsBuilder allows extensions to add additional parameters to the List request.
type Measure ¶
type Measure struct { // Timestamp represents a timestamp of when measure was pushed into the Gnocchi. Timestamp time.Time `json:"-"` // Granularity is a level of precision that is kept when aggregating data. Granularity float64 `json:"-"` // Value represents a value of data that was pushed into the Gnocchi. Value float64 `json:"-"` }
Measure is an datapoint thats is composed with a timestamp and a value.
func ExtractMeasures ¶
func ExtractMeasures(r pagination.Page) ([]Measure, error)
ExtractMeasures interprets the results of a single page from a List() call, producing a slice of Measures structs.
func MapToMeasure ¶
func (*Measure) UnmarshalJSON ¶
UnmarshalJSON helps to unmarshal response from reading Gnocchi measures.
Gnocchi APIv1 returns measures in a such format:
[
[ "2017-01-08T10:00:00+00:00", 300.0, 146.0 ], [ "2017-01-08T10:05:00+00:00", 300.0, 58.0 ]
]
Helper unmarshals every nested array into the Measure type.
type MeasureOpts ¶
type MeasureOpts struct { // Timestamp represents a measure creation timestamp. Timestamp *time.Time `json:"-" required:"true"` // Value represents a measure data value. Value float64 `json:"value"` }
MeasureOpts represents options of a single measure that can be created in the Gnocchi.
func (MeasureOpts) ToMap ¶
func (opts MeasureOpts) ToMap() (map[string]interface{}, error)
ToMap is a helper function to convert individual MeasureOpts structure into a sub-map.
type MeasurePage ¶
type MeasurePage struct {
pagination.SinglePageBase
}
MeasurePage is the page returned by a pager when traversing over a collection of measures.
func (MeasurePage) IsEmpty ¶
func (r MeasurePage) IsEmpty() (bool, error)
IsEmpty checks whether a MeasurePage struct is empty.
type MetricOpts ¶
type MetricOpts struct { // ID uniquely identifies the Gnocchi metric. ID string // Measures is a set of measures for a single metric that needs to be created. Measures []MeasureOpts }
MetricOpts represents measures of a single metric of the BatchCreateMetrics request.
func (MetricOpts) ToMap ¶
func (opts MetricOpts) ToMap() (map[string]interface{}, error)
ToMap is a helper function to convert individual MetricOpts structure into a sub-map.
type ResourcesMetricsOpts ¶
type ResourcesMetricsOpts struct { // MetricName is a human-readable name for the Gnocchi metric. MetricName string // ArchivePolicyName is a name of the Gnocchi archive policy that describes // the aggregate storage policy of a metric. ArchivePolicyName string // Unit is a unit of measurement for measures of that Gnocchi metric. Unit string // Measures is a set of measures for a single metric that needs to be created. Measures []MeasureOpts }
ResourcesMetricsOpts represents measures of a single metric of the resource from BatchResourcesMetricsOpts.
func (ResourcesMetricsOpts) ToMap ¶
func (opts ResourcesMetricsOpts) ToMap() (map[string]interface{}, error)
ToMap is a helper function to convert individual ResourcesMetricsOpts structure into a sub-map.