Cloud watch custom metrics creation with C# (.net) possible or not?

2.8k views Asked by At

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

2

There are 2 answers

4
Marcin Armatys On BEST ANSWER
0
Tiago Sampaio CorrĂȘa On

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