cloudwatch

package
v0.0.0-...-2731d20 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 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/AdRoll/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.

Please refer to AWS Cloudwatch's documentation for more info

##Examples ####Get Metric Statistics

import (
    "fmt"
    "time"
    "os"
    "github.com/AdRoll/goamz/aws"
    "github.com/AdRoll/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: cloudwatch.UnitCount, // Not mandatory
                Period: 60,
                Statistics: []string{cloudwatch.StatisticDatapointSum},
                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/AdRoll/goamz/aws"
    "github.com/AdRoll/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

View Source
const (
	UnitSeconds            string = "Seconds"
	UnitMicroseconds       string = "Microseconds"
	UnitMilliseconds       string = "Milliseconds"
	UnitBytes              string = "Bytes"
	UnitKilobytes          string = "Kilobytes"
	UnitMegabytes          string = "Megabytes"
	UnitGigabytes          string = "Gigabytes"
	UnitTerabytes          string = "Terabytes"
	UnitBits               string = "Bits"
	UnitKilobits           string = "Kilobits"
	UnitMegabits           string = "Megabits"
	UnitGigabits           string = "Gigabits"
	UnitTerabits           string = "Terabits"
	UnitPercent            string = "Percent"
	UnitCount              string = "Count"
	UnitBytesPerSecond     string = "Bytes/Second"
	UnitKilobytesPerSecond string = "Kilobytes/Second"
	UnitMegabytesPerSecond string = "Megabytes/Second"
	UnitGigabytesPerSecond string = "Gigabytes/Second"
	UnitTerabytesPerSecond string = "Terabytes/Second"
	UnitBitsPerSecond      string = "Bits/Second"
	UnitKilobitsPerSecond  string = "Kilobits/Second"
	UnitMegabitsPerSecond  string = "Megabits/Second"
	UnitGigabitsPerSecond  string = "Gigabits/Second"
	UnitTerabitsPerSecond  string = "Terabits/Second"
	UnitCountPerSecond     string = "Count/Second"
	UnitNone               string = "None"
)
View Source
const (
	StatisticDatapointAverage     string = "Average"
	StatisticDatapointSum         string = "Sum"
	StatisticDatapointSampleCount string = "SampleCount"
	StatisticDatapointMaximum     string = "Maximum"
	StatisticDatapointMinimum     string = "Minimum"
)
View Source
const (
	ComparisonOperatorLessThanThreshold             string = "LessThanThreshold"
	ComparisonOperatorLessThanOrEqualToThreshold    string = "LessThanOrEqualToThreshold"
	ComparisonOperatorGreaterThanThreshold          string = "GreaterThanThreshold"
	ComparisonOperatorGreaterThanOrEqualToThreshold string = "GreaterThanOrEqualToThreshold"
)
View Source
const (
	MetricNameCPUUtilization = "CPUUtilization"
)

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