本文整理汇总了Golang中github.com/crowdmob/goamz/cloudwatch.CloudWatch.GetMetricStatistics方法的典型用法代码示例。如果您正苦于以下问题:Golang CloudWatch.GetMetricStatistics方法的具体用法?Golang CloudWatch.GetMetricStatistics怎么用?Golang CloudWatch.GetMetricStatistics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/crowdmob/goamz/cloudwatch.CloudWatch
的用法示例。
在下文中一共展示了CloudWatch.GetMetricStatistics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getLastPoint
func getLastPoint(cloudWatch *cloudwatch.CloudWatch, dimensions *[]cloudwatch.Dimension, metricName string) (float64, error) {
now := time.Now()
response, err := cloudWatch.GetMetricStatistics(&cloudwatch.GetMetricStatisticsRequest{
Dimensions: *dimensions,
StartTime: now.Add(time.Duration(180) * time.Second * -1), // 3 mins (to fetch at least 1 data-point)
EndTime: now,
MetricName: metricName,
Period: 60,
Statistics: []string{"Average"},
Namespace: "AWS/ElastiCache",
})
if err != nil {
return 0, err
}
datapoints := response.GetMetricStatisticsResult.Datapoints
if len(datapoints) == 0 {
return 0, errors.New("fetched no datapoints")
}
latest := time.Unix(0, 0)
var latestVal float64
for _, dp := range datapoints {
if dp.Timestamp.Before(latest) {
continue
}
latest = dp.Timestamp
latestVal = dp.Average
}
return latestVal, nil
}
示例2: getLastPointAverage
func getLastPointAverage(cw *cloudwatch.CloudWatch, dimension *cloudwatch.Dimension, metricName string) (float64, error) {
namespace := "AWS/EC2"
now := time.Now()
prev := now.Add(time.Duration(600) * time.Second * -1) // 10 min (to fetch at least 1 data-point)
request := &cloudwatch.GetMetricStatisticsRequest{
Dimensions: []cloudwatch.Dimension{*dimension},
EndTime: now,
StartTime: prev,
MetricName: metricName,
Period: 60,
Statistics: []string{"Average"},
Namespace: namespace,
}
response, err := cw.GetMetricStatistics(request)
if err != nil {
return 0, err
}
datapoints := response.GetMetricStatisticsResult.Datapoints
if len(datapoints) == 0 {
return 0, errors.New("fetched no datapoints")
}
latest := time.Unix(0, 0)
var latestVal float64
for _, dp := range datapoints {
if dp.Timestamp.Before(latest) {
continue
}
latest = dp.Timestamp
latestVal = dp.Average
}
return latestVal, nil
}