/
cloudwatch.go
54 lines (49 loc) · 1.22 KB
/
cloudwatch.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
50
51
52
53
54
package fictionbase
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/spf13/viper"
)
// Cw Service Client Operator
type Cw struct {
sess *session.Session
svc *cloudwatch.CloudWatch
}
// NewCw Create New cloudwatch struct
func NewCw() *Cw {
SetViperConfig()
sess := session.Must(session.NewSession(&aws.Config{
Region: aws.String(viper.GetString("region"))},
))
svc := cloudwatch.New(sess)
c := &Cw{
sess: sess,
svc: svc,
}
return c
}
// SendCloudWatch send data to CloudWatch
func (Cw Cw) SendCloudWatch(input *cloudwatch.PutMetricDataInput) error {
_, err := Cw.svc.PutMetricData(input)
if err != nil {
return err
}
return nil
}
// GetCloudWatch get data to CloudWatch
func (Cw Cw) GetCloudWatch(nameSpace string, metricName string, dimensionsName string) *cloudwatch.ListMetricsOutput {
result, err := Cw.svc.ListMetrics(&cloudwatch.ListMetricsInput{
Namespace: aws.String(nameSpace),
MetricName: aws.String(metricName),
Dimensions: []*cloudwatch.DimensionFilter{
&cloudwatch.DimensionFilter{
Name: aws.String(dimensionsName),
},
},
})
if err != nil {
Logger.Error(err.Error())
}
return result
}