Question

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?).

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top