gke

package
v0.0.3 Latest Latest
Warning

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

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

README

GKE Module

Collects and exports costs associated with GKE instances. It's built on top of main of the same primitives as the GCP module. Specifically we share

  • PricingMap
  • MachineSpec
  • ListInstances

What differs between the two is that the module will filter out instances that are not GKE instances. This is done by checking the labels field of the instance and looking for the cluster name. If no cluster name is found, the instance is not considered a GKE instance and is filtered out.

The primary motivation for this module was to ensure we could support the following cases with ease:

  1. Collecting costs for GKE instances
  2. Collecting costs for Compute instances that may not be a GKE instance
  3. Collecting costs for Persistent Volumes that may be attached to a GKE instance

See the Design Doc for the rationale for a separate module. TL;DR; We do not want to emit metrics with a exporter_cluster label that is empty or make the setup process more complex needed.

Documentation

Index

Constants

View Source
const (
	BootDiskLabel = "goog-gke-node"
)
View Source
const GBPerGIB = 1e9 / (1 << 30)

GBPerGIB is a helper const to convert from GB to GiB 1 << 30 is the number of bytes in a GiB 1e9 is the number of bytes in a GB

Variables

This section is empty.

Functions

func ListDisks

func ListDisks(project string, zone string, service *compute.Service) ([]*compute.Disk, error)

ListDisks will list all disks in a given zone and return a slice of compute.Disk

Types

type Collector

type Collector struct {
	Projects          []string
	ComputePricingMap *gcpCompute.StructuredPricingMap
	NextScrape        time.Time
	// contains filtered or unexported fields
}

func New

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

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

func (*Collector) Register

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

type Config

type Config struct {
	Projects       string
	ScrapeInterval time.Duration
}

type Disk

type Disk struct {
	Cluster string

	Project string

	Size int64
	// contains filtered or unexported fields
}

func NewDisk

func NewDisk(disk *compute.Disk, project string) *Disk

func (Disk) DiskType

func (d Disk) DiskType() string

DiskType will search through the labels to determine the type of disk. If the disk has a label "goog-gke-node" it will return "boot_disk" Otherwise it returns persistent_volume

func (Disk) Name

func (d Disk) Name() string

Name will return the name of the disk. If the disk has a label "kubernetes.io/created-for/pv/name" it will return the value stored in that key. otherwise it will return the disk name that is directly associated with the disk.

func (Disk) Namespace

func (d Disk) Namespace() string

Namespace will search through the description fields for the namespace of the disk. If the namespace can't be determined An empty string is return.

func (Disk) Region

func (d Disk) Region() string

Region will return the region of the disk by search through the zone field and returning the region. If the region can't be determined It will return an empty string

func (Disk) SizeInGib

func (d Disk) SizeInGib() float64

SizeInGib is used to convert the size of the disk from GigaBytes to GibiBytes. This is particularly important when calculating the cost of the disk since the pricing is in GiB.

func (Disk) StorageClass

func (d Disk) StorageClass() string

StorageClass will return the storage class of the disk by looking at the type. Type in GCP is represented as a URL and as such we're looking for the last part of the URL to determine the storage class

Jump to

Keyboard shortcuts

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