Erwald
Erwald

Reputation: 2206

Where do you get Google Bigquery usage info (mainly for processed data)

I know that BigQuery offers the first "1 TB of data processed" per month for free but I can't figure out where to look on my dashboard to see my monthly usage. I used to be able to "revert" to the old dashboard which had the info but for the past couple of weeks the "old dashboard" isn't accessible.

Upvotes: 16

Views: 21810

Answers (4)

dmb68
dmb68

Reputation: 51

Theo is correct that there is no way to view the number of bytes processed or billed since the start of the month (inside of the free tier) in the GCP Billing Console. However, you can extract the bytes processed and bytes billed data from logs in Cloud Logging and calculate the total bytes processed/billed since the start of the month inside of BigQuery.

Here are the steps to count total bytes billed in a month:

  1. Under Cloud Logging, go to Logs Explorer (NOT the Legacy Logs Explorer) and run the following query in the query builder frame:
resource.type="bigquery_project" AND
protoPayload.metadata.jobChange.job.jobStats.queryStats.totalBilledBytes>1 AND
timestamp>="2021-04-01T00:00:00Z"

The timestamp clause is not actually necessary, but it will speed up the query. You can set timestamp >= <value> to any valid timestamp you want as long as it returns at least one result.

  1. In the Query Results frame, click the "Action" button, and select "Create Sink".

In the window that opens, give your sink a name, click "Next", and in the "Select sink service" dropdown menu select "BigQuery dataset".

In the "Select BigQuery dataset" dropdown menu, either select an existing dataset where you would like to create your sink (which is a table containing logs) or if you prefer, choose "Create new BigQuery dataset.

Finally, you will likely want to check the box for Partition Table, since this will help you control costs whenever you query this sink. As of the time of this answer, however, Google limits partition tables to 4000 partitions, so you may find it is necessary to clear out old logs eventually.

Click "Create Sink" (there is no need for any inclusion or exclusion filters).

  1. Run a query in BigQuery that produces bytes billed (i.e. a query that does not return a previously cached result). This is necessary to instantiate the sink. Moments after your query runs, you should now see a table called <your_biquery_dataset>.cloudaudit_googleapis_com_data_access

  2. Enter the following Standard SQL query in the BigQuery query editor:

WITH
  bytes_table AS (
  SELECT
    JSON_VALUE(protopayload_auditlog.metadataJson,
      '$.jobChange.job.jobStats.createTime') AS date_time,
    JSON_VALUE(protopayload_auditlog.metadataJson,
      '$.jobChange.job.jobStats.queryStats.totalBilledBytes') AS billedbytes
  FROM
    `<your_project><your_bigquery_dataset>.cloudaudit_googleapis_com_data_access`
  WHERE
    EXTRACT(MONTH
    FROM
      timestamp) = 4
    AND EXTRACT(YEAR
    FROM
      timestamp) = 2021)
SELECT
  (SUM(CAST(billedbytes AS INT64))/1073741824) AS total_GB
FROM
  bytes_table;

You will want to chance the month from 4 to whatever month you intend to query, and 2021 to whatever year you intend to query. Also, you may find it helpful to save this query as a view if you intend to rerun it periodically.

Be advised that your sink does not contain your past BigQuery logs, only BigQuery logs produced after you created the sink. Therefore in the first month the number of GB returned by this query will not be an accurate count your bytes billed in month unless you happen to have created the sink prior to running any queries in BigQuery during the current month.

Upvotes: 4

Hirnhamster
Hirnhamster

Reputation: 7389

Might be related to How can I monitor incurred BigQuery billings costs (jobs completed) by table/dataset in real-time?

If you are fine by using BigQuery itself to get that information (instead of using a UI), you can use something like this:

DECLARE gb_divisor INT64 DEFAULT 1024*1024*1024;
DECLARE tb_divisor INT64 DEFAULT gb_divisor*1024;
DECLARE cost_per_tb_in_dollar INT64 DEFAULT 5;
DECLARE cost_factor FLOAT64 DEFAULT cost_per_tb_in_dollar / tb_divisor;

SELECT
 ROUND(SUM(total_bytes_processed) / gb_divisor,2) as bytes_processed_in_gb,
 ROUND(SUM(IF(cache_hit != true, total_bytes_processed, 0)) * cost_factor,4) as cost_in_dollar,
 user_email,
FROM (
  (SELECT * FROM `region-us`.INFORMATION_SCHEMA.JOBS_BY_USER)
  UNION ALL
  (SELECT * FROM `other-project.region-us`.INFORMATION_SCHEMA.JOBS_BY_USER)
)
WHERE
  DATE(creation_time) BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY) and CURRENT_DATE()
GROUP BY 
  user_email

Upvotes: 4

Theo
Theo

Reputation: 1931

Post GCP Console Redesign Answer

The GCP console was redesigned and now the other answer here no longer applies, but it is still possible to view your usage by going to IAM & Admin -> Quotas.

What you're looking for is "Big Query API: Query usage per day". It doesn't seem possible to view your usage over 30 days unfortunately, but you can see your current usage (per day) and your peak usage over the past 7 days. You can also set a daily quota. If you're just working infrequently or doing a lot in one day, you can set a quota to 1 TiB and prevent yourself from blowing your whole allocation in one day.

You can try sending feedback about these limitations, like I did, by clicking the question mark at the top right and then send feedback.

Upvotes: 9

David
David

Reputation: 5519

From the Google Cloud Console overview page for your project, click on the "details" section on the top-right, next to the charge estimate :

Cloud Console overview

You'll get an estimate of the charges for the current month for each service and item in the service, including Big Query analysis :

Estimated usage for the current month

If you want to track this usage, you can also export the data into CSV every day by going in the Billing settings and enable the usage export feature. Do not worry about the fact that it only mentions Compute Engine, it actually works for other services also.

Billing usage export

You can also access directly the billing history by clicking on the billing account link :

Billing account link

You will get a detailed bill with the usage info :

enter image description here

Upvotes: 10

Related Questions