github.com/webonyx/up@v0.7.4-0.20180808230834-91b94e551323/internal/metrics/metrics.go (about) 1 // Package metrics provides higher level CloudWatch metrics operations. 2 package metrics 3 4 import ( 5 "time" 6 7 "github.com/aws/aws-sdk-go/aws" 8 "github.com/aws/aws-sdk-go/service/cloudwatch" 9 ) 10 11 // Metrics helper. 12 type Metrics struct { 13 in cloudwatch.GetMetricStatisticsInput 14 } 15 16 // New metrics. 17 func New() *Metrics { 18 return &Metrics{} 19 } 20 21 // Namespace sets the namespace. 22 func (m *Metrics) Namespace(name string) *Metrics { 23 m.in.Namespace = &name 24 return m 25 } 26 27 // Metric sets the metric name. 28 func (m *Metrics) Metric(name string) *Metrics { 29 m.in.MetricName = &name 30 return m 31 } 32 33 // Stats sets the stats. 34 func (m *Metrics) Stats(names []string) *Metrics { 35 m.in.Statistics = aws.StringSlice(names) 36 return m 37 } 38 39 // Stat adds the stat. 40 func (m *Metrics) Stat(name string) *Metrics { 41 m.in.Statistics = append(m.in.Statistics, &name) 42 return m 43 } 44 45 // Dimension adds a dimension. 46 func (m *Metrics) Dimension(name, value string) *Metrics { 47 m.in.Dimensions = append(m.in.Dimensions, &cloudwatch.Dimension{ 48 Name: &name, 49 Value: &value, 50 }) 51 52 return m 53 } 54 55 // Period sets the period in seconds. 56 func (m *Metrics) Period(seconds int) *Metrics { 57 m.in.Period = aws.Int64(int64(seconds)) 58 return m 59 } 60 61 // TimeRange sets the start and time times. 62 func (m *Metrics) TimeRange(start, end time.Time) *Metrics { 63 m.in.StartTime = &start 64 m.in.EndTime = &end 65 return m 66 } 67 68 // Params returns the API input. 69 func (m *Metrics) Params() *cloudwatch.GetMetricStatisticsInput { 70 return &m.in 71 }