Debian Codegraph @

fastly/realtime_stats.go

raw symbols SCIP
1 package fastly
2
3 import "fmt"
4
5 // RealtimeStats is a response from Fastly's real-time analytics endpoint
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 // RealtimeData represents combined stats for all Fastly's POPs and aggregate of them.
14 // It also includes a timestamp of when the stats were recorded
15 type RealtimeData struct {
16 Datacenter map[string]*Stats `mapstructure:"datacenter"`
17 Aggregated *Stats `mapstructure:"aggregated"`
18 Recorded uint64 `mapstructure:"recorded"`
19 }
20
21 // GetRealtimeStatsInput is an input parameter to GetRealtimeStats function
22 type GetRealtimeStatsInput struct {
23 Service string
24 Timestamp uint64
25 Limit uint32
26 }
27
28 // GetRealtimeStats returns realtime stats for a service based on the GetRealtimeStatsInput
29 // parameter. The realtime stats work in a rolling fasion where first request will return
30 // a timestamp which should be passed to consequentive call and so on.
31 // More details at https://docs.fastly.com/api/analytics
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 }