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
- Variables
- func DatabaseKey(d discover.Database) string
- func Measured(w discover.Workload, kinds UptimeKinds) bool
- type CloudWatchOf
- type CloudWatchPort
- type Dimension
- type GetMetricDataInput
- type GetMetricDataOutput
- type Message
- type Metric
- type MetricDataQuery
- type MetricDataResult
- type MetricStat
- type RegionRequests
- type RegionUptime
- type RequestsOptions
- type UptimeKinds
- type UptimeOptions
- type UptimeRead
Constants ¶
const ( PhaseRequests = "requests" PhaseUptime = "uptime" )
Phases of the progress events this package emits.
const Days = 14
Days is the period the estimate reads (CloudWatch keeps one-minute data 15 days).
const ScanByAscending = "TimestampAscending"
ScanByAscending asks the oldest values first (Node passes it on every call).
Variables ¶
var DefaultKinds = UptimeKinds{EC2: true}
DefaultKinds is what Node measures when no kinds are given: the instances.
Functions ¶
func DatabaseKey ¶
DatabaseKey is a companion database's key in the uptime: its kind and identifier.
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 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 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"`
}
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)
}
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 ¶
UptimeRead is what Uptime reads of a list of ids.
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.