コスト・レポートのダウンロード

請求およびコスト管理でコスト・レポートをダウンロードします。

コスト・レポートは、バケットにオブジェクトとして格納されるファイルです。オブジェクトのダウンロードに関する一般情報は、オブジェクト・ストレージ・オブジェクトのダウンロードを参照してください。

原価レポートのリストの詳細は、「原価レポートのリスト」を参照してください。

    1. 「コストおよび使用状況レポート」リスト・ページで、ダウンロードするコスト・レポートを検索します。リスト・ページまたは原価レポートの検索に関するヘルプが必要な場合は、「原価レポートのリスト」を参照してください。
    2. コスト・レポートの「アクション」メニュー「処理」メニューから、「レポートのダウンロード」を選択します。
  • ノート

    コスト・レポートは、テナンシのホーム・リージョンに格納されます。レポートで使用されるオブジェクト・ストレージ・ネームスペースは、blingです。バケット名はテナンシOCIDです。

    テナンシでコスト・レポートをダウンロードするには、oci os object getコマンドと必要なパラメータを使用します:

    oci os object get --bucket-name bucket-name --name object-name --file file-name

    例(APIタスクに示されているPython SDKコード例を参照):

    oci os object get --namespace-name bling --bucket-name {customer_tenancy_ocid}  --name reports/usage-csv/{report_name}.csv.gz --file {local_report_name}.csv.gz

    CLIコマンドのパラメータおよび値の完全なリストは、CLIコマンド・リファレンスを参照してください。

  • ノート

    コスト・レポートは、テナンシのホーム・リージョンに格納されます。レポートで使用されるオブジェクト・ストレージ・ネームスペースは、blingです。バケット名はテナンシOCIDです。

    GetObject操作を実行して、コスト・レポートをダウンロードします。

    次の例は、Pythonスクリプトを使用してコスト・レポートをダウンロードする方法を示しています:

    ノート

    この例では、特定のテナンシOCIDがあります。これは、レポートは、Oracle Cloud InfrastructureによってホストされるOracle所有のオブジェクト・ストレージ・バケットに格納され、顧客のテナンシに格納されないためです。
    import oci
    import os
                                   
    # This script downloads all of the cost, usage, (or both) reports for a tenancy (specified in the config file).
    #
    # Pre-requisites: Create an IAM policy to endorse users in your tenancy to read cost reports from the OCI tenancy.
    #
    # Example policy:
    # define tenancy reporting as ocid1.tenancy.oc1..aaaaaaaaned4fkpkisbwjlr56u7cj63lf3wffbilvqknstgtvzub7vhqkggq
    # endorse group <group_name> to read objects in tenancy reporting
    #
    # Note - The only value you need to change is the <group_name> with your own value. Do not change the OCID in the first statement.
                                   
    reporting_namespace = 'bling'
                                   
    # Download all usage and cost files. You can comment out based on the specific need:
    prefix_file = ""                       #  For cost and usage files
    # prefix_file = "reports/cost-csv"     #  For cost
    # prefix_file_focus = "FOCUS Reports"  #  For FOCUS reports
                                   
    # Update these values
    destintation_path = 'downloaded_reports'
                                   
    # Make a directory to receive reports
    if not os.path.exists(destintation_path):
        os.mkdir(destintation_path)
                                   
    # Get the list of reports
    config = oci.config.from_file(oci.config.DEFAULT_LOCATION, oci.config.DEFAULT_PROFILE)
    reporting_bucket = config['tenancy']
    object_storage = oci.object_storage.ObjectStorageClient(config)
    report_bucket_objects = oci.pagination.list_call_get_all_results(object_storage.list_objects, reporting_namespace, reporting_bucket, prefix=prefix_file)                          
    for o in report_bucket_objects.data.objects:
        print('Found file ' + o.name)
        object_details = object_storage.get_object(reporting_namespace, reporting_bucket, o.name)
        filename = o.name.rsplit('/', 1)[-1]
                                   
        with open(destintation_path + '/' + filename, 'wb') as f:
            for chunk in object_details.data.raw.stream(1024 * 1024, decode_content=False):
                f.write(chunk)
                                   
        print('----> File ' + o.name + ' Downloaded')