AWSSDKDocSamples.CloudWatch.CloudWatchSamples.CWPutMetricAlarm C# (CSharp) Method

CWPutMetricAlarm() public static method

public static CWPutMetricAlarm ( ) : void
return void
    public static void CWPutMetricAlarm()
    {
      #region CWPutMetricAlarm
      var client = new AmazonCloudWatchClient();

      var dimension = new Dimension
      {
        Name = "Desktop Machine Metrics",
        Value = "Virtual Desktop Machine Usage"
      };

      var request = new PutMetricAlarmRequest
      {
        ActionsEnabled = true,
        AlarmActions = new List<string>() 
          { "arn:aws:sns:us-east-1:80398EXAMPLE:CodingTestResults" },
        AlarmDescription = "Too many instances offline",
        AlarmName = "Offline Instances",
        ComparisonOperator = ComparisonOperator.GreaterThanOrEqualToThreshold,
        Dimensions = new List<Dimension>() { dimension },
        EvaluationPeriods = 1,
        MetricName = "Desktop Machines Offline",
        Namespace = "Example.com Custom Metrics",
        Period = (int)TimeSpan.FromMinutes(5).TotalSeconds,
        Statistic = new Statistic("Maximum"),
        Threshold = 5,
        Unit = StandardUnit.Count
      };

      client.PutMetricAlarm(request);
      #endregion
    }