cwatsch

package module
v0.0.0-...-cb2e5be Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2020 License: MIT Imports: 7 Imported by: 0

README

cwatsch

GoDoc

Send cloudwatch metrics in batch.

Name of the package is designed to sound similar to "Quatsch" - a german word for "talk nonsense". Constant chatter a child makes at the dinner table is a good example of Quatsch.

The goal of the package is to reduce aws costs spent on sending custom metrics.

Documentation

Overview

Package cwatsch enables sending cloudwatch metrics in batches.

Name of the package is designed to sound similar to "Quatsch" - a german word for "talk nonsense". Constant chatter a child makes at the dinner table is a good example of Quatsch.

The goal of the package is to reduce aws costs spent on sending custom metrics.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTicker

func NewTicker(ctx context.Context, interval time.Duration, fn func())

Types

type Batch

type Batch struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func New

func (*Batch) Add

func (b *Batch) Add(namespace string, data ...*cw.MetricDatum) *Batch

func (*Batch) AddInputs

func (b *Batch) AddInputs(inputs ...*cw.PutMetricDataInput) *Batch

func (*Batch) Flush

func (b *Batch) Flush() error

Flush all the collected metrics.

func (*Batch) FlushCompleteBatches

func (b *Batch) FlushCompleteBatches() error

FlushCompleteBatches flushes completed batches. The batch is completed if it has exactly 20 MetricDatum items. 20 is a max number of items aws allows to send in one request.

func (*Batch) FlushCompleteBatchesCtx

func (b *Batch) FlushCompleteBatchesCtx(ctx context.Context) error

func (*Batch) FlushCtx

func (b *Batch) FlushCtx(ctx context.Context) error

func (*Batch) LaunchAutoFlush

func (b *Batch) LaunchAutoFlush(ctx context.Context, interval time.Duration, onError func(error))

LaunchAutoFlush creates a background job that auto-flushes metrics periodically. onError is an optional parameter (nil can be provided).

Example
batch := cwatsch.New(&cwAPI)
defer batch.Flush()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// the metrics will be auto-flushed every 30s
batch.LaunchAutoFlush(ctx, 30*time.Second, func(err error) {
	log.Println(err)
})

batch.Add("myApp", &cloudwatch.MetricDatum{
	MetricName: aws.String("number_of_calls"),
	Value:      aws.Float64(1),
	Timestamp:  aws.Time(time.Now()),
})
Output:

func (*Batch) PutMetricData

func (b *Batch) PutMetricData(input *cw.PutMetricDataInput) (*cw.PutMetricDataOutput, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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