本文整理匯總了Golang中github.com/crowdmob/goamz/cloudwatch.CloudWatch類的典型用法代碼示例。如果您正苦於以下問題:Golang CloudWatch類的具體用法?Golang CloudWatch怎麽用?Golang CloudWatch使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CloudWatch類的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
}