Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultExporter ¶
func DefaultExporter(client CloudWatchClient) (*Exporter, *BatchMetricDatumSender)
DefaultExporter returns a reasonable Exporter that you can attach to a Reader. The exporter will send metrics to BatchMetricDatumSender. You should call `go BatchMetricDatumSender.Run()` on the returned Sender and pass the Exporter to a Reader.
Types ¶
type BatchMetricDatumSender ¶
type BatchMetricDatumSender struct { // CloudWatchClient is anything that can send datum to cloudwatch. It should probably be cwpagedmetricput.Pager so // you can take care of batching large requests CloudWatchClient CloudWatchClient // BatchDelay is how long to wait between getting one value and waiting for a batch to fill up BatchDelay time.Duration // BatchSize is the maximum number of Datum to send to a single call to CloudWatchClient BatchSize int // Namespace is the cloudwatch namespace attached to the datum Namespace string // OnFailedSend is called on any failure to send datum to CloudWatchClient OnFailedSend func(datum []*cloudwatch.MetricDatum, err error) // contains filtered or unexported fields }
BatchMetricDatumSender aggregates datum into a channel and sends them to cloudwatch
func (*BatchMetricDatumSender) Run ¶
func (b *BatchMetricDatumSender) Run() error
Run executes the batch datum sender. You should probably execute this inside a goroutine. It blocks until Shutdown
func (*BatchMetricDatumSender) SendMetricDatum ¶
func (b *BatchMetricDatumSender) SendMetricDatum(md *cloudwatch.MetricDatum) error
SendMetricDatum queues a datum for sending to cloudwatch
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 Exporter ¶
type Exporter struct { // Sender is anything that can take cloudwatch.MetricDatum and send them to cloudwatch Sender MetricDatumSender // OnFailedSend is called with any metric datum that the sender fails to send OnFailedSend func(md *cloudwatch.MetricDatum, err error) // contains filtered or unexported fields }
Exporter understands how to implement the interface of metricexport.Exporter and turn a list of metricdata.Metric into cloudwatch.MetricDatum. Those datum are fed into Sender for each call to ExportMetrics
func (*Exporter) ExportMetrics ¶
ExportMetrics converts all metrics items into the appropriate *cloudwatch.MetricDatum and sends each to Sender. It will ignore any metrics that Exporter cannot currently export and calls OnFailedSend on any failed sends.
Example ¶
package main import ( "context" "log" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudwatch" "github.com/cep21/cwopencensusexporter" "go.opencensus.io/metric/metricexport" ) func main() { awsClient := cloudwatch.New(session.Must(session.NewSession())) exporter, sender := cwopencensusexporter.DefaultExporter(awsClient) go func() { if err := sender.Run(); err != nil { log.Print(err) } }() defer func() { if err := sender.Shutdown(context.Background()); err != nil { log.Print(err) } }() ir, err := metricexport.NewIntervalReader(&metricexport.Reader{}, exporter) if err != nil { panic(err) } if err := ir.Start(); err != nil { panic(err) } defer ir.Stop() }
Output:
type MetricDatumSender ¶
type MetricDatumSender interface { // SendMetricDatum should not block. It should queue the datum for sending, or just send it. // It should not modify the input datum // but can assume the input datum is immutable. Return an error if unable to send this datum correctly. SendMetricDatum(md *cloudwatch.MetricDatum) error }
MetricDatumSender is anything that can send datum somewhere