cloudwatch

package
v1.5.8 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package cloudwatch reads CloudWatch metrics (Query API 2010-08-01) and CloudWatch Logs (JSON 1.1). Metric reads are billed by AWS, so callers go through Cache.

Index

Constants

View Source
const (

	// DefaultWindow is the read window for one metric view.
	DefaultWindow = 3 * time.Hour
	// DefaultPeriod is the datapoint period in seconds for one metric view.
	DefaultPeriod = 300
)
View Source
const ServiceName = "cloudwatch"

ServiceName is the key used in the guard ServicesEnabled map.

Variables

View Source
var (
	Service     = awsx.Service{Name: "monitoring", Prefix: "monitoring", SigningName: "monitoring"}
	LogsService = awsx.Service{Name: "logs", Prefix: "logs", SigningName: "logs", TargetPrefix: "Logs_20140328"}
)

Service names are checked against the botocore models for monitoring and logs.

View Source
var ErrBadQuery = errors.New("cloudwatch: invalid metric query")

ErrBadQuery is returned for a query that cannot be sent.

Functions

func Cached

func Cached[T any](c *Cache, key string, fn func() (T, error)) (T, bool, error)

Cached runs fn once per key per TTL and reports whether the answer came from the cache.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache holds metric reads for a short TTL. Concurrent callers with the same key share one provider call, because every metric read is billed.

func NewCache

func NewCache(ttl time.Duration) *Cache

NewCache builds a cache; a TTL of zero or less disables storing results.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the lazy CloudWatch module; it makes no call until a method runs.

func New

func New(c *awsx.Client) *Client

New wraps a shared client.

func (*Client) DescribeLogGroups

func (c *Client) DescribeLogGroups(ctx context.Context, region, prefix string, limit int) ([]LogGroup, error)

DescribeLogGroups lists groups by name prefix, up to limit (all pages until then).

func (*Client) FilterLogEvents

func (c *Client) FilterLogEvents(ctx context.Context, region string, f FilterInput) (events []Event, truncated bool, err error)

FilterLogEvents reads matching events in the window, up to Limit. truncated reports that more events exist than were returned.

func (*Client) GetMetricData

func (c *Client) GetMetricData(ctx context.Context, region string, qs []Query, start, end time.Time) ([]Series, error)

GetMetricData reads many metrics in as few calls as possible (500 per call) and follows NextToken. Results come oldest first.

func (*Client) ListMetrics

func (c *Client) ListMetrics(ctx context.Context, region, namespace, name string, dims []Dimension) ([]Metric, error)

ListMetrics lists metrics, optionally filtered by namespace, name and one or more dimensions.

type Dimension

type Dimension struct{ Name, Value string }

Dimension is one name and value of a metric identity.

type Event

type Event struct {
	Time            time.Time
	Stream, Message string
}

Event is one log event.

type FilterInput

type FilterInput struct {
	Group, Pattern string
	Start, End     time.Time
	Limit          int
}

FilterInput selects log events.

type LogGroup

type LogGroup struct {
	Name          string
	RetentionDays int
	StoredBytes   int64
}

LogGroup is one CloudWatch Logs group.

type Metric

type Metric struct {
	Namespace, Name string
	Dimensions      []Dimension
}

Metric is one metric identity from ListMetrics.

type Point

type Point struct {
	T time.Time
	V float64
}

Point is one datapoint.

type Query

type Query struct {
	ID, Namespace, Name, Stat string
	Dimensions                []Dimension
	Period                    int
}

Query is one metric to read.

type Series

type Series struct {
	ID, Label, Status string
	Points            []Point
}

Series is the answer for one Query, oldest point first.

Jump to

Keyboard shortcuts

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