如何在C#中更新Cloudwatch自定义指标?

时间:2014-02-28 20:59:44

标签: c# .net amazon-web-services amazon-cloudwatch

如何在C#中为我的Elastic Beanstalk环境创建自定义指标

我有一个数字指标seconds

我使用以下代码:

 double seconds = ts.Seconds + (Convert.ToDouble(ts.Milliseconds / 10) / 100);

 using (AmazonCloudWatchClient cloudwatch = new AmazonCloudWatchClient(accessKey, secretKey))
  {
          PutMetricDataRequest mdr = new PutMetricDataRequest();
           mdr.Namespace = "Performance";

           MetricDatum dataPoint = new MetricDatum();
            dataPoint.MetricName = "UploadSpeedInSeconds";
            dataPoint.Unit = "Seconds";
            dataPoint.Value = seconds;
  }

我不知道要继续下去。我希望自定义指标能够在几秒钟内完成上传文件。我已经有度量值,我想更新自定义指标,以便跟踪它(BTW:我可以在控制台中查看自定义指标吗?)。

1 个答案:

答案 0 :(得分:9)

不要忘记将其实际发送给AWS:

            mdr.MetricData = new List<MetricDatum>();
            mdr.MetricData.Add(dataPoint);

            PutMetricDataResponse resp = cloudwatch.PutMetricData(mdr);
            Debug.Assert(resp.HttpStatusCode == System.Net.HttpStatusCode.OK);