{"id":1393,"date":"2024-06-07T02:10:22","date_gmt":"2024-06-07T02:10:22","guid":{"rendered":"https:\/\/adrianotanaka.com.br\/?p=1393"},"modified":"2024-09-30T00:06:33","modified_gmt":"2024-09-30T00:06:33","slug":"a-script-to-work-with-oci-cost-api-usage-api","status":"publish","type":"post","link":"https:\/\/adrianotanaka.com.br\/index.php\/2024\/06\/07\/a-script-to-work-with-oci-cost-api-usage-api\/","title":{"rendered":"A script to work with OCI Cost API (usage-api)"},"content":{"rendered":"\n<p>OCI has a great interface to gather Cost and Usage reports, but imagine that you have a tenancy with almost 300 compartments and you need to build a report with the cost by each one?<\/p>\n\n\n\n<p>I know that you can export the reports in PDF format(or CSV), but you will need to do some type of work to aggregate it, so this script will help you, the main goal here is to get the last 7 days of cost from the last Sunday (that&#8217;s why the script is called show_costs_<strong>week<\/strong>.sh).<\/p>\n\n\n\n<p>As usual, this script uses the oci cli (you need to have it installed and configured before using the script), and to keep the things clear, <strong>this is not an official script from Oracle<\/strong>, use it to just estimate the cost! <\/p>\n\n\n\n<p>Example of output:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[opc@XXXXX ~]$ \/home\/opc\/XXX\/show_costs_week.sh TENANCY ocid1.tenancy.oc1..XXX us-ashburn-1\n-------------------------------------------------------------------------------------------------------------------------------------------------\nProfile: TENANCY| Begin Date: 2024-05-26 | End Date: 2024-06-02\n-------------------------------------------------------------------------------------------------------------------------------------------------\nCompartment:  compB\n-------------------------------------------------------------------------------------------------------------------------------------------------\n+----------------------------------------+------------------+---------------------------+---------------------------+-----------------+\n| CompPath                               | CompartName      | Fim                       | Inicio                    | Valor           |\n+----------------------------------------+------------------+---------------------------+---------------------------+-----------------+\n| root\/compA\/compB | compB | 2024-05-27T00:00:00+00:00 | 2024-05-26T00:00:00+00:00 | 23.002692666972 |\n| root\/compA\/compB | compB | 2024-05-30T00:00:00+00:00 | 2024-05-29T00:00:00+00:00 | 22.898028714713 |\n| root\/compA\/compB | compB | 2024-06-02T00:00:00+00:00 | 2024-06-01T00:00:00+00:00 | 46.408353207519 |\n| root\/compA\/compB | compB | 2024-06-01T00:00:00+00:00 | 2024-05-31T00:00:00+00:00 | 22.740664837568 |\n| root\/compA\/compB | compB | 2024-05-29T00:00:00+00:00 | 2024-05-28T00:00:00+00:00 | 20.279208945572 |\n| root\/compA\/compB | compB | 2024-05-31T00:00:00+00:00 | 2024-05-30T00:00:00+00:00 | 22.725654484152 |\n| root\/compA\/compB | compB | 2024-05-28T00:00:00+00:00 | 2024-05-27T00:00:00+00:00 | 23.493054517126 |\n+----------------------------------------+------------------+---------------------------+---------------------------+-----------------+\nTotal for compB compartment: 181.548\n<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Get the script from my GitHub : <a href=\"https:\/\/github.com\/adrianotanaka\/scripts\/blob\/master\/oci\/cli\/show_costs_week.sh\">scripts\/oci\/cli\/show_costs_week.sh at master \u00b7 adrianotanaka\/scripts (github.com)<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>If you have any problem or suggestion, feel free to get in touch.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>OCI has a great interface to gather Cost and Usage reports, but imagine that you have a tenancy with almost 300 compartments and you need to build a report with the cost by each one? I know that you can export the reports in PDF format(or CSV), but you will need to do some type [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1398,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"material-hide-sections":[],"footnotes":""},"categories":[55,19],"tags":[],"class_list":["post-1393","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-api","category-cli"],"_links":{"self":[{"href":"https:\/\/adrianotanaka.com.br\/index.php\/wp-json\/wp\/v2\/posts\/1393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adrianotanaka.com.br\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adrianotanaka.com.br\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adrianotanaka.com.br\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/adrianotanaka.com.br\/index.php\/wp-json\/wp\/v2\/comments?post=1393"}],"version-history":[{"count":9,"href":"https:\/\/adrianotanaka.com.br\/index.php\/wp-json\/wp\/v2\/posts\/1393\/revisions"}],"predecessor-version":[{"id":1407,"href":"https:\/\/adrianotanaka.com.br\/index.php\/wp-json\/wp\/v2\/posts\/1393\/revisions\/1407"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/adrianotanaka.com.br\/index.php\/wp-json\/wp\/v2\/media\/1398"}],"wp:attachment":[{"href":"https:\/\/adrianotanaka.com.br\/index.php\/wp-json\/wp\/v2\/media?parent=1393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adrianotanaka.com.br\/index.php\/wp-json\/wp\/v2\/categories?post=1393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adrianotanaka.com.br\/index.php\/wp-json\/wp\/v2\/tags?post=1393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}