| 1 | /* |
| 2 | Package metrics provides the ability to retrieve metrics through the Gnocchi API. |
| 3 | |
| 4 | Example of Listing metrics |
| 5 | |
| 6 | listOpts := metrics.ListOpts{ |
| 7 | Limit: 25, |
| 8 | } |
| 9 | |
| 10 | allPages, err := metrics.List(gnocchiClient, listOpts).AllPages() |
| 11 | if err != nil { |
| 12 | panic(err) |
| 13 | } |
| 14 | |
| 15 | allMetrics, err := metrics.ExtractMetrics(allPages) |
| 16 | if err != nil { |
| 17 | panic(err) |
| 18 | } |
| 19 | |
| 20 | for _, metric := range allMetrics { |
| 21 | fmt.Printf("%+v\n", metric) |
| 22 | } |
| 23 | |
| 24 | Example of Getting a metric |
| 25 | |
| 26 | metricID = "9e5a6441-1044-4181-b66e-34e180753040" |
| 27 | metric, err := metrics.Get(gnocchiClient, metricID).Extract() |
| 28 | if err != nil { |
| 29 | panic(err) |
| 30 | } |
| 31 | |
| 32 | Example of Creating a metric and link it to an existing archive policy |
| 33 | |
| 34 | createOpts := metrics.CreateOpts{ |
| 35 | ArchivePolicyName: "low", |
| 36 | Name: "network.incoming.packets.rate", |
| 37 | Unit: "packet/s", |
| 38 | } |
| 39 | metric, err := metrics.Create(gnocchiClient, createOpts).Extract() |
| 40 | if err != nil { |
| 41 | panic(err) |
| 42 | } |
| 43 | |
| 44 | Example of Creating a metric without an archive policy, assuming that Gnocchi has the needed |
| 45 | archive policy rule and can assign the policy automatically |
| 46 | |
| 47 | createOpts := metrics.CreateOpts{ |
| 48 | ResourceID: "1f3a0724-1807-4bd1-81f9-ee18c8ff6ccc", |
| 49 | Name: "memory.usage", |
| 50 | Unit: "MB", |
| 51 | } |
| 52 | metric, err := metrics.Create(gnocchiClient, createOpts).Extract() |
| 53 | if err != nil { |
| 54 | panic(err) |
| 55 | } |
| 56 | |
| 57 | Example of Deleting a Gnocchi metric |
| 58 | |
| 59 | metricID := "01b2953e-de74-448a-a305-c84440697933" |
| 60 | err := metrics.Delete(gnocchiClient, metricID).ExtractErr() |
| 61 | if err != nil { |
| 62 | panic(err) |
| 63 | } |
| 64 | */ |
| 65 | package metricsscip-go gomod github.com/gophercloud/utils . `github.com/gophercloud/utils/gnocchi/metric/v1/metrics`/ |