0

I am trying to create a script to get the amount free tier left. I have a GCP account with $300 free tier after that amount is over my applications will be shut down by Google. My question is how to get the about of left free tier using API or Python so I can send a notification to my chatting system to be aware when to migrate my application

I did go over all Stack Overflow questions and can't find the answer

VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • It is possible you don't find the specific answer for your specific problem. What have you tried so far? Have you red the billing API? – Puteri Feb 12 '22 at 20:56

1 Answers1

1

There are a couple of ways.

0 - Budgets programmatic notifications

I think flow from link below illustrates what you need. https://cloud.google.com/billing/docs/how-to/budgets-programmatic-notifications From budget alert > to pub/sub > to cloud function which you can program to do what you want including pinging slack/discord etc would have to use their APIs in cloud function. Example flow below from documentation:

enter image description here


1. Extracting your billing data to bigquery

https://cloud.google.com/billing/docs/how-to/export-data-bigquery From there you could monitor billing by project and product, however I am not sure how instant it is, but you can imagine from there scheduling a BQ job or airflow to to check for statuses and ping pub/sub or cloud function to shut off what ever needs to be shut off or send messages like above


2. Set up budget alerts to yourself / other --- manual

https://cloud.google.com/billing/docs/how-to/budgets You can set up alerts on when you are coming close to or exceeding your specified budget.

  • In google cloud console go to billing
  • Select your billing account (if multiple)
  • Then go to Budgets & alerts. I think you can publish these alerts to pub sub and go from there with whatever you need to shut down or migrate (like mentioned in 0.)

3. Budgets API

https://cloud.google.com/billing/docs/how-to/budget-api There are some other cool things you can assemble from here for your solution.

Yev Guyduy
  • 1,371
  • 12
  • 13