當前位置: 首頁>>代碼示例>>Golang>>正文


Golang CloudWatch.GetMetricStatistics方法代碼示例

本文整理匯總了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
}
開發者ID:yano3,項目名稱:mackerel-agent-plugins,代碼行數:34,代碼來源:aws-elasticache.go

示例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
}
開發者ID:netmarkjp,項目名稱:mackerel-agent-plugins,代碼行數:38,代碼來源:aws-ec2-cpucredit.go


注:本文中的github.com/crowdmob/goamz/cloudwatch.CloudWatch.GetMetricStatistics方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。