-
Notifications
You must be signed in to change notification settings - Fork 3
/
instance.go
81 lines (68 loc) · 1.91 KB
/
instance.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package rds
import (
tea "github.com/charmbracelet/bubbletea"
"github.com/danielcmessias/sawsy/data"
"github.com/danielcmessias/sawsy/ui/components/chart/histogram"
"github.com/danielcmessias/sawsy/ui/components/page"
"github.com/danielcmessias/sawsy/ui/context"
)
type InstancePageModel struct {
page.Model
}
type InstancePageContext struct {
InstanceId string
}
func NewInstancePage(ctx *context.ProgramContext) *InstancePageModel {
return &InstancePageModel{
Model: page.New(ctx, instanceSpecPage),
}
}
func (m *InstancePageModel) FetchData(client *data.Client) tea.Cmd {
cmds := []tea.Cmd{
m.fetchDetails(client),
m.fetchTags(client),
}
for i, met := range metrics {
cmds = append(cmds, m.fetchMetric(client, i, met.APIName, met.Formatter))
}
return tea.Batch(cmds...)
}
func (m *InstancePageModel) fetchDetails(client *data.Client) tea.Cmd {
return func() tea.Msg {
rows, _ := client.RDS.GetInstanceDetails(m.Context.(InstancePageContext).InstanceId)
msg := page.NewRowsMsg{
Page: m.Spec.Name,
PaneId: m.GetPaneId("Details"),
Rows: rows,
}
return msg
}
}
func (m *InstancePageModel) fetchTags(client *data.Client) tea.Cmd {
return func() tea.Msg {
rows, _ := client.RDS.GetInstanceTags(m.Context.(InstancePageContext).InstanceId)
msg := page.NewRowsMsg{
Page: m.Spec.Name,
PaneId: m.GetPaneId("Tags"),
Rows: rows,
}
return msg
}
}
func (m *InstancePageModel) fetchMetric(client *data.Client, galleryPaneId int, metric string, valueFormatter func(float64) float64) tea.Cmd {
return func() tea.Msg {
data, _ := client.RDS.GetMetric(m.Context.(InstancePageContext).InstanceId, metric)
if valueFormatter != nil {
for i, d := range data {
data[i] = valueFormatter(d)
}
}
msg := histogram.NewDataMsg{
Page: m.Spec.Name,
PaneId: m.GetPaneId("Monitoring"),
GalleryPaneId: galleryPaneId,
Data: data,
}
return msg
}
}