Beispiel #1
0
// Helper function to send data.
func Send(cw *cloudwatch.CloudWatch, dn, dv, n string, v float64) {
	_, err := cw.PutMetricData(&cloudwatch.PutMetricDataInput{
		MetricData: []*cloudwatch.MetricDatum{
			{
				MetricName: aws.String(n),
				Dimensions: []*cloudwatch.Dimension{
					{
						Name:  aws.String(dn),
						Value: aws.String(dv),
					},
				},
				Timestamp: aws.Time(time.Now()),
				Value:     aws.Float64(v),
			},
		},
		Namespace: aws.String("Custom"),
	})
	if err != nil {
		log.Println(err)
		return
	}

	log.WithFields(log.Fields{
		"DimensionName":  dn,
		"DimensionValue": dv,
		"MetricName":     n,
		"MetricValue":    v,
	}).Info("Successfully posted to CloudWatch")
}
Beispiel #2
0
func putMetric(metricName string, watchService *cloudwatch.CloudWatch, unitName string, metricValue float64) {
	if watchService == nil {
		return
	}

	params := &cloudwatch.PutMetricDataInput{
		MetricData: []*cloudwatch.MetricDatum{
			&cloudwatch.MetricDatum{
				MetricName: aws.String(metricName),
				Timestamp:  aws.Time(time.Now()),
				Unit:       aws.String(unitName),
				Value:      aws.Float64(metricValue),
			},
		},
		Namespace: aws.String(cloudwatchNamespace),
	}

	_, err := watchService.PutMetricData(params)
	if err != nil {
		log.Printf("Failure to put cloudwatch metric: %s", err)
	}
}