0

Is it possible to create AWS CloudWatch custom metrics using .net SDK provided by AWS. The developer guide talks about publishing custom metrics through Command line tools. Is it possible by the .net SDK. if yes, please provide the links or tutorials for that..

Nikhil Saswade
  • 167
  • 2
  • 6
  • 16

2 Answers2

2

I found the answer on the aws documentation.

It is in this link: https://docs.aws.amazon.com/sdkfornet/latest/apidocs/Index.html Under the topic: Amazon.CloudWatch > AmazonCloudWatchClient > PutMetricData

There is this example bellow

var client = new AmazonCloudWatchClient();
 
var dimension = new Dimension
{
  Name = "Desktop Machine Metrics",
  Value = "Virtual Desktop Machine Usage"
};
 
var metric1 = new MetricDatum
{
  Dimensions = new List<Dimension>(),
  MetricName = "Desktop Machines Online",
  StatisticValues = new StatisticSet(),
  Timestamp = DateTime.Today,
  Unit = StandardUnit.Count,
  Value = 14
};
 
var metric2 = new MetricDatum
{
  Dimensions = new List<Dimension>(),
  MetricName = "Desktop Machines Offline",
  StatisticValues = new StatisticSet(),
  Timestamp = DateTime.Today,
  Unit = StandardUnit.Count,
  Value = 7
};
 
var metric3 = new MetricDatum
{
  Dimensions = new List<Dimension>(),
  MetricName = "Desktop Machines Online",
  StatisticValues = new StatisticSet(),
  Timestamp = DateTime.Today,
  Unit = StandardUnit.Count,
  Value = 12
};
 
var metric4 = new MetricDatum
{
  Dimensions = new List<Dimension>(),
  MetricName = "Desktop Machines Offline",
  StatisticValues = new StatisticSet(),
  Timestamp = DateTime.Today,
  Unit = StandardUnit.Count,
  Value = 9
};
 
var request = new PutMetricDataRequest
{
  MetricData = new List<MetricDatum>() { metric1, metric2, 
    metric3, metric4 },
  Namespace = "Example.com Custom Metrics"
};
 
client.PutMetricData(request);
0

Here is a documentation of .NET API http://docs.aws.amazon.com/sdkfornet/latest/apidocs/Index.html

Marcin Armatys
  • 599
  • 9
  • 25
  • How can we use this two methods GetMetricsStatesticsRequest() and GetMetricsStatesticResponce() to get Metrics data of Amazon Metrics? – Nikhil Saswade Jun 04 '15 at 09:07
  • can you please give me an example for CPUUtilization metrics – Nikhil Saswade Jun 04 '15 at 09:07
  • Look at example at:http://docs.aws.amazon.com/sdkfornet/latest/apidocs/items/TCloudWatch_CloudWatchNET4_5.html. – Marcin Armatys Jun 08 '15 at 11:50
  • How could this be the answer? The question is about creating custom metrics using AWS SDK and not asking for a reference to it. And the link in the comments doesn't work – Sam Aug 28 '19 at 04:05