-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudWatch.go
More file actions
47 lines (44 loc) · 1.28 KB
/
cloudWatch.go
File metadata and controls
47 lines (44 loc) · 1.28 KB
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
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
)
type CloudWatchClient struct {
Region string
AccessKey string
SecretKey string
client *cloudwatch.CloudWatch
}
func NewCloudWatchClient(region string, accesskey string, secretkey string) CloudWatchClient {
sess := session.Must(session.NewSessionWithOptions(session.Options{
Config: aws.Config{
Region: aws.String(region),
Credentials: credentials.NewStaticCredentials(accesskey, secretkey, ""),
},
}))
return CloudWatchClient{
client: cloudwatch.New(sess),
Region: region,
AccessKey: accesskey,
SecretKey: secretkey,
}
}
func (cw *CloudWatchClient) SendMetric(namespace string, key string, value float64) (*cloudwatch.PutMetricDataOutput, error) {
result, err := cw.client.PutMetricData(&cloudwatch.PutMetricDataInput{
MetricData: []*cloudwatch.MetricDatum{
&cloudwatch.MetricDatum{
MetricName: aws.String(key),
Unit: aws.String(cloudwatch.StandardUnitNone),
Value: aws.Float64(value),
Dimensions: []*cloudwatch.Dimension{},
},
},
Namespace: aws.String(namespace),
})
if err != nil {
return nil, err
}
return result, nil
}