forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instance_stats.go
56 lines (49 loc) · 1.58 KB
/
instance_stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package linodego
import (
"context"
"fmt"
)
// StatsNet represents a network stats object
type StatsNet struct {
In [][]float64 `json:"in"`
Out [][]float64 `json:"out"`
PrivateIn [][]float64 `json:"private_in"`
PrivateOut [][]float64 `json:"private_out"`
}
// StatsIO represents an IO stats object
type StatsIO struct {
IO [][]float64 `json:"io"`
Swap [][]float64 `json:"swap"`
}
// InstanceStatsData represents an instance stats data object
type InstanceStatsData struct {
CPU [][]float64 `json:"cpu"`
IO StatsIO `json:"io"`
NetV4 StatsNet `json:"netv4"`
NetV6 StatsNet `json:"netv6"`
}
// InstanceStats represents an instance stats object
type InstanceStats struct {
Title string `json:"title"`
Data InstanceStatsData `json:"data"`
}
// GetInstanceStats gets the template with the provided ID
func (c *Client) GetInstanceStats(ctx context.Context, linodeID int) (*InstanceStats, error) {
e := fmt.Sprintf("linode/instances/%d/stats", linodeID)
req := c.R(ctx).SetResult(&InstanceStats{})
r, err := coupleAPIErrors(req.Get(e))
if err != nil {
return nil, err
}
return r.Result().(*InstanceStats), nil
}
// GetInstanceStatsByDate gets the template with the provided ID, year, and month
func (c *Client) GetInstanceStatsByDate(ctx context.Context, linodeID int, year int, month int) (*InstanceStats, error) {
e := fmt.Sprintf("linode/instances/%d/stats/%d/%d", linodeID, year, month)
req := c.R(ctx).SetResult(&InstanceStats{})
r, err := coupleAPIErrors(req.Get(e))
if err != nil {
return nil, err
}
return r.Result().(*InstanceStats), nil
}