metrics

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package metrics is phase 2 of the estimate (vision docs/specs/2026-10-10-savings-estimate-design.md §5): each eligible workload's requests per minute over 14 days, and the measured uptime of EC2 instances, ECS services and companion databases, read from CloudWatch.

This file ports manager packages/estimate/src/requests.ts: each workload's target group RequestCount (CloudWatch keeps one-minute data 15 days), five metrics per GetMetricData call (20,160 values each, under the 100,800 a call returns), every page, by each value's timestamp. CloudWatch publishes nothing for a minute without request: an empty series is a workload no one called; a metric it could not read is unreadable, never silence. Kept per account and region the same UTC day.

Index

Constants

View Source
const (
	PhaseRequests = "requests"
	PhaseUptime   = "uptime"
)

Phases of the progress events this package emits.

View Source
const Days = 14

Days is the period the estimate reads by default (--days; CloudWatch keeps one-minute data 15 days).

View Source
const ScanByAscending = "TimestampAscending"

ScanByAscending asks the oldest values first (Node passes it on every call).

Variables

View Source
var DefaultKinds = UptimeKinds{EC2: true}

DefaultKinds is what Node measures when no kinds are given: the instances.

Functions

func DatabaseKey

func DatabaseKey(d discover.Database) string

DatabaseKey is a companion database's key in the uptime: its kind and identifier.

func Measured

func Measured(w discover.Workload, kinds UptimeKinds) bool

Measured says whether the option measures the workload's uptime.

Types

type CloudWatchOf

type CloudWatchOf func(ctx context.Context, account, region string) (CloudWatchPort, error)

CloudWatchOf gives an account's CloudWatch in a region (Node's cloudwatchOf).

type CloudWatchPort

type CloudWatchPort interface {
	GetMetricData(ctx context.Context, in GetMetricDataInput) (GetMetricDataOutput, error)
}

CloudWatchPort is the metrics API.

type Dimension

type Dimension = discover.Dimension

The query shapes are the scan's (discovery reads the same GetMetricData).

type GetMetricDataInput

type GetMetricDataInput struct {
	StartTime         time.Time
	EndTime           time.Time
	MetricDataQueries []MetricDataQuery
	ScanBy            string
	NextToken         string
}

GetMetricDataInput is a GetMetricData call. Its times are written as Node's toISOString does (2026-10-12T08:00:00.000Z).

func (GetMetricDataInput) MarshalJSON

func (in GetMetricDataInput) MarshalJSON() ([]byte, error)

MarshalJSON writes the input with its times as ISO strings.

type GetMetricDataOutput

type GetMetricDataOutput struct {
	MetricDataResults []MetricDataResult `json:"MetricDataResults,omitempty"`
	NextToken         string             `json:"NextToken,omitempty"`
}

GetMetricDataOutput is a page of results; NextToken says there is another.

type Message

type Message struct {
	Code  string `json:"Code,omitempty"`
	Value string `json:"Value,omitempty"`
}

Message is a message of a result (why CloudWatch could not read a metric).

type Metric

type Metric = discover.Metric

The query shapes are the scan's (discovery reads the same GetMetricData).

type MetricDataQuery

type MetricDataQuery = discover.MetricDataQuery

The query shapes are the scan's (discovery reads the same GetMetricData).

type MetricDataResult

type MetricDataResult struct {
	ID         string      `json:"Id,omitempty"`
	Timestamps []time.Time `json:"Timestamps,omitempty"`
	Values     []float64   `json:"Values,omitempty"`
	StatusCode string      `json:"StatusCode,omitempty"`
	Messages   []Message   `json:"Messages,omitempty"`
}

MetricDataResult is one query's values: Timestamps and Values side by side.

type MetricStat

type MetricStat = discover.MetricStat

The query shapes are the scan's (discovery reads the same GetMetricData).

type RegionRequests

type RegionRequests struct {
	Account    string                  `json:"account"`
	Region     string                  `json:"region"`
	From       string                  `json:"from"`
	To         string                  `json:"to"`
	Minutes    map[string][][2]float64 `json:"minutes"`
	Unreadable map[string]string       `json:"unreadable"`
}

RegionRequests is a region's requests: by target group ARN, [minute, count] pairs (minutes from From, ascending; only minutes with a request) or why its metric could not be read. JSON names as Node's (the cache and the report).

func Requests

func Requests(ctx context.Context, cw CloudWatchPort, workloads []discover.Workload, days int, now time.Time) (RegionRequests, error)

Requests reads the requests per minute of the workloads' target groups over the days before now (to the minute): one metric per target group, a managed workload's waker too, added up to its own (R10). An error is a call that failed, whole.

func RequestsAll

func RequestsAll(ctx context.Context, o RequestsOptions) ([]RegionRequests, error)

RequestsAll reads the requests of every region with workloads and no error, --parallel regions at a time, in the regions' order. A region it cannot read at all is a RegionRequests whose workloads are unreadable with AWS's reason; the error is the context's.

type RegionUptime

type RegionUptime struct {
	Account    string              `json:"account"`
	Region     string              `json:"region"`
	From       string              `json:"from"`
	To         string              `json:"to"`
	Running    map[string][][2]int `json:"running"`
	Unreadable map[string]string   `json:"unreadable"`
	// Go only: each ECS service's task-minutes over the period (its LiveTaskCount); none when CloudWatch has none.
	// Counted: the tasks were read (an uptime kept from before is read again).
	Tasks   map[string]float64 `json:"tasks,omitempty"`
	Counted bool               `json:"counted,omitempty"`
}

RegionUptime is a region's measured uptime: by instance id, service ARN or database key, when it ran ([start, end) in minutes from From, sorted and disjoint), or why it could not be read. JSON names as Node's.

func UptimeAll

func UptimeAll(ctx context.Context, o UptimeOptions) ([]RegionUptime, error)

UptimeAll measures the regions with something to measure, over their requests period, --parallel regions at a time, in the regions' order. A region it cannot read at all is a RegionUptime whose ids are unreadable with AWS's reason; the error is the context's.

type RequestsOptions

type RequestsOptions struct {
	Regions      []discover.RegionDiscovery
	CloudWatchOf CloudWatchOf
	Cache        *cache.Cache
	// Refresh is "discovery" or "metrics" (read again) or "".
	Refresh string
	Now     func() time.Time
	// Progress, OnPlan and OnStart are called one at a time (a mutex), though
	// regions run at once. OnPlan comes first, before any read.
	Progress func(discover.ProgressEvent)
	// Concurrency is the regions read at once (--parallel; 5 when < 1).
	Concurrency int
	// OnPlan says how many regions are read; OnStart says when each starts.
	OnPlan  func(count int)
	OnStart func(account, region string)
	// Days is the days of requests read before the run (--days; Days when < 1).
	Days int
}

RequestsOptions are the inputs of RequestsAll.

type UptimeKinds

type UptimeKinds struct{ EC2, ECS, RDS bool }

UptimeKinds says what each option measures: EC2 instances without an Auto Scaling group (EC2), ECS services (ECS), never what Dormeto manages; and the companion databases a nap could stop (RDS).

type UptimeOptions

type UptimeOptions struct {
	Regions []discover.RegionDiscovery
	// Requests are the regions' requests: each region is measured over its period.
	Requests     []RegionRequests
	CloudWatchOf CloudWatchOf
	Cache        *cache.Cache
	// Refresh is "discovery" or "metrics" (read again) or "".
	Refresh  string
	Now      func() time.Time
	Progress func(discover.ProgressEvent)
	// Kinds is what is measured; nil: DefaultKinds (Node's default argument).
	Kinds *UptimeKinds
	// Concurrency is the regions read at once (--parallel; 5 when < 1).
	Concurrency int
	// OnPlan says how many regions are measured; OnStart when each starts.
	OnPlan  func(count int)
	OnStart func(account, region string)
}

UptimeOptions are the inputs of UptimeAll.

type UptimeRead

type UptimeRead struct {
	Running    map[string][][2]int
	Unreadable map[string]string
	Tasks      map[string]float64
}

UptimeRead is what Uptime reads of a list of ids: when each ran, and each ECS service's task-minutes.

func Uptime

func Uptime(ctx context.Context, cw CloudWatchPort, ids []string, from, to string) (UptimeRead, error)

Uptime reads the running periods of the ids over [from, to] (ISO strings, the region's requests period): each datapoint is running its 5 minutes, consecutive ones joined. An error is a call that failed, whole.

Jump to

Keyboard shortcuts

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