| 1 |
package fastly |
| 2 |
|
| 3 |
import "fmt" |
| 4 |
|
| 5 |
|
| 6 |
type RealtimeStatsResponse struct { |
| 7 |
Timestamp uint64 `mapstructure:"Timestamp"` |
| 8 |
Data []*RealtimeData `mapstructure:"Data"` |
| 9 |
Error string `mapstructure:"Error"` |
| 10 |
AggregateDelay uint32 `mapstructure:"AggregateDelay"` |
| 11 |
} |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
type RealtimeData struct { |
| 16 |
Datacenter map[string]*Stats `mapstructure:"datacenter"` |
| 17 |
Aggregated *Stats `mapstructure:"aggregated"` |
| 18 |
Recorded uint64 `mapstructure:"recorded"` |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
type GetRealtimeStatsInput struct { |
| 23 |
Service string |
| 24 |
Timestamp uint64 |
| 25 |
Limit uint32 |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
func (c *RTSClient) GetRealtimeStats(i *GetRealtimeStatsInput) (*RealtimeStatsResponse, error) { |
| 33 |
if i.Service == "" { |
| 34 |
return nil, ErrMissingService |
| 35 |
} |
| 36 |
|
| 37 |
path := fmt.Sprintf("/v1/channel/%s/ts/%d", i.Service, i.Timestamp) |
| 38 |
|
| 39 |
if i.Limit != 0 { |
| 40 |
path = fmt.Sprintf("%s/limit/%d", path, i.Limit) |
| 41 |
} |
| 42 |
|
| 43 |
resp, err := c.client.Get(path, nil) |
| 44 |
if err != nil { |
| 45 |
return nil, err |
| 46 |
} |
| 47 |
|
| 48 |
var s *RealtimeStatsResponse |
| 49 |
if err := decodeJSON(&s, resp.Body); err != nil { |
| 50 |
return nil, err |
| 51 |
} |
| 52 |
return s, nil |
| 53 |
} |