github.com/wtfutil/wtf@v0.43.0/modules/newrelic/client/usages.go (about) 1 package newrelic 2 3 import ( 4 "time" 5 ) 6 7 // Usage describes usage over a single time period. 8 type Usage struct { 9 From time.Time `json:"from,omitempty"` 10 To time.Time `json:"to,omitempty"` 11 Usage int `json:"usage,omitempty"` 12 } 13 14 // UsageData represents usage data for a product over a time frame, including 15 // a slice of Usages. 16 type UsageData struct { 17 Product string `json:"product,omitempty"` 18 From time.Time `json:"from,omitempty"` 19 To time.Time `json:"to,omitempty"` 20 Unit string `json:"unit,omitempty"` 21 Usages []Usage `json:"usages,omitempty"` 22 } 23 24 type usageParams struct { 25 Start time.Time 26 End time.Time 27 IncludeSubaccount bool 28 } 29 30 func (o *usageParams) String() string { 31 return encodeGetParams(map[string]interface{}{ 32 "start_date": o.Start.Format("2006-01-02"), 33 "end_date": o.End.Format("2006-01-02"), 34 "include_subaccounts": o.IncludeSubaccount, 35 }) 36 } 37 38 // GetUsages will return usage for a product in a given time frame. 39 func (c *Client) GetUsages(product string, start, end time.Time, includeSubaccounts bool) (*UsageData, error) { 40 resp := &struct { 41 UsageData *UsageData `json:"usage_data,omitempty"` 42 }{} 43 options := &usageParams{start, end, includeSubaccounts} 44 err := c.doGet("usages/"+product+".json", options, resp) 45 if err != nil { 46 return nil, err 47 } 48 return resp.UsageData, nil 49 }