Documentation
¶
Overview ¶
Package cwpagedmetricput allows mass PutMetricData calls into CloudWatch metrics with an API that matches CloudWatch's aws-sdk-go client. It does this by bucketing Datum into sizes allowed by AWS's API. It also takes cost saving measures by gzip sending large datum sends.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CloudWatchClient ¶
type CloudWatchClient interface { // PutMetricDataWithContext should match the contract of cloudwatch.CloudWatch.PutMetricDataWithContext PutMetricDataWithContext(aws.Context, *cloudwatch.PutMetricDataInput, ...request.Option) (*cloudwatch.PutMetricDataOutput, error) }
CloudWatchClient is anything that can receive CloudWatch metrics as documented by CloudWatch's public API constraints.
type Config ¶
type Config struct { // True will empty out the "unit" field of datum that have a unit not explicitly documented at // https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html ClearInvalidUnits bool // True will *not* use goroutines to send all the batches at once and will send the batches serially after they are // created SerialSends bool // Callback executed when weird datum or RPC calls force us to drop some of the datum from a request we've had to // split. OnDroppedDatum func(datum *cloudwatch.MetricDatum) }
Config controls optional parameters of Pager. The zero value is a reasonable default.
type Pager ¶
type Pager struct { // Client is required and is usually an instance of *cloudwatch.CloudWatch Client CloudWatchClient // Config is optional and controls how data is filtered or aggregated Config Config }
Pager behaves like CloudWatch's MetricData API, but takes care of all of the smaller parts for you around how to correctly bucket and split MetricDatum. Pager is as thread safe as the Client parameter. If you're using *cloudwatch.CloudWatch as your Client, then it will be thread safe.
func (*Pager) PutMetricData ¶
func (c *Pager) PutMetricData(input *cloudwatch.PutMetricDataInput) (*cloudwatch.PutMetricDataOutput, error)
PutMetricData should be a drop in replacement for *cloudwatch.CloudWatch.PutMetricData, but taking care of splitting datum that are too large. Note: More difficult to support PutMetricDataRequest since it is not one request.Request, but many.
Example ¶
package main import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudwatch" "github.com/cep21/cwpagedmetricput" ) func main() { a := cwpagedmetricput.Pager{ Client: cloudwatch.New(session.Must(session.NewSession(&aws.Config{ Region: aws.String("us-west-2"), }))), } _, err := a.PutMetricData(&cloudwatch.PutMetricDataInput{ Namespace: aws.String("custom"), MetricData: []*cloudwatch.MetricDatum{ { MetricName: aws.String("custom metric"), }, }, }) if err != nil { // You'll need valid AWS credentials fmt.Println("error result") } else { fmt.Println("result") } }
Output: error result
func (*Pager) PutMetricDataWithContext ¶
func (c *Pager) PutMetricDataWithContext(ctx aws.Context, input *cloudwatch.PutMetricDataInput, reqs ...request.Option) (*cloudwatch.PutMetricDataOutput, error)
PutMetricDataWithContext should be a drop in replacement for *cloudwatch.CloudWatch.PutMetricDataWithContext, but taking care of splitting datum that are too large.