utils

package
v0.32.3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package utils contains shared helpers for metric construction and constants.

Index

Constants

View Source
const (
	// DefaultScrapeInterval is the default scrape interval for the collectors.
	DefaultScrapeInterval = 1 * time.Hour
	// HoursInMonth is an approximate average number of hours in a month.
	// 24.35 is the average number of hours per day over a year.
	HoursInMonth = 24.35 * 30
	// InstanceCPUCostSuffix is the suffix for per-core-hour CPU cost metrics.
	InstanceCPUCostSuffix = "instance_cpu_usd_per_core_hour"
	// InstanceMemoryCostSuffix is the suffix for per-GiB-hour memory cost metrics.
	InstanceMemoryCostSuffix = "instance_memory_usd_per_gib_hour"
	// InstanceTotalCostSuffix is the suffix for total per-hour instance cost metrics.
	InstanceTotalCostSuffix = "instance_total_usd_per_hour"
	// PersistentVolumeCostSuffix is the suffix for per-hour EBS volume cost metrics.
	PersistentVolumeCostSuffix = "persistent_volume_usd_per_hour"
	// Used for Azure persistent volumes following AWS naming pattern.
	PersistentVolumeCostPerGiBSuffix = "persistent_volume_usd_per_gib_hour"
	// RegionUnknown is used as a label value when a region or other attribute cannot be determined.
	RegionUnknown = "unknown"
)

Variables

This section is empty.

Functions

func GenerateDesc added in v0.6.0

func GenerateDesc(prefix, subsystem, suffix, description string, labels []string) *prometheus.Desc

GenerateDesc creates a Prometheus metric descriptor with a standardized fqname.

func RegionsFromMap added in v0.28.1

func RegionsFromMap[V any](m map[string]V) []string

RegionsFromMap returns the keys of a map as a slice of strings. Used by collectors that store per-region clients in a map[string]Client.

func Retry added in v0.13.0

func Retry(attempts int, initialDelay, maxDelay time.Duration, retryIf func(error) bool, op func() error) error

Retry runs op up to attempts times, sleeping with exponential backoff between retries when op returns a non-nil error and retryIf(err) returns true. The delay grows as: initialDelay * 2^attempt, capped at maxDelay. If attempts <= 0, it defaults to 1 (no retries).

Types

type LabelMap

type LabelMap map[string]string

type MetricResult

type MetricResult struct {
	FqName     string
	Labels     LabelMap
	Value      float64
	MetricType prometheus.ValueType
}

func ReadMetrics

func ReadMetrics(metric prometheus.Metric) *MetricResult

Jump to

Keyboard shortcuts

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