csm

package
v1.14.22 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package csm provides Client Side Monitoring (CSM) which enables sending metrics via UDP connection. Using the Start function will enable the reporting of metrics on a given port. If Start is called, with different parameters, again, a panic will occur.

Pause can be called to pause any metrics publishing on a given port. Sessions that have had their handlers modified via InjectHandlers may still be used. However, the handlers will act as a no-op meaning no metrics will be published.

Example:
	r, err := csm.Start("clientID", ":31000")
	if err != nil {
		panic(fmt.Errorf("failed starting CSM:  %v", err))
	}

	sess, err := session.NewSession(&aws.Config{})
	if err != nil {
		panic(fmt.Errorf("failed loading session: %v", err))
	}

	r.InjectHandlers(&sess.Handlers)

	client := s3.New(sess)
	resp, err := client.GetObject(&s3.GetObjectInput{
		Bucket: aws.String("bucket"),
		Key: aws.String("key"),
	})

	// Will pause monitoring
	r.Pause()
	resp, err = client.GetObject(&s3.GetObjectInput{
		Bucket: aws.String("bucket"),
		Key: aws.String("key"),
	})

	// Resume monitoring
	r.Continue()

Start returns a Reporter that is used to enable or disable monitoring. If access to the Reporter is required later, calling Get will return the Reporter singleton.

Example:
	r := csm.Get()
	r.Continue()

Index

Examples

Constants

View Source
const (
	APICallMetricHandlerName        = "awscsm.SendAPICallMetric"
	APICallAttemptMetricHandlerName = "awscsm.SendAPICallAttemptMetric"
)

Client side metric handler names

View Source
const (
	// DefaultPort is used when no port is specified
	DefaultPort = "31000"
)

Variables

View Source
var (
	// MetricsChannelSize of metrics to hold in the channel
	MetricsChannelSize = 100
)

Functions

This section is empty.

Types

type Reporter

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

Reporter will gather metrics of API requests made and send those metrics to the CSM endpoint.

func Get

func Get() *Reporter

Get will return a reporter if one exists, if one does not exist, nil will be returned.

func Start

func Start(clientID string, url string) (*Reporter, error)

Start will start the a long running go routine to capture client side metrics. Calling start multiple time will only start the metric listener once and will panic if a different client ID or port is passed in.

Example:
	r, err := csm.Start("clientID", "127.0.0.1:8094")
	if err != nil {
		panic(fmt.Errorf("expected no error, but received %v", err))
	}
	sess := session.NewSession()
	r.InjectHandlers(sess.Handlers)

	svc := s3.New(sess)
	out, err := svc.GetObject(&s3.GetObjectInput{
		Bucket: aws.String("bucket"),
		Key: aws.String("key"),
	})
Example
package main

import (
	"fmt"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/csm"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/s3"
)

func main() {
	r, err := csm.Start("clientID", ":31000")
	if err != nil {
		panic(fmt.Errorf("failed starting CSM:  %v", err))
	}

	sess, err := session.NewSession(&aws.Config{})
	if err != nil {
		panic(fmt.Errorf("failed loading session: %v", err))
	}

	r.InjectHandlers(&sess.Handlers)

	client := s3.New(sess)
	client.GetObject(&s3.GetObjectInput{
		Bucket: aws.String("bucket"),
		Key:    aws.String("key"),
	})

	// Pauses monitoring
	r.Pause()
	client.GetObject(&s3.GetObjectInput{
		Bucket: aws.String("bucket"),
		Key:    aws.String("key"),
	})

	// Resume monitoring
	r.Continue()
}
Output:

func (*Reporter) Continue

func (rep *Reporter) Continue()

Continue will reopen the metric channel and allow for monitoring to be resumed.

func (*Reporter) InjectHandlers

func (rep *Reporter) InjectHandlers(handlers *request.Handlers)

InjectHandlers will will enable client side metrics and inject the proper handlers to handle how metrics are sent.

Example:
	// Start must be called in order to inject the correct handlers
	r, err := csm.Start("clientID", "127.0.0.1:8094")
	if err != nil {
		panic(fmt.Errorf("expected no error, but received %v", err))
	}

	sess := session.NewSession()
	r.InjectHandlers(&sess.Handlers)

	// create a new service client with our client side metric session
	svc := s3.New(sess)

func (*Reporter) Pause

func (rep *Reporter) Pause()

Pause will pause the metric channel preventing any new metrics from being added.

Jump to

Keyboard shortcuts

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