Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I update a Cloudwatch custom metric in C#?

How do I create a custom metric for my Elastic Beanstalk environment in C#?

I have a numerical metric seconds.

I use the following code:

 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;
  }

I have no idea were to continue on. I want the custom metric to mesuare the uploads in seconds of files. I already have the metric value, and I want to update a custom metric so I can keep track of it (BTW: can I view the custom metric in the console?).

like image 369
Idan Shechter Avatar asked Feb 28 '14 20:02

Idan Shechter


People also ask

How do I edit CloudWatch metric?

To change the metric, choose Edit, choose the All metrics tab, and do one of the following: Choose the service namespace that contains the metric that you want. Continue choosing options as they appear to narrow the choices. When a list of metrics appears, select the check box next to the metric that you want.

How long does it take for CloudWatch metrics to update?

CloudWatch Metrics now supports the following three retention schedules: 1 minute datapoints are available for 15 days. 5 minute datapoints are available for 63 days. 1 hour datapoints are available for 455 days.


1 Answers

Don't forget to actually send it off to AWS:

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

            PutMetricDataResponse resp = cloudwatch.PutMetricData(mdr);
            Debug.Assert(resp.HttpStatusCode == System.Net.HttpStatusCode.OK);
like image 112
DocKell Avatar answered Sep 28 '22 05:09

DocKell