gbillingplot

package module
v0.0.0-...-12b5a45 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

README

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

Documentation

Overview

*

  • Copyright (c) 2019-present Future Corporation *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GraphedBilling

func GraphedBilling(ctx context.Context, m *pubsub.Message) error

Types

type Payload

type Payload struct {
	Limit int `json:"limit"`
}

Directories

Path Synopsis
cmd
gbplot
* * Copyright (c) 2019-present Future Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
* * Copyright (c) 2019-present Future Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
* * Copyright (c) 2019-present Future Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
* * Copyright (c) 2019-present Future Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
* * Copyright (c) 2019-present Future Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
* * Copyright (c) 2019-present Future Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
* * Copyright (c) 2019-present Future Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
* * Copyright (c) 2019-present Future Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL