Permalink
Browse files

CloudWatch only accepts maximum of 20 data metrics per request. We th…

…erefore split any incoming metrics in to groups of 20 before sending.
  • Loading branch information...
1 parent 7040e94 commit 04ad53522ed178f03b83926021ca783d4f2d42f4 Peter Miller committed May 13, 2012
Showing with 9 additions and 3 deletions.
  1. +9 −3 Class Libraries/Natol.PerformanceCounter2CloudWatch.Framework/CounterManager.cs
@@ -141,10 +141,16 @@ private void SendMetrics(IList<MetricDatum> data, string dataNamesspace)
//setup cloudwatch service
AmazonCloudWatch client = Amazon.AWSClientFactory.CreateAmazonCloudWatchClient(appSettings["AWS-CloudWatch-AccessKey"], appSettings["AWS-CloudWatch-SecretKey"], new AmazonCloudWatchConfig { ServiceURL = appSettings["AWS-CloudWatch-ServiceUrl"] });
- client.PutMetricData(new PutMetricDataRequest()
- .WithMetricData(data)
- .WithNamespace(dataNamesspace));
+ //cloud-watch only lets us send maximum of 20 pieces of metric data per request,
+ // so split in to groups of 20
+ var dataGrp = from i in Enumerable.Range(0, data.Count())
+ group data[i] by i / 20;
+ dataGrp.ToList().ForEach(dataSet =>
+ client.PutMetricData(new PutMetricDataRequest()
+ .WithMetricData(dataSet.AsEnumerable())
+ .WithNamespace(dataNamesspace))
+ );
}

0 comments on commit 04ad535

Please sign in to comment.