Documentation ¶
Index ¶
Constants ¶
const ( // used to specify the event when metrics have been collected MetricsCollectedEvent bus.EventType = iota // used to speicfy the event when emissions for instances have been // calculated EmissionsCalculatedEvent )
Variables ¶
var EmissionUnits = map[string]EmissionUnit{ GCO2eqString: GCO2eqString, }
EmissionUnits Lookup map for listing all the supported emissions as well as deserializing them
var ErrParsingEmissionUnit = errors.New("unsupported EmissionUnit")
ErrParsingEmissionUnit Error parsing the EmissionUnit
var ErrParsingProvider = errors.New("unsupported Provider")
ErrParsingProvider Error parsing the Provider
var ErrParsingResourceType = errors.New("unsupported ResourceType")
ErrParsingResourceType parsing the ResourceType
var ErrParsingResourceUnits = errors.New("unsupported ResourceUnits")
ErrParsingResourceUnits Error parsing the ResourceUnits
var Providers = map[string]Provider{ // contains filtered or unexported fields }
Providers Lookup map for listing all the supported providers as well as deserializing them
var ResourceTypes = map[string]ResourceType{ // contains filtered or unexported fields }
ResourceTypes Lookup map for listing all the supported resources as well as deserializing them
var ResourceUnits = map[string]ResourceUnit{ // contains filtered or unexported fields }
ResourceUnits Lookup map for listing all the supported resource units as well as deserializing them
Functions ¶
This section is empty.
Types ¶
type EmissionUnit ¶
type EmissionUnit string
EmissionUnits Defines the unit of emission of CO2 equivalent
const ( // Grams of carbon per kilowatt hour GCO2eq EmissionUnit = GCO2eqString // Constant string definitions GCO2eqString = "gCO2eq" )
func (EmissionUnit) String ¶
func (e EmissionUnit) String() string
Return the emission unit as string
type Instance ¶
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 }
The instance for which we are collecting the metrics
func NewInstance ¶
Create a new instance. We need both the name and the provider
func (*Instance) PrintPretty ¶
type InstanceStatus ¶
type InstanceStatus string
Used to speicy the state of an instance
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" )
type Metric ¶
type Metric struct { // Unique name for the resource // For instance a virtual machine could have multiple disks attached to it // So the name could be the disk name Name string // The resource type // - Cpu // - Memory // - Storage // - Network ResourceType ResourceType // The resource usage in percentage // It is a value between 0 and 100 Usage float64 // The total amount of unit types // - total amount of vCPUs of a VM // - disk size UnitAmount float64 // The unit type representing this resource // Examples: // - vCPUs: in case of a CPU // - Gb: in case of a Disk // - Gb: in case of Ram Unit ResourceUnit // The energy consumption calculated // for the metric. This is then multiplied // by the pue and grid coefficient to get // the Emissions data Energy float64 // Emissions at a specific point in time Emissions ResourceEmissions // Time of update UpdatedAt time.Time // The resource specific labels Labels Labels }
Metric tracks the uilization and emission of a specific resource
func (*Metric) SetUpdatedAt ¶
func (r *Metric) SetUpdatedAt()
Automatically update the last updated time to now
type Metrics ¶
Represents the metrics for a specific service The key is the unique name of the resource
type Provider ¶
type Provider string
Provider where the resource consumption data is collected from
const ( // Amazon web services API AWS Provider = awsString // Azure cloud API Azure Provider = azureString // Google cloud platform API GCP Provider = gcpString // Prometheus API for baremetal and kubernetes support Prometheus Provider = prometheusString // custom third party providers Custom Provider = customString )
Provider constants
func (*Provider) UnmarshalJSON ¶
Custom deserialization for Provider
type ResourceEmissions ¶
type ResourceEmissions struct { // Current amount of emissions Value float64 // The unit of the emission Unit EmissionUnit }
func NewResourceEmission ¶
func NewResourceEmission(value float64, unit EmissionUnit) ResourceEmissions
New instance of the resource emission
type ResourceType ¶
type ResourceType string
ResourceType The resource type that we are collecting data for
const ( // CPU resource CPU ResourceType = cpuString // Memory resource Memory ResourceType = memoryString // Storage resource Storage ResourceType = storageString // Network resource Network ResourceType = networkString )
func (ResourceType) String ¶
func (rt ResourceType) String() string
Return the resource type as string
func (*ResourceType) UnmarshalJSON ¶
func (rt *ResourceType) UnmarshalJSON(data []byte) error
Custom deserialization for ResourceType
type ResourceUnit ¶
type ResourceUnit string
ResourceUnit The unit of the resource type that we are collecting data for
const ( // vCPU VCPU ResourceUnit = vCPUString // KB: Kilobytes KB ResourceUnit = kbString // MB: Megabytes MB ResourceUnit = mbString // GB: Gigabytes GB ResourceUnit = gbString // TB: Terabytes TB ResourceUnit = tbString // PB: Petabytes PB ResourceUnit = pbString // KBs: Kilobits per second KBs ResourceUnit = kbsString // MBs: Megabits per second MBs ResourceUnit = mbsString // GBs: Gigabits per second GBs ResourceUnit = gbsString // TBs: Terabits per second TBs ResourceUnit = tbsString )
func (ResourceUnit) String ¶
func (ru ResourceUnit) String() string
Returns a string representation of the Resource unit
func (*ResourceUnit) UnmarshalJSON ¶
func (ru *ResourceUnit) UnmarshalJSON(data []byte) error
Custom deserialization for ResourceUnit
type Source ¶
type Source interface { // Stop is the "teardown" that will be used for graceful shutdown Stop(context.Context) error // Fetch is the business logic that should return a list of instances // that have metrics attached to them mainly cpu, memory, storage and network Fetch(context.Context) ([]*Instance, error) }
Source is an interface for fetching metrics that can be calculated