-
Notifications
You must be signed in to change notification settings - Fork 3
/
instance.go
102 lines (81 loc) · 2 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package v1
import (
"context"
"fmt"
"log/slog"
"github.com/re-cinq/aether/pkg/log"
)
// Used to speicy the state of an instance
type InstanceStatus string
const (
// Instance is currently functioning
InstancePending InstanceStatus = "pending"
// Instance is currently functioning
InstanceRunning InstanceStatus = "running"
// Instance has been terminated and will be removed from the system
InstanceTerminated InstanceStatus = "terminated"
)
// The instance for which we are collecting the metrics
type Instance struct {
// unique identifier
ID string
// The provider used as source for this metric
Provider Provider
// The service type (Instance, Database etc..)
Service string
// Unique name of the instance
// Can be the VM name
Name string
// The region of the instance
// Examples:
// - europe-west4 (GCP)
// - us-east-2 (AWS)
// - eu-east-rack-1 (Baremetal)
Region string
// The instance zone
// - europe-west4-a (GCP)
Zone string
// This is the kind of service
// Examples for VMs:
// - n2-standard-8 (GCP)
// - m6.2xlarge (AWS)
Kind string
// Status of the instance
Status InstanceStatus
// The metrics collection for the specific service
// Operational emissions are stored here
Metrics Metrics
// The embodied emissions for the service
EmbodiedEmissions ResourceEmissions
// Labels associated with the service
Labels Labels
}
// Create a new instance.
// We need both the name and the provider
func NewInstance(name string, provider Provider) *Instance {
// Make sure the instance name is set
if name == "" {
slog.Error("failed to create service, got an empty name")
return nil
}
// Build the instance
return &Instance{
Name: name,
Provider: provider,
Metrics: Metrics{},
Labels: Labels{},
}
}
func (i *Instance) PrintPretty(ctx context.Context) {
logger := log.FromContext(ctx)
for _, m := range i.Metrics {
logger.Debug(fmt.Sprintf(
"Collected metric: %s %s %s %s | %s",
i.Service,
i.Region,
i.Name,
i.Kind,
m.String(),
))
}
}