Skip to content

Create graphed invoice for Google Cloud Platform. You can see billing amount per GCP project.

License

Notifications You must be signed in to change notification settings

future-architect/gbilling-plot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gbilling-plot

go version 1.12 Apache 2.0 License Go Report Card

Create graphed invoice for Google Cloud Platform. You can see billing amount per GCP project.

Usage

This package uses below great services.

  • Google Cloud Billing(BigQuery)
  • Google Cloud Functions
  • Google Cloud Pub/Sub
  • Google Cloud Scheduler
  • Slack API

QuickStart

  1. Install
    go get -u go get -u github.com/future-architect/gbilling-plot/cmd/gbplot
  2. Obtain GCP Service credentials that must have bigquery.tables.getData and bigquery.jobs.create permission
  • You can assign predefined Cloud IAM roles that are dataViewer and jobUser
  1. Set environment variable
    export GOOGLE_APPLICATION_CREDENTIALS=<credentials path>
  2. Export your GCP billing to BigQuery
  3. Run command
    gbplot -project <your project name> -table <your billing table name on bigquery> -out out.png
  4. You can confirm out.png file

Options

$ 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

Deploy Google Cloud Function

Requirements

Steps

  1. Get Slack API Token
    • Permission Scopes is required files:write:user
    • Create Bot User OAuth Access Token and Install App
  2. Create Slack Bot User
    • invite bot user to slack channel
  3. Export your GCP billing to BigQuery
  4. 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."
  5. 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>"
  6. Go to the Cloud Scheduler page and click the run now button of graphBilling

Example

Sample output is below.

example

License

This project is licensed under the Apache License 2.0 License - see the LICENSE file for details

About

Create graphed invoice for Google Cloud Platform. You can see billing amount per GCP project.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages