compute

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NextScrapeDesc = prometheus.NewDesc(
		prometheus.BuildFQName(cloudcost_exporter.ExporterName, subsystem, "next_scrape"),
		"Next time GCP's compute submodule pricing map will be refreshed as unix timestamp",
		nil,
		nil,
	)
	InstanceCPUHourlyCostDesc = prometheus.NewDesc(
		prometheus.BuildFQName(cloudcost_exporter.MetricPrefix, subsystem, "instance_cpu_usd_per_core_hour"),
		"The cpu cost a GCP Compute Instance in USD/(core*h)",
		[]string{"instance", "region", "family", "machine_type", "project", "price_tier"},
		nil,
	)
	InstanceMemoryHourlyCostDesc = prometheus.NewDesc(
		prometheus.BuildFQName(cloudcost_exporter.MetricPrefix, subsystem, "instance_ram_usd_per_gib_hour"),
		"The memory cost of a GCP Compute Instance in USD/(GiB*h)",
		[]string{"instance", "region", "family", "machine_type", "project", "price_tier"},
		nil,
	)
)
View Source
var (
	GkeClusterLabel = "goog-k8s-cluster-name"
	GkeRegionLabel  = "goog-k8s-cluster-location"
)
View Source
var (
	SkuNotFound        = errors.New("no sku was interested in us")
	SkuIsNil           = errors.New("sku is nil")
	SkuNotParsable     = errors.New("can't parse sku")
	SkuNotRelevant     = errors.New("sku isn't relevant for the current use cases")
	PricingDataIsOff   = errors.New("pricing data in sku isn't parsable")
	RegionNotFound     = errors.New("region wasn't found in pricing map")
	FamilyTypeNotFound = errors.New("family wasn't found in pricing map for this region")
)
View Source
var (
	ListInstancesError = errors.New("no list price was found for the sku")
)

Functions

This section is empty.

Types

type Collector

type Collector struct {
	PricingMap *StructuredPricingMap

	Projects   []string
	NextScrape time.Time
	// contains filtered or unexported fields
}

Collector implements the Collector interface for compute services in Compute.

func New

func New(config *Config, computeService *compute.Service, billingService *billingv1.CloudCatalogClient) *Collector

New is a helper method to properly set up a compute.Collector struct.

func (*Collector) CheckReadiness added in v0.3.0

func (c *Collector) CheckReadiness() bool

func (*Collector) Collect

func (c *Collector) Collect(ch chan<- prometheus.Metric) error

func (*Collector) CollectMetrics

func (c *Collector) CollectMetrics(ch chan<- prometheus.Metric) float64

func (*Collector) Describe

func (c *Collector) Describe(ch chan<- *prometheus.Desc) error

func (*Collector) Name

func (c *Collector) Name() string

Name returns a well formatted string for the name of the collector. Helpful for logging

func (*Collector) Register

func (c *Collector) Register(registry provider.Registry) error

type Config

type Config struct {
	Projects       string
	ScrapeInterval time.Duration
}

type FamilyPricing

type FamilyPricing struct {
	Family map[string]*PriceTiers
}

FamilyPricing is a map where the key is the family and the value is the price tiers

func NewMachineTypePricing

func NewMachineTypePricing() *FamilyPricing

type MachineSpec

type MachineSpec struct {
	Instance     string
	Zone         string
	Region       string
	Family       string
	MachineType  string
	SpotInstance bool
	Labels       map[string]string
	PriceTier    string
}

MachineSpec is a slimmed down representation of a google compute.Instance struct

func ListInstancesInZone

func ListInstancesInZone(projectID, zone string, c *compute.Service) ([]*MachineSpec, error)

ListInstancesInZone will list all instances in a given zone and return a slice of MachineSpecs

func NewMachineSpec

func NewMachineSpec(instance *compute.Instance) *MachineSpec

NewMachineSpec will create a new MachineSpec from compute.Instance objects. It's responsible for determining the machine family and region that it operates in

func (*MachineSpec) GetClusterName

func (m *MachineSpec) GetClusterName() string

type ParsedSkuData

type ParsedSkuData struct {
	Region          string
	PriceTier       PriceTier
	Price           int32
	Description     string
	ComputeResource Resource
}

func NewParsedSkuData

func NewParsedSkuData(region string, priceTier PriceTier, price int32, description string, computeResource Resource) *ParsedSkuData

type PriceTier

type PriceTier int64
const (
	OnDemand PriceTier = iota
	Spot
)

type PriceTiers

type PriceTiers struct {
	OnDemand Prices
	Spot     Prices
}

func NewPriceTiers

func NewPriceTiers() *PriceTiers

type Prices

type Prices struct {
	Cpu float64
	Ram float64
}

type Resource

type Resource int64
const (
	Cpu Resource = iota
	Ram
	Storage
)

type StoragePricing

type StoragePricing struct {
	Storage map[string]float64
}

StoragePricing is a map where the key is the storage type and the value is the price

func NewStoragePricing

func NewStoragePricing() *StoragePricing

type StructuredPricingMap

type StructuredPricingMap struct {
	Compute map[string]*FamilyPricing
	Storage map[string]*StoragePricing
}

StructuredPricingMap is a map of regions to a map of family to price tiers

func GeneratePricingMap

func GeneratePricingMap(skus []*billingpb.Sku) (*StructuredPricingMap, error)

func NewStructuredPricingMap

func NewStructuredPricingMap() *StructuredPricingMap

NewStructuredPricingMap returns a new StructuredPricingMap in a way that can be used afterwards.

func (*StructuredPricingMap) CheckReadiness added in v0.3.0

func (spm *StructuredPricingMap) CheckReadiness() bool

func (StructuredPricingMap) GetCostOfInstance

func (m StructuredPricingMap) GetCostOfInstance(instance *MachineSpec) (float64, float64, error)

func (StructuredPricingMap) GetCostOfStorage

func (m StructuredPricingMap) GetCostOfStorage(region, storageClass string) (float64, error)

Jump to

Keyboard shortcuts

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