ListMetrics() public method

List the specified metrics. You can use the returned metrics with GetMetricStatistics to obtain statistical data.

Up to 500 results are returned for any one call. To retrieve additional results, use the returned token with subsequent calls.

After you create a metric, allow up to fifteen minutes before the metric appears. Statistics about the metric, however, are available sooner using GetMetricStatistics.

/// Request processing has failed due to some unknown error, exception, or failure. /// /// The value of an input parameter is bad or out-of-range. ///
public ListMetrics ( ) : ListMetricsResponse
return Amazon.CloudWatch.Model.ListMetricsResponse
Ejemplo n.º 1
0
        public void GetMetrics()
        {
            var clientCW         = new Amazon.CloudWatch.AmazonCloudWatchClient();
            var instanceList     = GetInstanceList();
            var availableMetrics = clientCW.ListMetrics();

            foreach (var metric in availableMetrics.Metrics)
            {
                var      statisticTypes    = ConfigurationManager.AppSettings["MetricStatisticTypes"];
                var      statisticTypeList = statisticTypes.Split(';').ToList();
                int      metricPeriod      = Convert.ToInt32(ConfigurationManager.AppSettings["MetricPeriod"]);
                var      cwMetrics         = GetCWMetrics(metric, statisticTypeList, metricPeriod);
                Instance instance          = (metric.Dimensions.Count > 0) ? GetInstance(instanceList, metric.Dimensions[0].Value) : null;
                DBManager.SaveCWMetrics(metric, cwMetrics, instance, statisticTypeList);
                FileManager.SaveCWMetrics(metric, cwMetrics, instance, statisticTypeList);
            }
            S3Manager.UploadMetricFile();
        }
Ejemplo n.º 2
0
    public static void CWListMetrics()
    {
      #region CWListMetrics
      var client = new AmazonCloudWatchClient();

      var filter = new DimensionFilter
      {
        Name = "InstanceType",
        Value = "t1.micro"
      };

      var request = new ListMetricsRequest
      {
        Dimensions = new List<DimensionFilter>() { filter },
        MetricName = "CPUUtilization",
        Namespace = "AWS/EC2"
      };

      var response = new ListMetricsResponse();

      do
      {
        response = client.ListMetrics(request);

        if (response.Metrics.Count > 0)
        {
          foreach (var metric in response.Metrics)
          {
            Console.WriteLine(metric.MetricName +
              " (" + metric.Namespace + ")");

            foreach (var dimension in metric.Dimensions)
            {
              Console.WriteLine("  " + dimension.Name + ": "
                + dimension.Value);
            }
          }
        }
        else
        {
          Console.WriteLine("No metrics found.");
        }

        request.NextToken = response.NextToken;

      } while (!string.IsNullOrEmpty(response.NextToken));
      #endregion

      Console.ReadLine();
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Given a Profile and Region, return a table with data about bucket sizes,
        /// collected from CloudWatch.
        /// </summary>
        /// <param name="aprofile"></param>
        /// <param name="Region2Scan"></param>
        /// <returns></returns>
        public DataTable S3SizeCloudWatch(string aprofile, string Region2Scan)
        {
            DataTable ToReturn =AWSTables.GetS3SizesTable();
            
            string accountid = GetAccountID(aprofile);
            RegionEndpoint Endpoint2scan = RegionEndpoint.USEast1;
            //Convert the Region2Scan to an AWS Endpoint.
            foreach (var aregion in RegionEndpoint.EnumerableAllRegions)
            {
                if (aregion.DisplayName.Equals(Region2Scan))
                {
                    Endpoint2scan = aregion;
                    continue;
                }
            }

            DataTable metlist = new DataTable();
            try
            {
                var credential = new Amazon.Runtime.StoredProfileAWSCredentials(aprofile);
                AmazonCloudWatchClient CWClient = new AmazonCloudWatchClient(credential, Endpoint2scan);
                Amazon.CloudWatch.Model.ListMetricsRequest LMReq = new Amazon.CloudWatch.Model.ListMetricsRequest();               

                //Using to explore the metrics
                LMReq.Namespace = "AWS/S3";
                LMReq.MetricName = "BucketSizeBytes";
                var getmetrics = CWClient.ListMetrics(LMReq).Metrics;

                //This is just stuff I used to view data from the List
                metlist.Columns.Add("MetricName");
                metlist.Columns.Add("NameSpace");

                //These are the dimensions for S3.
                metlist.Columns.Add("Bucketname");
                metlist.Columns.Add("StorageType");

                foreach (var ametric in getmetrics)
                {
                    var DR = metlist.NewRow();
                    try
                    {
                        DR["MetricName"] = ametric.MetricName;
                        DR["NameSpace"] = ametric.Namespace;
                        var dim = ametric.Dimensions;
                        //These are the dimensions for S3.
                        DR["BucketName"] = dim[0].Value;
                        DR["StorageType"] =  dim[1].Value;
                        metlist.Rows.Add(DR);
                    }
                    catch(Exception ex)
                    {

                    }
                }

                // Okay, collect the daters for these here buckets




                foreach (var abucket in metlist.AsEnumerable())
                {
                    Amazon.CloudWatch.Model.GetMetricStatisticsRequest GMReq = new Amazon.CloudWatch.Model.GetMetricStatisticsRequest();
                    string bucketname = abucket[2].ToString();
                    string storagetype = abucket[3].ToString();
                    
                    try
                    {
                        Amazon.CloudWatch.Model.Dimension dimbo = new Amazon.CloudWatch.Model.Dimension();
                        dimbo.Name = "BucketName";
                        dimbo.Value = bucketname;
                        GMReq.Dimensions.Add(dimbo);
                        Amazon.CloudWatch.Model.Dimension dimbo2 = new Amazon.CloudWatch.Model.Dimension();
                        dimbo2.Name = "StorageType";
                        dimbo2.Value = storagetype;
                        GMReq.Dimensions.Add(dimbo2);

                        //Build the request:
                        GMReq.Namespace = "AWS/S3";
                        GMReq.EndTime = DateTime.Now;
                        GMReq.StartTime = DateTime.Now - TimeSpan.FromDays(21);
                        GMReq.Period = (60 * 60 * 24 * 7);//Seconds in a week.
                        GMReq.Statistics.Add("Minimum");
                        GMReq.Statistics.Add("Maximum");
                        GMReq.Statistics.Add("Average");
                        GMReq.MetricName = "BucketSizeBytes";

                        //Execute request:
                        var metricresponse = CWClient.GetMetricStatistics(GMReq);
                        
                        //Process Return
                        var dp = metricresponse.Datapoints;
                         if(dp.Count==0)
                        {
                            //none
                        }


                        var arow = ToReturn.NewRow();

                        Dictionary<DateTime, Amazon.CloudWatch.Model.Datapoint> sortem = new Dictionary<DateTime, Amazon.CloudWatch.Model.Datapoint>();
                        foreach(var ap in dp)
                        {
                            sortem.Add(ap.Timestamp, ap);
                        }
                        var sorteddates = sortem.Keys.ToList();
                        sorteddates.Sort();
                        var firstpass = true;
                        foreach(var key in sorteddates)
                        {
                            var ap = sortem[key];
                            var min = ap.Minimum;
                            var max = ap.Maximum;
                            var av = ap.Average;
                            var ts = ap.Timestamp;

                            if (firstpass)
                            {
                                firstpass = false;
                                arow["AccountID"] = accountid;
                                arow["Profile"] = aprofile;
                                arow["Bucket"] = bucketname;
                                arow["Region"] = Region2Scan;
                                arow["StartDate"] = ts.ToShortDateString();
                                arow["EndDate"] = ts.ToShortDateString();
                                arow["StartSizeMin"] =GetFileSize( min);
                                arow["StartSizeMax"] =GetFileSize( max);
                                arow["StartSizeAVG"]= GetFileSize(av);
                            }
                            else
                            {
                                arow["EndDate"] = ts.ToShortDateString();
                                arow["EndSizeMin"] = GetFileSize(min);
                                arow["EndSizeAVG"] = GetFileSize(av);
                                arow["EndSizeMax"] = GetFileSize(max);
                                arow["EndSizeMaxBytes"] = Math.Round(av);

                            }
                        }
                        ToReturn.Rows.Add(arow.ItemArray);
                    }
                    catch(Exception ex)
                    {

                    }
                }


            }
            catch(Exception ex)
            {

            }
            int buckets = metlist.Rows.Count;

            int returning = ToReturn.Rows.Count;
            return ToReturn;
        }