Fix typo in README and format in cloudwatch output

This commit is contained in:
Stephen Kwong 2016-01-19 14:32:27 -08:00
parent bb0be0d76d
commit 262abb4d25
3 changed files with 20 additions and 20 deletions

View File

@ -3,7 +3,7 @@ package all
import ( import (
_ "github.com/influxdb/telegraf/plugins/outputs/amon" _ "github.com/influxdb/telegraf/plugins/outputs/amon"
_ "github.com/influxdb/telegraf/plugins/outputs/amqp" _ "github.com/influxdb/telegraf/plugins/outputs/amqp"
_ "github.com/influxdb/telegraf/plugins/outputs/cloudwatch" _ "github.com/influxdb/telegraf/plugins/outputs/cloudwatch"
_ "github.com/influxdb/telegraf/plugins/outputs/datadog" _ "github.com/influxdb/telegraf/plugins/outputs/datadog"
_ "github.com/influxdb/telegraf/plugins/outputs/graphite" _ "github.com/influxdb/telegraf/plugins/outputs/graphite"
_ "github.com/influxdb/telegraf/plugins/outputs/influxdb" _ "github.com/influxdb/telegraf/plugins/outputs/influxdb"

View File

@ -4,7 +4,7 @@ This plugin will send points to Amazon CloudWatch.
## Amazon Authentication ## Amazon Authentication
This plugin uses a credential chain for Authentication with the Kinesis API endpoint. In the following order the plugin This plugin uses a credential chain for Authentication with the CloudWatch API endpoint. In the following order the plugin
will attempt to authenticate. will attempt to authenticate.
1. [IAMS Role](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html) 1. [IAMS Role](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html)
2. [Environment Variables](https://github.com/aws/aws-sdk-go/wiki/configuring-sdk) 2. [Environment Variables](https://github.com/aws/aws-sdk-go/wiki/configuring-sdk)

View File

@ -10,8 +10,8 @@ import (
"github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds" "github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
"github.com/aws/aws-sdk-go/aws/ec2metadata" "github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/influxdb/influxdb/client/v2" "github.com/influxdb/influxdb/client/v2"
"github.com/influxdb/telegraf/plugins/outputs" "github.com/influxdb/telegraf/plugins/outputs"
@ -20,12 +20,12 @@ import (
) )
type CloudWatchOutput struct { type CloudWatchOutput struct {
Region string // AWS Region Region string // AWS Region
Namespace string // CloudWatch Metrics Namespace Namespace string // CloudWatch Metrics Namespace
svc *cloudwatch.CloudWatch svc *cloudwatch.CloudWatch
} }
var sampleConfig = ` var sampleConfig = `
# Amazon REGION # Amazon REGION
region = 'us-east-1' region = 'us-east-1'
@ -43,13 +43,13 @@ func (c *CloudWatchOutput) Description() string {
func (c *CloudWatchOutput) Connect() error { func (c *CloudWatchOutput) Connect() error {
Config := &aws.Config{ Config := &aws.Config{
Region: aws.String(c.Region), Region: aws.String(c.Region),
Credentials: credentials.NewChainCredentials( Credentials: credentials.NewChainCredentials(
[]credentials.Provider{ []credentials.Provider{
&ec2rolecreds.EC2RoleProvider{Client: ec2metadata.New(session.New())}, &ec2rolecreds.EC2RoleProvider{Client: ec2metadata.New(session.New())},
&credentials.EnvProvider{}, &credentials.EnvProvider{},
&credentials.SharedCredentialsProvider{}, &credentials.SharedCredentialsProvider{},
}), }),
} }
svc := cloudwatch.New(session.New(Config)) svc := cloudwatch.New(session.New(Config))
@ -58,7 +58,7 @@ func (c *CloudWatchOutput) Connect() error {
Namespace: aws.String(c.Namespace), Namespace: aws.String(c.Namespace),
} }
_, err := svc.ListMetrics(params) // Try a read-only call to test connection. _, err := svc.ListMetrics(params) // Try a read-only call to test connection.
if err != nil { if err != nil {
log.Printf("cloudwatch: Error in ListMetrics API call : %+v \n", err.Error()) log.Printf("cloudwatch: Error in ListMetrics API call : %+v \n", err.Error())
@ -90,7 +90,7 @@ func (c *CloudWatchOutput) Write(points []*client.Point) error {
func (c *CloudWatchOutput) WriteSinglePoint(point *client.Point) error { func (c *CloudWatchOutput) WriteSinglePoint(point *client.Point) error {
datums := buildMetricDatum(point) datums := buildMetricDatum(point)
const maxDatumsPerCall = 20 // PutMetricData only supports up to 20 data points per call const maxDatumsPerCall = 20 // PutMetricData only supports up to 20 data points per call
for idxRange := range gopart.Partition(len(datums), maxDatumsPerCall) { for idxRange := range gopart.Partition(len(datums), maxDatumsPerCall) {
err := c.WriteToCloudWatch(datums[idxRange.Low:idxRange.High]) err := c.WriteToCloudWatch(datums[idxRange.Low:idxRange.High])
@ -106,7 +106,7 @@ func (c *CloudWatchOutput) WriteSinglePoint(point *client.Point) error {
func (c *CloudWatchOutput) WriteToCloudWatch(datums []*cloudwatch.MetricDatum) error { func (c *CloudWatchOutput) WriteToCloudWatch(datums []*cloudwatch.MetricDatum) error {
params := &cloudwatch.PutMetricDataInput{ params := &cloudwatch.PutMetricDataInput{
MetricData: datums, MetricData: datums,
Namespace: aws.String(c.Namespace), Namespace: aws.String(c.Namespace),
} }
_, err := c.svc.PutMetricData(params) _, err := c.svc.PutMetricData(params)
@ -152,9 +152,9 @@ func buildMetricDatum(point *client.Point) []*cloudwatch.MetricDatum {
datums[i] = &cloudwatch.MetricDatum{ datums[i] = &cloudwatch.MetricDatum{
MetricName: aws.String(strings.Join([]string{point.Name(), k}, "_")), MetricName: aws.String(strings.Join([]string{point.Name(), k}, "_")),
Value: aws.Float64(value), Value: aws.Float64(value),
Dimensions: buildDimensions(point.Tags()), Dimensions: buildDimensions(point.Tags()),
Timestamp: aws.Time(point.Time()), Timestamp: aws.Time(point.Time()),
} }
i += 1 i += 1
@ -171,7 +171,7 @@ func buildDimensions(ptTags map[string]string) []*cloudwatch.Dimension {
for k, v := range ptTags { for k, v := range ptTags {
dimensions[i] = &cloudwatch.Dimension{ dimensions[i] = &cloudwatch.Dimension{
Name: aws.String(k), Name: aws.String(k),
Value: aws.String(v), Value: aws.String(v),
} }