My Google Cloud account contains many projects and servers, but only one Billing Account. So I'm writing a script to calculate my balance. I would like to export to BigQuery. My script:
SERVICE_ACCOUNT_FILE = 'service.json'
PROJECT_ID = 'poject'
DATA_SET = 'dataset'
TABLE_NAME = 'gcp_billing_export_v1_008DE2_378957_642BE6'
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = SERVICE_ACCOUNT_FILE
client = bigquery.Client()
QUERY = ("SELECT SUM(cost) AS cost FROM `" + PROJECT_ID + "." + DATA_SET + "." + TABLE_NAME + "`" +
" WHERE cost > 0")
query_job = client.query(QUERY)
rows = query_job.result()
for row in rows:
print("Daily Cost:", row.cost)
It shows some information about all my projects and current costs. Now it should watch my balance so that if I spend over 200 USD, it will automatically charge from my bank card.
Which API method or library should I use?
billingAccountName
in individual projects when your billing costs shoots about 200 USD – Oluwafemi Sule