Skip to content

Commit

Permalink
remove snakecase dependency and utilize internal helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
joshhardy committed Apr 1, 2016
1 parent 971567d commit 62077e1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 35 deletions.
1 change: 0 additions & 1 deletion Godeps
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ github.com/Shopify/sarama 8aadb476e66ca998f2f6bb3c993e9a2daa3666b9
github.com/Sirupsen/logrus 219c8cb75c258c552e999735be6df753ffc7afdc
github.com/amir/raidman 53c1b967405155bfc8758557863bf2e14f814687
github.com/aws/aws-sdk-go 13a12060f716145019378a10e2806c174356b857
github.com/azer/snakecase 7a41237eda4ca971bdcbba00d459901be8221a19
github.com/beorn7/perks 3ac7bf7a47d159a033b107610db8a1b6575507a4
github.com/cenkalti/backoff 4dc77674aceaabba2c7e3da25d4c823edfb73f99
github.com/couchbase/go-couchbase cb664315a324d87d19c879d9cc67fda6be8c2ac1
Expand Down
1 change: 0 additions & 1 deletion Godeps_windows
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ github.com/Sirupsen/logrus 219c8cb75c258c552e999735be6df753ffc7afdc
github.com/StackExchange/wmi f3e2bae1e0cb5aef83e319133eabfee30013a4a5
github.com/amir/raidman 53c1b967405155bfc8758557863bf2e14f814687
github.com/aws/aws-sdk-go 13a12060f716145019378a10e2806c174356b857
github.com/azer/snakecase 7a41237eda4ca971bdcbba00d459901be8221a19
github.com/beorn7/perks 3ac7bf7a47d159a033b107610db8a1b6575507a4
github.com/cenkalti/backoff 4dc77674aceaabba2c7e3da25d4c823edfb73f99
github.com/couchbase/go-couchbase cb664315a324d87d19c879d9cc67fda6be8c2ac1
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/cloudwatch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ Tag Dimension names are represented in [snake case](https://en.wikipedia.org/wik

```
$ ./telegraf -config telegraf.conf -input-filter cloudwatch -test
> cloudwatch_aws_elb,load_balancer_name=p-motd,region=us-east-1,unit=seconds,latency_average=0.0012776487302826093,latency_maximum=0.07484889030456543,latency_minimum=0.0006072521209716797,latency_sample_count=13493,latency_sum=17.239314317703247 1459474260000000000
> cloudwatch_aws_elb,load_balancer_name=p-example,region=us-east-1,unit=seconds latency_average=0.004810798017284538,latency_maximum=0.1100282669067383,latency_minimum=0.0006084442138671875,latency_sample_count=4029,latency_sum=19.382705211639404 1459542420000000000
```
51 changes: 19 additions & 32 deletions plugins/inputs/cloudwatch/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@ import (
"github.com/aws/aws-sdk-go/aws/session"

"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/azer/snakecase"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/inputs"
)

type CloudWatch struct {
Region string `toml:"region"`
Period string `toml:"period"`
Delay string `toml:"delay"`
Namespace string `toml:"namespace"`
Metrics []*Metric `toml:"metrics"`
client *cloudwatch.CloudWatch
periodDuration time.Duration
delayDuration time.Duration
metricCache *MetricCache
Region string `toml:"region"`
Period internal.Duration `toml:"period"`
Delay internal.Duration `toml:"delay"`
Namespace string `toml:"namespace"`
Metrics []*Metric `toml:"metrics"`
client *cloudwatch.CloudWatch
metricCache *MetricCache
}

type Metric struct {
Expand Down Expand Up @@ -67,13 +65,13 @@ func (c *CloudWatch) SampleConfig() string {
## Metrics to Pull (optional)
## Defaults to all Metrics in Namespace if nothing is provided
## Refreshes Namespace available metrics every 1h
[[inputs.cloudwatch.metrics]]
names = ['Latency', 'RequestCount']
## Dimension filters for Metric (optional)
[[inputs.cloudwatch.metrics.dimensions]]
name = 'LoadBalancerName'
value = 'p-example'
#[[inputs.cloudwatch.metrics]]
# names = ['Latency', 'RequestCount']
#
# ## Dimension filters for Metric (optional)
# [[inputs.cloudwatch.metrics.dimensions]]
# name = 'LoadBalancerName'
# value = 'p-example'
`
}

Expand Down Expand Up @@ -158,17 +156,6 @@ func (c *CloudWatch) initializeCloudWatch() error {
}

c.client = cloudwatch.New(session.New(config))

var err error
c.delayDuration, err = time.ParseDuration(c.Delay)
if err != nil {
return err
}
c.periodDuration, err = time.ParseDuration(c.Period)
if err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -275,7 +262,7 @@ func formatMeasurement(namespace string) string {
}

func snakeCase(s string) string {
s = snakecase.SnakeCase(s)
s = internal.SnakeCase(s)
s = strings.Replace(s, "__", "_", -1)
return s
}
Expand All @@ -284,14 +271,14 @@ func snakeCase(s string) string {
* Map Metric to *cloudwatch.GetMetricStatisticsInput for given timeframe
*/
func (c *CloudWatch) getStatisticsInput(metric *cloudwatch.Metric, now time.Time) *cloudwatch.GetMetricStatisticsInput {
end := now.Add(-c.delayDuration)
end := now.Add(-c.Delay.Duration)

input := &cloudwatch.GetMetricStatisticsInput{
StartTime: aws.Time(end.Add(-c.periodDuration)),
StartTime: aws.Time(end.Add(-c.Period.Duration)),
EndTime: aws.Time(end),
MetricName: metric.MetricName,
Namespace: metric.Namespace,
Period: aws.Int64(int64(c.periodDuration.Seconds())),
Period: aws.Int64(int64(c.Period.Duration.Seconds())),
Dimensions: metric.Dimensions,
Statistics: []*string{
aws.String(cloudwatch.StatisticAverage),
Expand Down

0 comments on commit 62077e1

Please sign in to comment.