Create graphed invoice for Google Cloud Platform. You can see billing amount per GCP project.
This package uses below great services.
- Google Cloud Billing(BigQuery)
- Google Cloud Functions
- Google Cloud Pub/Sub
- Google Cloud Scheduler
- Slack API
- Install
go get -u go get -u github.com/future-architect/gbilling-plot/cmd/gbplot
- Obtain GCP Service credentials that must have
bigquery.tables.getData
andbigquery.jobs.create
permission
- You can assign predefined Cloud IAM roles that are
dataViewer
andjobUser
- Set environment variable
export GOOGLE_APPLICATION_CREDENTIALS=<credentials path>
- Export your GCP billing to BigQuery
- Run command
gbplot -project <your project name> -table <your billing table name on bigquery> -out out.png
- You can confirm out.png file
$ gbplot --help
Usage of gbplot:
-l int
Max display project count (default 8)
-limit int
Max display project count (default 8)
-o string
Output file name (default "out.png")
-out string
Output file name (default "out.png")
-p string
GCP project name
-project string
GCP project name
-t string
BigQuery billing table name
-table string
BigQuery billing table name
- Get Slack API Token
- Permission Scopes is required
files:write:user
- Create
Bot User OAuth Access Token
andInstall App
- Permission Scopes is required
- Create Slack Bot User
- invite bot user to slack channel
- Export your GCP billing to BigQuery
- Create Cloud Scheduler
gcloud beta scheduler jobs create pubsub graph-billing --project "<your project name>" \ --schedule "50 23 * * *" \ --topic graph-billing \ --message-body="{}" \ --time-zone "Asia/Tokyo" \ --description "This is scheduler for graph billing."
- Deploy to Cloud Function
git clone https://github.com/future-architect/gbilling-plot.git cd gbilling-plot gcloud functions deploy graphBilling --project "<your project name>" \ --entry-point GraphedBilling \ --triggerz-resource graph-billing \ --trigger-event google.pubsub.topic.publish \ --runtime go111 \ --set-env-vars TABLE_NAME="<your billing table name on bigquery>" \ --set-env-vars SLACK_API_TOKEN="<your slack api token>" \ --set-env-vars SLACK_CHANNEL="<your slack channel name>"
- Go to the Cloud Scheduler page and click the run now button of graphBilling
Sample output is below.
This project is licensed under the Apache License 2.0 License - see the LICENSE file for details