-
Notifications
You must be signed in to change notification settings - Fork 1
/
cloudfront.go
49 lines (42 loc) · 1.56 KB
/
cloudfront.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
package main
import (
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
)
func cfCheckMetric(region, metricName, namespace, dimensionName, dimensionValue, unit *string, period *int64) ([]*cloudwatch.Datapoint, error) {
startTime := time.Now()
endTime := startTime.Add(-time.Second * time.Duration(*period))
// Here we call to the svc creation for cloudwatch
svc := cloudwatch.New(session.New(&aws.Config{Region: aws.String(*region)}))
// Parameters required for getting the info
params := &cloudwatch.GetMetricStatisticsInput{
EndTime: aws.Time(startTime), // Required
MetricName: aws.String(*metricName), // Required
Namespace: aws.String(*namespace), // Required
Period: aws.Int64(*period), // Required
StartTime: aws.Time(endTime), // Required
Statistics: []*string{ // Required
aws.String("Average"),
aws.String("Sum"),
aws.String("Minimum"),
aws.String("Maximum"),
aws.String("SampleCount"),
},
Dimensions: []*cloudwatch.Dimension{
{ // Required
Name: aws.String(*dimensionName), // Required
Value: aws.String(*dimensionValue), // Required
},
// More values...
},
Unit: aws.String(*unit),
}
resp, err := svc.GetMetricStatistics(params)
return resp.Datapoints, err
}