v1

package
v0.0.1-alpha.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var EmissionUnits = map[string]EmissionUnit{
	GCO2eqString: GCO2eqString,
}

EmissionUnits Lookup map for listing all the supported emissions as well as deserializing them

View Source
var ErrParsingEmissionUnit = errors.New("unsupported EmissionUnit")

ErrParsingEmissionUnit Error parsing the EmissionUnit

View Source
var ErrParsingProvider = errors.New("unsupported Provider")

ErrParsingProvider Error parsing the Provider

View Source
var ErrParsingResourceType = errors.New("unsupported ResourceType")

ErrParsingResourceType parsing the ResourceType

View Source
var ErrParsingResourceUnits = errors.New("unsupported ResourceUnits")

ErrParsingResourceUnits Error parsing the ResourceUnits

View Source
var Providers = map[string]Provider{
	// contains filtered or unexported fields
}

Providers Lookup map for listing all the supported providers as well as deserializing them

View Source
var ResourceTypes = map[string]ResourceType{
	// contains filtered or unexported fields
}

ResourceTypes Lookup map for listing all the supported resources as well as deserializing them

View Source
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

func NewInstance(name string, provider Provider) *Instance

Create a new instance. We need both the name and the provider

func (*Instance) PrintPretty

func (i *Instance) PrintPretty(ctx context.Context)

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 Labels

type Labels map[string]string

Labels definition

func (*Labels) Add

func (l *Labels) Add(key, value string)

Helper method for adding a label

func (*Labels) Delete

func (l *Labels) Delete(key string)

Helper method for deleting a specific label

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 NewMetric

func NewMetric(name string) *Metric

Creates a new metric

func (*Metric) SetUpdatedAt

func (r *Metric) SetUpdatedAt()

Automatically update the last updated time to now

func (*Metric) String

func (r *Metric) String() string

Creates a string representation for the resource Useful for logging or debugging

type Metrics

type Metrics map[string]Metric

Represents the metrics for a specific service The key is the unique name of the resource

func (*Metrics) Upsert

func (m *Metrics) Upsert(metric *Metric)

Helper method for adding a specific metric

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) String

func (p Provider) String() string

Return the provider as string

func (*Provider) UnmarshalJSON

func (p *Provider) UnmarshalJSON(data []byte) error

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 Scheduler

type Scheduler interface {

	// Schedule the scraping of the provider data
	Schedule(ctx context.Context)

	// Cancel the scraping of the provider data
	Cancel()
}

type Scraper

type Scraper interface {
	Start(context.Context)
	Stop(context.Context)
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL