-
Notifications
You must be signed in to change notification settings - Fork 81
/
instance_stats.go
55 lines (46 loc) · 1.49 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
package linodego
import (
"context"
)
// 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 := formatAPIPath("linode/instances/%d/stats", linodeID)
response, err := doGETRequest[InstanceStats](ctx, c, e)
if err != nil {
return nil, err
}
return response, 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 := formatAPIPath("linode/instances/%d/stats/%d/%d", linodeID, year, month)
response, err := doGETRequest[InstanceStats](ctx, c, e)
if err != nil {
return nil, err
}
return response, nil
}