/// <summary> /// Initiates the asynchronous execution of the GetRightsizingRecommendation operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the GetRightsizingRecommendation operation on AmazonCostExplorerClient.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndGetRightsizingRecommendation /// operation.</returns> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/ce-2017-10-25/GetRightsizingRecommendation">REST API Reference for GetRightsizingRecommendation Operation</seealso> public virtual IAsyncResult BeginGetRightsizingRecommendation(GetRightsizingRecommendationRequest request, AsyncCallback callback, object state) { var options = new InvokeOptions(); options.RequestMarshaller = GetRightsizingRecommendationRequestMarshaller.Instance; options.ResponseUnmarshaller = GetRightsizingRecommendationResponseUnmarshaller.Instance; return(BeginInvoke(request, options, callback, state)); }
public async Task <GetRightsizingRecommendationResponse> GetHighRecommActivities() { GetRightsizingRecommendationRequest rightsizingRecommendationRequest = new GetRightsizingRecommendationRequest(); rightsizingRecommendationRequest.Service = "AmazonEC2"; var response = await costExplorerRepository.GetRightsizingRecommendation(rightsizingRecommendationRequest); var highRecomActivities = response.RightsizingRecommendations.SelectMany(x => x.ModifyRecommendationDetail.TargetInstances).Select(y => new { y.ResourceDetails.EC2ResourceDetails.InstanceType, y.ResourceDetails.EC2ResourceDetails.Memory, y.ResourceDetails.EC2ResourceDetails.Vcpu }); return(response); }
public async Task <object> GetCpuVsRecommendCpuUsage() { GetRightsizingRecommendationRequest rightsizingRecommendationRequest = new GetRightsizingRecommendationRequest(); rightsizingRecommendationRequest.Service = "AmazonEC2"; var response = await costExplorerRepository.GetRightsizingRecommendation(rightsizingRecommendationRequest); var cpuUsageDetails = response.RightsizingRecommendations.Select(x => new { ResourceId = x.CurrentInstance.ResourceId, RecommendCpu = Convert.ToDecimal(x.ModifyRecommendationDetail.TargetInstances.FirstOrDefault().ExpectedResourceUtilization.EC2ResourceUtilization.MaxCpuUtilizationPercentage), CPUusage = Convert.ToDecimal(x.CurrentInstance.ResourceUtilization.EC2ResourceUtilization.MaxCpuUtilizationPercentage), }); return(cpuUsageDetails); }
public async Task <object> GetUsedVsUnusedCpu() { GetRightsizingRecommendationRequest rightsizingRecommendationRequest = new GetRightsizingRecommendationRequest(); rightsizingRecommendationRequest.Service = "AmazonEC2"; var response = await costExplorerRepository.GetRightsizingRecommendation(rightsizingRecommendationRequest); var cpuUsageDetails = response.RightsizingRecommendations.Select(x => new { ResourceId = x.CurrentInstance.ResourceId, UnusedCPUusage = 100 - Convert.ToDecimal(x.CurrentInstance.ResourceUtilization.EC2ResourceUtilization.MaxCpuUtilizationPercentage), CPUusage = Convert.ToDecimal(x.CurrentInstance.ResourceUtilization.EC2ResourceUtilization.MaxCpuUtilizationPercentage), }); return(cpuUsageDetails.ToList()); }
public async Task <object> GetCostVsSavings() { GetRightsizingRecommendationRequest rightsizingRecommendationRequest = new GetRightsizingRecommendationRequest(); rightsizingRecommendationRequest.Service = "AmazonEC2"; var response = await costExplorerRepository.GetRightsizingRecommendation(rightsizingRecommendationRequest); var recommendationResponse = response.RightsizingRecommendations.Select(x => new { ResourceId = x.CurrentInstance.ResourceId, Cost = Convert.ToDecimal(x.CurrentInstance.MonthlyCost), Saving = Convert.ToDecimal(x.ModifyRecommendationDetail.TargetInstances.FirstOrDefault().EstimatedMonthlyCost) }); return(recommendationResponse); }
public async Task <CostRecommendationSummaryResponse> GetCostSummary() { GetRightsizingRecommendationRequest rightsizingRecommendationRequest = new GetRightsizingRecommendationRequest(); rightsizingRecommendationRequest.Service = "AmazonEC2"; var response = await costExplorerRepository.GetRightsizingRecommendation(rightsizingRecommendationRequest); var currentCost = response.RightsizingRecommendations.Select(x => Convert.ToDouble(string.IsNullOrEmpty(x.CurrentInstance?.MonthlyCost)?"0": x.CurrentInstance?.MonthlyCost)).Sum(); return(new CostRecommendationSummaryResponse() { TotalInstance = Convert.ToInt32(string.IsNullOrEmpty(response.Summary?.TotalRecommendationCount)?"0": response.Summary?.TotalRecommendationCount), Savings = Math.Round(Convert.ToDouble(string.IsNullOrEmpty(response.Summary?.EstimatedTotalMonthlySavingsAmount)?"0": response.Summary?.EstimatedTotalMonthlySavingsAmount), 2), RecommendedCost = Math.Round(currentCost - Convert.ToDouble(string.IsNullOrEmpty(response.Summary?.EstimatedTotalMonthlySavingsAmount) ? "0" : response.Summary?.EstimatedTotalMonthlySavingsAmount), 2), CurrentCost = Math.Round(currentCost, 2) }); }
public async Task <List <CostRecommendationResponse> > GetCostSummaryDetails() { GetRightsizingRecommendationRequest rightsizingRecommendationRequest = new GetRightsizingRecommendationRequest(); rightsizingRecommendationRequest.Service = "AmazonEC2"; var response = await costExplorerRepository.GetRightsizingRecommendation(rightsizingRecommendationRequest); var recommendationResponse = response.RightsizingRecommendations.Select(x => new CostRecommendationResponse { ResourceId = x.CurrentInstance?.ResourceId, Cost = Convert.ToDecimal(x.CurrentInstance?.MonthlyCost), RecommendCost = Convert.ToDecimal(x.ModifyRecommendationDetail?.TargetInstances?.FirstOrDefault()?.EstimatedMonthlyCost), //TotalMonthlySavings = Convert.ToDecimal(x.CurrentInstance.MonthlyCost) - Convert.ToDecimal(x.ModifyRecommendationDetail.TargetInstances.FirstOrDefault().EstimatedMonthlyCost) Size = x.CurrentInstance?.ResourceDetails?.EC2ResourceDetails?.InstanceType, RecommendSize = x.ModifyRecommendationDetail.TargetInstances.FirstOrDefault()?.ResourceDetails?.EC2ResourceDetails?.InstanceType }); return(recommendationResponse.ToList()); }
/// <summary> /// Creates recommendations that helps you save cost by identifying idle and underutilized /// Amazon EC2 instances. /// /// /// <para> /// Recommendations are generated to either downsize or terminate instances, along with /// providing savings detail and metrics. For details on calculation and function, see /// <a href="https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/ce-what-is.html">Optimizing /// Your Cost with Rightsizing Recommendations</a>. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the GetRightsizingRecommendation service method.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// /// <returns>The response from the GetRightsizingRecommendation service method, as returned by CostExplorer.</returns> /// <exception cref="Amazon.CostExplorer.Model.InvalidNextTokenException"> /// The pagination token is invalid. Try again without a pagination token. /// </exception> /// <exception cref="Amazon.CostExplorer.Model.LimitExceededException"> /// You made too many calls in a short period of time. Try again later. /// </exception> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/ce-2017-10-25/GetRightsizingRecommendation">REST API Reference for GetRightsizingRecommendation Operation</seealso> public virtual Task <GetRightsizingRecommendationResponse> GetRightsizingRecommendationAsync(GetRightsizingRecommendationRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var options = new InvokeOptions(); options.RequestMarshaller = GetRightsizingRecommendationRequestMarshaller.Instance; options.ResponseUnmarshaller = GetRightsizingRecommendationResponseUnmarshaller.Instance; return(InvokeAsync <GetRightsizingRecommendationResponse>(request, options, cancellationToken)); }
internal virtual GetRightsizingRecommendationResponse GetRightsizingRecommendation(GetRightsizingRecommendationRequest request) { var options = new InvokeOptions(); options.RequestMarshaller = GetRightsizingRecommendationRequestMarshaller.Instance; options.ResponseUnmarshaller = GetRightsizingRecommendationResponseUnmarshaller.Instance; return(Invoke <GetRightsizingRecommendationResponse>(request, options)); }
public async Task <GetRightsizingRecommendationResponse> GetRightsizingRecommendation(GetRightsizingRecommendationRequest rightsizingRecommendationRequest) { using (var amazonCostExplorerClient = new AmazonCostExplorerClient(awsCredentials, RegionEndpoint.GetBySystemName("us-east-1"))) { var response = await amazonCostExplorerClient.GetRightsizingRecommendationAsync(rightsizingRecommendationRequest); return(response); } }