public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonCloudWatchConfig config = new AmazonCloudWatchConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonCloudWatchClient client = new AmazonCloudWatchClient(creds, config);

            GetMetricDataResponse resp = new GetMetricDataResponse();

            do
            {
                GetMetricDataRequest req = new GetMetricDataRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxDatapoints = maxItems
                };

                resp = client.GetMetricData(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.Messages)
                {
                    AddObject(obj);
                }

                foreach (var obj in resp.MetricDataResults)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
예제 #2
0
        internal virtual GetMetricDataResponse GetMetricData(GetMetricDataRequest request)
        {
            var marshaller   = GetMetricDataRequestMarshaller.Instance;
            var unmarshaller = GetMetricDataResponseUnmarshaller.Instance;

            return(Invoke <GetMetricDataRequest, GetMetricDataResponse>(request, marshaller, unmarshaller));
        }
예제 #3
0
        private async Task <GetMetricDataResponse> GetMetricsAsync(DateTime startTimeUTC, DateTime endTimeUTC, string metricQueryId, string metricName)
        {
            var req = new GetMetricDataRequest
            {
                StartTimeUtc      = startTimeUTC,
                EndTimeUtc        = endTimeUTC,
                MetricDataQueries = new List <MetricDataQuery>
                {
                    new MetricDataQuery
                    {
                        Id = metricQueryId,

                        MetricStat = new MetricStat
                        {
                            Stat   = "Sum",
                            Metric = new Metric
                            {
                                MetricName = metricName,
                                Namespace  = GA_METRICS_NAMESPACE
                            },
                            Period = ONE_DAY_IN_SECONDS
                        }
                    }
                }
            };

            return(await CloudwatchClient.GetMetricDataAsync(req));
        }
예제 #4
0
        /// <summary>
        /// Initiates the asynchronous execution of the GetMetricData operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the GetMetricData operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/monitoring-2010-08-01/GetMetricData">REST API Reference for GetMetricData Operation</seealso>
        public virtual Task <GetMetricDataResponse> GetMetricDataAsync(GetMetricDataRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = GetMetricDataRequestMarshaller.Instance;
            var unmarshaller = GetMetricDataResponseUnmarshaller.Instance;

            return(InvokeAsync <GetMetricDataRequest, GetMetricDataResponse>(request, marshaller,
                                                                             unmarshaller, cancellationToken));
        }
예제 #5
0
        /// <summary>
        /// Initiates the asynchronous execution of the GetMetricData operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the GetMetricData operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/monitoring-2010-08-01/GetMetricData">REST API Reference for GetMetricData Operation</seealso>
        public virtual Task <GetMetricDataResponse> GetMetricDataAsync(GetMetricDataRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = GetMetricDataRequestMarshaller.Instance;
            options.ResponseUnmarshaller = GetMetricDataResponseUnmarshaller.Instance;

            return(InvokeAsync <GetMetricDataResponse>(request, options, cancellationToken));
        }
예제 #6
0
        internal virtual GetMetricDataResponse GetMetricData(GetMetricDataRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = GetMetricDataRequestMarshaller.Instance;
            options.ResponseUnmarshaller = GetMetricDataResponseUnmarshaller.Instance;

            return(Invoke <GetMetricDataResponse>(request, options));
        }
        public async Task <GetMetricDataResponse> GetMetricData(GetMetricDataRequest metricDataRequest)
        {
            using (var amazonCloudWatchClient = new AmazonCloudWatchClient(awsCredentials, RegionEndpoint.GetBySystemName(Region)))
            {
                var response = await amazonCloudWatchClient.GetMetricDataAsync(metricDataRequest);

                return(response);
            }
        }
        public async Task LoadMetrics(int minutes = 15, int period = 10)
        {
            var cloudWatch = new AmazonCloudWatchClient();

            var getMetricRequest = new GetMetricDataRequest
            {
                StartTimeUtc      = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(minutes)),
                EndTimeUtc        = DateTime.UtcNow,
                MetricDataQueries = new AutoConstructedList <MetricDataQuery>
                {
                    new MetricDataQuery
                    {
                        Id         = "Person".ToLower(),
                        MetricStat = new MetricStat
                        {
                            Metric = new Metric
                            {
                                Namespace  = "Cameras",
                                MetricName = "Confidence",
                                Dimensions = new AutoConstructedList <Dimension>
                                {
                                    new Dimension
                                    {
                                        Name  = "CameraKey",
                                        Value = CameraKey
                                    },
                                    new Dimension
                                    {
                                        Name  = "Label",
                                        Value = "Person"
                                    },
                                    new Dimension
                                    {
                                        Name  = "Source",
                                        Value = "Rekognition"
                                    }
                                }
                            },
                            Period = period,
                            Stat   = "Maximum",
                            Unit   = StandardUnit.Percent
                        },
                        ReturnData = true
                    }
                }
            };

            foreach (var className in ClassNames)
            {
                getMetricRequest.MetricDataQueries.Add(new MetricDataQuery
                {
                    Id         = className.ToLower(),
                    MetricStat = new MetricStat
                    {
                        Metric = new Metric
                        {
                            Namespace  = "Cameras",
                            MetricName = "Confidence",
                            Dimensions = new AutoConstructedList <Dimension>
                            {
                                new Dimension
                                {
                                    Name  = "CameraKey",
                                    Value = CameraKey
                                },
                                new Dimension
                                {
                                    Name  = "Label",
                                    Value = className
                                },
                                new Dimension
                                {
                                    Name  = "Source",
                                    Value = PredictionEndpointName
                                }
                            }
                        },
                        Period = period,
                        Stat   = "Maximum",
                        Unit   = StandardUnit.Percent
                    },
                    ReturnData = true
                });
            }

            var response = await cloudWatch.GetMetricDataAsync(getMetricRequest);

            MetricData = response.MetricDataResults;
            MetricsLoaded?.Invoke(MetricData.Count);
            CreateObservations();
        }