/// <summary> /// Returns usage for the given account. /// </summary> /// <param name="request"></param> /// <returns></returns> public RequestSummarizedUsagesResponse RequestSummarizedUsages(RequestSummarizedUsagesRequest request) { var uriStr = $"{GetEndPoint(UsageServices.Usage, this.Region, "oci.oraclecloud.com")}"; var options = request.GetOptions(); if (!string.IsNullOrEmpty(options)) { uriStr = uriStr + "?" + options; } var uri = new Uri(uriStr); var httpRequestHeaderParam = new HttpRequestHeaderParam() { OpcRequestId = request.OpcRequestId, }; using (var webResponse = this.RestClient.Post(uri, request.RequestSummarizedUsagesDetails, httpRequestHeaderParam)) using (var stream = webResponse.GetResponseStream()) using (var reader = new StreamReader(stream)) { var response = reader.ReadToEnd(); return(new RequestSummarizedUsagesResponse() { UsageAggregation = this.JsonSerializer.Deserialize <UsageAggregation>(response), OpcRequestId = webResponse.Headers.Get("opc-request-id"), OpcNextPage = webResponse.Headers.Get("opc-next-page") }); } }
/// <summary> /// Returns usage for the given account. /// /// </summary> /// <param name="request">The request object containing the details to send. Required.</param> /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param> /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param> /// <returns>A response object containing details about the completed operation</returns> /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/usageapi/RequestSummarizedUsages.cs.html">here</a> to see an example of how to use RequestSummarizedUsages API.</example> public async Task <RequestSummarizedUsagesResponse> RequestSummarizedUsages(RequestSummarizedUsagesRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { logger.Trace("Called requestSummarizedUsages"); Uri uri = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/usage".Trim('/'))); HttpMethod method = new HttpMethod("POST"); HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request); requestMessage.Headers.Add("Accept", "application/json"); GenericRetrier retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration); HttpResponseMessage responseMessage; try { if (retryingClient != null) { responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false); } else { responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false); } this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage); return(Converter.FromHttpResponseMessage <RequestSummarizedUsagesResponse>(responseMessage)); } catch (Exception e) { logger.Error($"RequestSummarizedUsages failed with error: {e.Message}"); throw; } }
public static void Example(ClientConfig config) { var client = new UsageClient(config) { Region = Regions.AP_TOKYO_1 }; RequestSummarizedConfigurationsRequest configurationsRequest = new RequestSummarizedConfigurationsRequest { TenantId = config.TenancyId }; var configurations = client.RequestSummarizedConfigurations(configurationsRequest); RequestSummarizedUsagesRequest usagesRequest = new RequestSummarizedUsagesRequest { RequestSummarizedUsagesDetails = new OCISDK.Core.Usage.Model.RequestSummarizedUsagesDetails { TenantId = config.TenancyId, TimeUsageStarted = DateTime.UtcNow.AddDays(-1).ToString("yyyy-MM-ddTHH:mm:ssZ"), TimeUsageEnded = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"), Granularity = GranularityParam.DAILY } }; Console.WriteLine("Daily cost info -----------------------------"); do { var consts = client.RequestSummarizedUsages(usagesRequest); foreach (var cost in consts.UsageAggregation.Items) { Console.WriteLine("start:" + cost.TimeUsageStarted + " - end:" + cost.TimeUsageEnded); Console.WriteLine("service:" + cost.Service); Console.WriteLine("resource:" + cost.ResourceName + "(" + cost.ResourceId + ")"); Console.WriteLine("amount:" + cost.ComputedAmount + "(" + cost.Currency + ")"); Console.WriteLine("overage:" + cost.Overage + "(" + cost.Currency + ")"); } if (string.IsNullOrEmpty(consts.OpcNextPage)) { break; } usagesRequest.Page = consts.OpcNextPage; } while (true); }
protected override void ProcessRecord() { base.ProcessRecord(); RequestSummarizedUsagesRequest request; try { request = new RequestSummarizedUsagesRequest { RequestSummarizedUsagesDetails = RequestSummarizedUsagesDetails, OpcRequestId = OpcRequestId, Page = Page, Limit = Limit }; response = client.RequestSummarizedUsages(request).GetAwaiter().GetResult(); WriteOutput(response, response.UsageAggregation); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }