v1

package
v0.0.1-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 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{
	GCO2eqkWhString: GCO2eqkWhString,
}

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
	GCO2eqkWh EmissionUnit = GCO2eqkWhString

	// Constant string definitions
	GCO2eqkWhString = "gCO2eqkWh"
)

func (EmissionUnit) String

func (e EmissionUnit) String() string

Return the emission unit as string

func (*EmissionUnit) UnmarshalJSON

func (e *EmissionUnit) UnmarshalJSON(data []byte) error

Custom deserialization for EmissionUnit

type Instance

type Instance struct {

	// 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

	// The metrics collection for the specific service
	Metrics Metrics

	// The CPU emissions of the service during operation
	OperationalCPUEmissions ResourceEmissions

	// 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) AddLabel

func (i *Instance) AddLabel(key, value string)

Insert a label to the service

func (*Instance) PrintPretty

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

func (*Instance) UpsertMetric

func (i *Instance) UpsertMetric(resource *Metric)

Upsert the metric for the resource

type Labels

type Labels map[string]string

Labels definition

func (Labels) Add

func (labels Labels) Add(key, value string)

Helper method for adding a label

func (Labels) Delete

func (labels Labels) Delete(key string)

Helper method for deleting a specific label

func (Labels) Exists

func (labels Labels) Exists(key string) bool

Helper method for getting a specific label

func (Labels) Get

func (labels Labels) Get(key string) (string, bool)

Helper method for getting 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

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

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 Resource

type Resource struct {
	// The resource ID
	ID string

	// The name
	Name string

	// The region where the resource is located
	Region string

	// The service the resource belongs to
	Service string

	// For example spot, reserved
	Lifecycle string

	// Amount of vCPUs
	VCPUCount int

	// The instance kind for example
	Kind string

	// When was the last time it was updated
	LastUpdated time.Time
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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