https://github.com/future-architect/gbilling-plot
Create graphed invoice for Google Cloud Platform. You can see billing amount per GCP project.
https://github.com/future-architect/gbilling-plot
bigquery billing cloud-scheduler gcp-billing go golang slack
Last synced: 22 days ago
JSON representation
Create graphed invoice for Google Cloud Platform. You can see billing amount per GCP project.
- Host: GitHub
- URL: https://github.com/future-architect/gbilling-plot
- Owner: future-architect
- License: apache-2.0
- Created: 2019-07-23T10:20:07.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-28T12:22:37.000Z (about 3 years ago)
- Last Synced: 2025-05-07T21:08:50.501Z (22 days ago)
- Topics: bigquery, billing, cloud-scheduler, gcp-billing, go, golang, slack
- Language: Go
- Size: 217 KB
- Stars: 11
- Watchers: 2
- Forks: 6
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gbilling-plot

[](LICENSE)
[](https://goreportcard.com/report/github.com/future-architect/gcp-instance-scheduler)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
```console
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`
3. Set environment variable
```bash
export GOOGLE_APPLICATION_CREDENTIALS=
```
4. Export your GCP billing to BigQuery
* https://cloud.google.com/billing/docs/how-to/export-data-bigquery
5. Run command
```bash
gbplot -project -table -out out.png
```
6. You can confirm out.png file## Options
```console
$ 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
* [Go](https://golang.org/dl/) more than 1.11
* [Cloud SDK](https://cloud.google.com/sdk/install/)### Steps
1. [Get Slack API Token](https://get.slack.help/hc/en-us/articles/215770388-Create-and-regenerate-API-tokens#-internal-app-tokens)
* Permission Scopes is required `files:write:user`
* Create `Bot User OAuth Access Token` and `Install App`
2. [Create Slack Bot User](https://get.slack.help/hc/en-us/articles/215770388-Create-and-regenerate-API-tokens#-bot-user-tokens)
* invite bot user to slack channel
3. [Export your GCP billing to BigQuery](https://cloud.google.com/billing/docs/how-to/export-data-bigquery)
4. Create Cloud Scheduler
```sh
gcloud beta scheduler jobs create pubsub graph-billing --project "" \
--schedule "50 23 * * *" \
--topic graph-billing \
--message-body="{}" \
--time-zone "Asia/Tokyo" \
--description "This is scheduler for graph billing."
```
5. Deploy to Cloud Function
```sh
git clone https://github.com/future-architect/gbilling-plot.git
cd gbilling-plot
gcloud functions deploy graphBilling --project "" \
--entry-point GraphedBilling \
--triggerz-resource graph-billing \
--trigger-event google.pubsub.topic.publish \
--runtime go111 \
--set-env-vars TABLE_NAME="" \
--set-env-vars SLACK_API_TOKEN="" \
--set-env-vars SLACK_CHANNEL=""
```
6. Go to the [Cloud Scheduler page](https://cloud.google.com/scheduler/docs/tut-pub-sub) and click the *run now* button of *graphBilling*## Example
Sample output is below.

## License
This project is licensed under the Apache License 2.0 License - see the [LICENSE](LICENSE) file for details