示例#1
0
func goStats(cw *cloudwatch.CloudWatch, requests *[]cloudwatch.GetMetricStatisticsRequest, now time.Time, statsCli *statsd.StatsdBuffer) {
	log.WithField("now", now).Debug("tick")
	for _, request := range *requests {
		request.EndTime = now
		request.StartTime = now.Add(time.Minute * -1) // 1 minute ago

		response, err := cw.GetMetricStatistics(&request)
		if err != nil {
			log.WithField("error", err).Warn("could not retrieve metric from cloudwatch")
		}

		for _, dp := range response.GetMetricStatisticsResult.Datapoints {
			statsCli.Absolute(fmt.Sprintf("%s.%s", strings.ToLower(request.Dimensions[0].Value), strings.ToLower(request.MetricName)), int64(dp.Sum))
		}
	}
}
示例#2
0
func getMetricRequests(cw *cloudwatch.CloudWatch) ([]cloudwatch.GetMetricStatisticsRequest, error) {
	metricsRequest := &cloudwatch.ListMetricsRequest{Namespace: "AWS/SQS"}
	response, err := cw.ListMetrics(metricsRequest)
	if err != nil {
		return nil, err
	}

	outRequests := make([]cloudwatch.GetMetricStatisticsRequest, len(response.ListMetricsResult.Metrics))
	for i, metric := range response.ListMetricsResult.Metrics {
		outRequests[i] = cloudwatch.GetMetricStatisticsRequest{
			Dimensions: metric.Dimensions,
			MetricName: metric.MetricName,
			Namespace:  metric.Namespace,
			Period:     60,
			Statistics: []string{"Sum"},
		}
	}

	return outRequests, err
}