cloudwatch

package
v0.0.0-...-93f2c22 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2017 License: LGPL-3.0 Imports: 7 Imported by: 0

README

#GoLang AWS Cloudwatch

Installation

Please refer to the project's main page at https://github.com/channelmeter/goamz for instructions about how to install.

Available methods

GetMetricStatistics Gets statistics for the specified metric.
ListMetrics Returns a list of valid metrics stored for the AWS account.
PutMetricData Publishes metric data points to Amazon CloudWatch.
PutMetricAlarm Creates or updates an alarm and associates it with the specified Amazon CloudWatch metric.

Please refer to AWS Cloudwatch's documentation for more info

##Examples ####Get Metric Statistics

import (
    "fmt"
    "time"
    "os"
    "github.com/channelmeter/goamz/aws"
    "github.com/channelmeter/goamz/cloudwatch"
)

func test_get_metric_statistics() {
    region := aws.Regions["a_region"]
    namespace:= "AWS/ELB"
    dimension  := &cloudwatch.Dimension{
                                         Name: "LoadBalancerName",
                                         Value: "your_value",
                                       }
    metricName := "RequestCount"
    now := time.Now()
    prev := now.Add(time.Duration(600)*time.Second*-1) // 600 secs = 10 minutes

    auth, err := aws.GetAuth("your_AccessKeyId", "your_SecretAccessKey", "", now)
    if err != nil {
       fmt.Printf("Error: %+v\n", err)
       os.Exit(1)
    }

    cw, err := cloudwatch.NewCloudWatch(auth, region.CloudWatchServicepoint)
    request := &cloudwatch.GetMetricStatisticsRequest {
                Dimensions: []cloudwatch.Dimension{*dimension},
                EndTime: now,
                StartTime: prev,
                MetricName: metricName,
                Unit: "Count", // Not mandatory
                Period: 60,
                Statistics: []string{"Sum"},
                Namespace: namespace,
            }

    response, err := cw.GetMetricStatistics(request)
    if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Printf("Error: %+v\n", err)
    }
}

####List Metrics

import (
    "fmt"
    "time"
    "os"
    "github.com/channelmeter/goamz/aws"
    "github.com/channelmeter/goamz/cloudwatch"
)

func test_list_metrics() {
    region := aws.Regions["us-east-1"]  // Any region here
    now := time.Now()

    auth, err := aws.GetAuth("an AccessKeyId", "a SecretAccessKey", "", now)
    if err != nil {
       fmt.Printf("Error: %+v\n", err)
       os.Exit(1)
    }
    cw, err := cloudwatch.NewCloudWatch(auth, region.CloudWatchServicepoint)
    request := &cloudwatch.ListMetricsRequest{Namespace: "AWS/EC2"}

    response, err := cw.ListMetrics(request)
    if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Printf("Error: %+v\n", err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlarmAction

type AlarmAction struct {
	ARN string
}

type CloudWatch

type CloudWatch struct {
	Service aws.AWSService
}

The CloudWatch type encapsulates all the CloudWatch operations in a region.

func NewCloudWatch

func NewCloudWatch(auth aws.Auth, region aws.ServiceInfo) (*CloudWatch, error)

Create a new CloudWatch object for a given namespace

func (*CloudWatch) GetMetricStatistics

func (c *CloudWatch) GetMetricStatistics(req *GetMetricStatisticsRequest) (result *GetMetricStatisticsResponse, err error)

Get statistics for specified metric

If the arguments are invalid or the server returns an error, the error will be set and the other values undefined.

func (*CloudWatch) ListMetrics

func (c *CloudWatch) ListMetrics(req *ListMetricsRequest) (result *ListMetricsResponse, err error)

func (*CloudWatch) PutMetricAlarm

func (c *CloudWatch) PutMetricAlarm(alarm *MetricAlarm) (result *aws.BaseResponse, err error)

func (*CloudWatch) PutMetricData

func (c *CloudWatch) PutMetricData(metrics []MetricDatum) (result *aws.BaseResponse, err error)

func (*CloudWatch) PutMetricDataNamespace

func (c *CloudWatch) PutMetricDataNamespace(metrics []MetricDatum, namespace string) (result *aws.BaseResponse, err error)

type Datapoint

type Datapoint struct {
	Average     float64
	Maximum     float64
	Minimum     float64
	SampleCount float64
	Sum         float64
	Timestamp   time.Time
	Unit        string
}

type Dimension

type Dimension struct {
	Name  string
	Value string
}

type GetMetricStatisticsRequest

type GetMetricStatisticsRequest struct {
	Dimensions []Dimension
	EndTime    time.Time
	StartTime  time.Time
	MetricName string
	Unit       string
	Period     int
	Statistics []string
	Namespace  string
}

type GetMetricStatisticsResponse

type GetMetricStatisticsResponse struct {
	GetMetricStatisticsResult GetMetricStatisticsResult
	ResponseMetadata          aws.ResponseMetadata
}

type GetMetricStatisticsResult

type GetMetricStatisticsResult struct {
	Datapoints []Datapoint `xml:"Datapoints>member"`
	NextToken  string      `xml:"NextToken"`
}

type ListMetricsRequest

type ListMetricsRequest struct {
	Dimensions []Dimension
	MetricName string
	Namespace  string
	NextToken  string
}

type ListMetricsResponse

type ListMetricsResponse struct {
	ListMetricsResult ListMetricsResult
	ResponseMetadata  aws.ResponseMetadata
}

type ListMetricsResult

type ListMetricsResult struct {
	Metrics   []Metric `xml:"Metrics>member"`
	NextToken string
}

type Metric

type Metric struct {
	Dimensions []Dimension `xml:"Dimensions>member"`
	MetricName string
	Namespace  string
}

type MetricAlarm

type MetricAlarm struct {
	AlarmActions            []AlarmAction
	AlarmDescription        string
	AlarmName               string
	ComparisonOperator      string
	Dimensions              []Dimension
	EvaluationPeriods       int
	InsufficientDataActions []AlarmAction
	MetricName              string
	Namespace               string
	OkActions               []AlarmAction
	Period                  int
	Statistic               string
	Threshold               float64
	Unit                    string
}

type MetricDatum

type MetricDatum struct {
	Dimensions      []Dimension
	MetricName      string
	StatisticValues *StatisticSet
	Timestamp       time.Time
	Unit            string
	Value           float64
}

type StatisticSet

type StatisticSet struct {
	Maximum     float64
	Minimum     float64
	SampleCount float64
	Sum         float64
}

Jump to

Keyboard shortcuts

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