使用C#(。net)创建Cloud watch自定义指标是否成功?

时间:2015-06-02 07:29:02

标签: amazon-web-services amazon-ec2 amazon-cloudwatch cloudwatch

是否可以使用AWS提供的.net SDK创建AWS CloudWatch自定义指标。开发人员指南介绍了如何通过命令行工具发布自定义指标。 是否可以通过.net SDK实现。如果是,请提供链接或教程..

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

我在aws文档中找到了答案。

它在此链接中:https://docs.aws.amazon.com/sdkfornet/latest/apidocs/Index.html 在主题下: Amazon.CloudWatch> AmazonCloudWatchClient> PutMetricData

下面是这个例子

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