A recipe for getting consumption ir usage with the OCI usage rest API.
First, clone this repo
git clone https://github.com/javiermugueta/oci-rest.git cd oci-rest
Set your environment
put your pivate key in a file called myppk vi my-oci-env ... # # put here your tenancy and user data # tenancyId="ocid1.tenancy.oc1..aaaaaaaaei..."; authUserId="ocid1.user.oc1..aaaaaa..."; keyFingerprint="eb:..."; # privateKeyPath=./myppk #
Put in a json file the request, for exmaple:
{ "granularity": "HOURLY", "tenantId": "ocid1.tenancy.oc1..aaaaaaaaeicd...", "timeUsageStarted": "2021-02-10T00:00:00.000Z", "timeUsageEnded": "2021-02-11T00:00:00.000Z" }
Now run this using the endpoint according with your primary (home) region
./oci-rest usageapi.eu-frankfurt-1.oci.oraclecloud.com post body.json "/20200107/usage" Usage: oci-rest <api-endpoint-without-protocol> <verb> [<jsonfile for post verb>] <method> verb: get, post,... >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> { "groupBy" : null, "items" : [ { "tenantId" : null, "tenantName" : null, "compartmentId" : null, "compartmentPath" : null, "compartmentName" : null, "service" : null, "resourceName" : null, "resourceId" : null, "region" : null, "ad" : null, "weight" : null, "shape" : null, "skuPartNumber" : null, "skuName" : null, "unit" : null, "discount" : null, "listRate" : null, "platform" : null, "timeUsageStarted" : "2021-02-10T12:00:00.000Z", "timeUsageEnded" : "2021-02-10T13:00:00.000Z", "computedAmount" : null, "computedQuantity" : 0, "overagesFlag" : null, "unitPrice" : null, "currency" : " ", "subscriptionId" : null, "overage" : null, "tags" : [ { "namespace" : null, "key" : null, "value" : null } ] }, { "tenantId" : null, "tenantName" : null, ....
That’s all, hope it helps! 🙂
See also